Vector multiplication into a matrix

Problems with modeling
Post Reply
salvadorgarciamunoz
User
User
Posts: 2
Joined: 6 years ago

Vector multiplication into a matrix

Post by salvadorgarciamunoz »

Hi,

Newbie here, sorry if this is trivial, how can you multiply two vectors into a matrix (say a n*1 times an 1*m into a n*m) ? Just multiplying them will surely send an error since the order sets are different, is there a trick here?

With apologies,
Thanks
Sal.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Vector multiplication into a matrix

Post by Renger »

Hi

For this you can use a double loop:

Code: Select all

set i /i1*i4/, j /j1*j5/;

parameter vector1(i), vector2(j), matrix(i,j);

* Give some random values:
vector1(i) = ord(i);
vector2(j) = ord(j)

loop(i, 
    loop(j, 
            matrix(i,j) = vector1(i) * vector2(j);
      );
);

display matrix;
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
salvadorgarciamunoz
User
User
Posts: 2
Joined: 6 years ago

Re: Vector multiplication into a matrix

Post by salvadorgarciamunoz »

Thanks ! This is very helpful !
Post Reply