How to compute matrix arithmetic in Gams

Archive of Gamsworld Google Group
Archiver
User
User
Posts: 7876
Joined: 5 months ago

How to compute matrix arithmetic in Gams

Postby Archiver » 2 years ago


Hello,

How to compute matrix A multiplied by matrix B in Gams?
And how to compute matrix A divided by matrix B in Gams?

In the example below, how can I compute matrix pmax divided by matrix vmax in Gams?

sets
i /i1*i5/
j /j1/
k /k1*k2/

scalars
b1 /5/
b2 /10/
b3 /4/
b4 /8/
b5 /6.67/
d1 /0/
d2 /6.83/
d3 /-1.25/
d4 /7.06/
d12
d23
d34
d14
d24
H;

d12=d2-d1;
d23=d3-d2;
d34=d4-d3;
d14=d4-d1;
d24=d4-d2;

table
p(j,i)
i1 i2 i3 i4 i5
j1 2.23 -1.95 -1.95 2.23 0.28;
table
v(j,k)
k1 k2
j1 0.77 -0.64;

parameters
pmax
vmax;
pmax(i,j)=p(j,i);
vmax(k,j)=v(j,k);

display pmax,p,vmax,v;

Sincerely

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Archiver
User
User
Posts: 7876
Joined: 5 months ago

RE: How to compute matrix arithmetic in Gams

Postby Archiver » 2 years ago


Hi Songming



Multiplication can be done as follows:



parameter

vmaxt(j,k) Transposed vmax,

pmaxvmax(i,k) Matrix multiplicationof pmax and vmax;



vmaxt(j,k) = vmax(k,j);

pmaxvmax(i,k) = prod(j, pmax(i,j) * vmaxt(j,k));



display pmaxvmax;



The division of pmax by vmax is not defined, but I assume you want to have the vector divided by the first value of vmax and then by the second value.



parameter

pmaxvmaxdiv(j,i,k) Division of pmax by vmax;



pmaxvmaxdiv(j,i,k) = pmax(i,j)/vmax(k,j);

display pmaxvmaxdiv;



As set j only has one element, you could also write



parameter

pmaxvmaxdiv(i,k) Division of pmax by vmax;



pmaxvmaxdiv(i,k) = pmax(i,”j1”)/vmax(k,”j1”);

display pmaxvmaxdiv;



Cheers



Renger





_________________________________________________________________

Renger van Nieuwkoop, PhD



Department of Management, Technology and Economics | Director

Centre for Energy Policy and Economics | Modelworks

Swiss Federal Institute of Technology Zurich | Gewerbestrasse 15

Zürichbergstrasse 18, CH-8032 Zurich | CH-3600 Thun



Mobile: +41 79 818 53 73

E-Mail: rengerv@vannieuwkoop.ch

Blog: http://blog.modelworks.ch









From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Songming Zhu
Sent: Dienstag, 13. Januar 2015 02:37
To: gamsworld@googlegroups.com
Subject: Re: How to compute matrix arithmetic in Gams



Hello,



How to compute matrix A multiplied by matrix B in Gams?

And how to compute matrix A divided by matrix B in Gams?



In the example below, how can I compute matrix pmax divided by matrix vmax in Gams?



sets

i /i1*i5/

j /j1/

k /k1*k2/



scalars

b1 /5/

b2 /10/

b3 /4/

b4 /8/

b5 /6.67/

d1 /0/

d2 /6.83/

d3 /-1.25/

d4 /7.06/

d12

d23

d34

d14

d24

H;



d12=d2-d1;

d23=d3-d2;

d34=d4-d3;

d14=d4-d1;

d24=d4-d2;



table

p(j,i)

i1 i2 i3 i4 i5

j1 2.23 -1.95 -1.95 2.23 0.28;

table

v(j,k)

k1 k2

j1 0.77 -0.64;



parameters

pmax

vmax;

pmax(i,j)=p(j,i);

vmax(k,j)=v(j,k);



display pmax,p,vmax,v;



Sincerely

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

jorgeiv500
User
User
Posts: 1
Joined: 4 weeks ago

Re: How to compute matrix arithmetic in Gams

Postby jorgeiv500 » 4 weeks ago

Hello

There is any function for multiply matrices in GAMS like MMULT (Excel,matlab,julia), ??

Please help!


Return to “Archive Google Group”

Who is online

Users browsing this forum: No registered users and 1 guest