Vector multiplication into a matrix

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

Vector multiplication into a matrix

Post by salvadorgarciamunoz » 2 months ago

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: 111
Joined: 1 year ago

Re: Vector multiplication into a matrix

Post by Renger » 2 months ago

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

salvadorgarciamunoz
User
User
Posts: 2
Joined: 2 months ago

Re: Vector multiplication into a matrix

Post by salvadorgarciamunoz » 2 months ago

Thanks ! This is very helpful !

Post Reply