product of an nxn matrix with nx1 vector

598 views
Skip to first unread message

humaira fazal

unread,
May 12, 2008, 5:34:54 PM5/12/08
to am...@googlegroups.com
Hi,
 I'm trying to multiply an nxn matrix with nx1 vector.
var A{i in N,j in N}
var r{j in N}
var A{j in N}=B[i,j]*r[j];
 
 Also I have to reshape  an n^2x1 vector into nxn matrix.
Can anyone please tell me the syntax of it.
thanks


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

Robert Fourer

unread,
May 13, 2008, 8:49:50 AM5/13/08
to am...@googlegroups.com, humaira fazal

I'm not sure what is intended here, but the following is one example of matrix-vector multiplication:

 

   param N integer > 0;

   param A {1..N,1..N};

   var r {1..N};

 

   var v {i in 1..N} = sum {j in 1..N} A[i,j] * r[j];

 

The reshape will involve an assignment like

 

   let {i in 1..N, j in 1..N} Mat[i,j] := vect[N*(i-1)+j];

 

but I will leave the details to the reader.

 

Bob Fourer

4...@ampl.com=

 

 


From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of humaira fazal
Sent: Monday, May 12, 2008 4:35 PM
To: am...@googlegroups.com
Subject: [AMPL 1775] product of an nxn matrix with nx1 vector

Reply all
Reply to author
Forward
0 new messages