Sum

Top  Previous  Next

One might wish to sum items as follows

 

r=sum(I,y[I]);

r=sum((I,j),y(i)+w(j));

eq5[I]..  zz[I]=e=sum[j,zz[i-1]+zq[j]];

 

Here the sum is computed over all of

 

the elements in I for the first equation

the elements in I and j for the second equation

the elements in j for the third equation

Notes:

The general syntax is sum(settovary,expression) where
The settovary is the name of the sets or sets that will be varied
When more than one set is to be varied they are enclosed in parentheses – sum((i,j),x(i,j)).
Expression is a generally a function of the set in the sum
A ( occurs just after the word sum and matches with a ) at the end of the sum.
In replacement statements parameters, and scalars can freely appear.  Variables and equations can only be present if attributes of them are being addressed.
In model equation specification statements parameters, scalars and variables can freely appear.
The expression after the comma is fully computed and then applied to the sum as if the term were in parentheses.