Page 1 of 1

Vector multiplication into a matrix

Posted: Mon Feb 19, 2018 4:12 pm
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.

Re: Vector multiplication into a matrix

Posted: Tue Feb 20, 2018 9:49 am
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

Re: Vector multiplication into a matrix

Posted: Tue Feb 20, 2018 2:45 pm
by salvadorgarciamunoz
Thanks ! This is very helpful !