The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: vector and array element multiplication
Replies: 6   Last Post: Apr 19, 2013 6:47 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 6,677
Registered: 2/7/05
Re: vector and array element multiplication
Posted: Apr 18, 2013 10:29 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4/18/2013 8:26 PM, Gorbeña wrote:
> Hi,
> I would like to create a second order polynomial from a vector or a matrix. Each element
>of the vector or matrix corresponds to an independedent variable.
> Given vector A, where A = [x1 x2 x3], I want the following result:
> [x1 x1² x1*x2 x1*x3 x2 x2*x1 x2² x1*x3 x3 x3*x1 x3*x2 x3²]
> In case I have matrix B = [a1 a2 a3; b1 b2 b3], the desired result will be:
> [a1 a1² a1*a2 a1*a3 a2 a2*a1 a2² a1*a3 a3 a3*a1 a3*a2 a3²;
> b1 b1² b1*b2 b1*b3 b2 b2*b1 b2² b1*b3 b3 b3*b1 b3*b2 b3²]
> Does anybody knows how to do this?
> Thanks

You can make each poly by multiplying each row by itself but after
transposing. (i.e. do an outer product)

syms x1 x2 x3
V = [x1 x2 x3] %one row
C = V.'*V;
C = [V C(:).']

[ x1, x2, x3, x1^2, x1*x2, x1*x3, x1*x2, x2^2, x2*x3, x1*x3, x2*x3, x3^2]

So for a matrix, just do the above outer product for its of its rows.


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.