Help regarding coding for a vector of interrelated elements.

Problems with modeling
Post Reply
bbiswas
User
User
Posts: 12
Joined: 5 months ago

Help regarding coding for a vector of interrelated elements.

Post by bbiswas » 1 month ago

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.

User avatar
Renger
Posts: 353
Joined: 2 years ago

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

Post by Renger » 1 month ago

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: The lazy economist

bbiswas
User
User
Posts: 12
Joined: 5 months ago

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

Post by bbiswas » 1 month ago

Thank you so much sir.

Post Reply