The correct syntax for sum inside sum Topic is solved

Problems with syntax of GAMS
Post Reply
urise
User
User
Posts: 7
Joined: 6 years ago

The correct syntax for sum inside sum

Post by urise »

Hi All,

I have multiple sums as follow: \sum_{j=2}^J [ 1 - \sqrt(\sum_{l=1}^L \sum_{t=1}^T\ (sum_{k=2}^j x(k) - x(k-1))^2)].

I try to implement in GAMS as below:

sum(j $ (ord(j) gt 1), (1 - sqrt(sum((l,t), power(sum(k $ (ord(k) <= ord(j) and ord(k) >= 2), x(k) - x(k-1)),2)))).

Is this syntax correct? If not, what is the correct one?
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: The correct syntax for sum inside sum

Post by Renger »

Hi

You only forget to close one parenthesis (something you could have find yourself). A good way to test your stuff is using small sets and a known parameter, so you can do the calculation by hand and check it this way.
Here an example:

Code: Select all

set j /1*3/, k /1*3/, l /1*3/, t /1*3/;

parameter x;

x(k) = k.val;

parameter test;
test = sum(j$(ord(j) gt 1), (1 - sqrt(sum((l,t), power(sum(k$(ord(k) <= ord(j) and ord(k) >= 2), x(k) - x(k-1)),2)))));
display test;
CHeers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
urise
User
User
Posts: 7
Joined: 6 years ago

Re: The correct syntax for sum inside sum

Post by urise »

Thank you, Renger!
Post Reply