Help regarding coding for a vector of interrelated elements.

Problems with modeling
bbiswas
User Posts: 14
Joined: 7 months ago

Help regarding coding for a vector of interrelated elements.

Hello,
Let's say I want to to write the following code in GAMS,
V, %vector of size 10
diff, %vector of size 10

for i=2:10
V(i)=V(i-1) + diff(i);
end

How do I write similar code in GAMS? Let's assume I have a variable V of size b, where b=/x1,x2,x3,x4/, similarly the diff variable has same index b. Thank you.

Renger
Posts: 398
Joined: 3 years ago

Re: Help regarding coding for a vector of interrelated elements.

Hi
Use the \$-sign to restrict the equation to elements not equal to the first element

Code: Select all

V(i)\$(ord(i) > 1)=V(i-1) + diff(i);
* or if the elements of the set are integers
V(i)\$(i.val > 1)=V(i-1) + diff(i);
* or using sameas
V(i)\$(not sameas(i,"1") =V(i-1) + diff(i);
Cheers
Renger

Enjoy modeling even more: The lazy economist
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

bbiswas
User Posts: 14
Joined: 7 months ago

Re: Help regarding coding for a vector of interrelated elements.

Thank you so much sir.