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.

## Help regarding coding for a vector of interrelated elements.

### 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
Cheers

Renger

Enjoy modeling even more: The lazy economist

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);
```

Renger

Enjoy modeling even more: The lazy economist

____________________________________

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

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

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

Thank you so much sir.