LOOP Problem
Posted: Wed Dec 13, 2017 3:42 pm
Hi,
I want to code the following BASIC program into GAMS. This program computes variable Z based on variable L and assumes that L in the last period is zero (T= 0,...,10). Reversely, it computes L variable up to the first time. Below please find my loop command but it doesn't give me the correct loop answer.
Thanks for the help,
0 REM PROGRAM 1.1: MINE PROBLEM
20 DIM X(11},Y(11).Z(11).L(11}
30 L(10) = 0
40 FOR T = 9 TO 0 STEP -1
50 Z(T} = (1- L(T+1))
60 L(T) = L(T+1) + Z(T)^2
70 NEXT T
80 X(0) = 1000
90 FOR T = 0 TO 9
100 Y(T) = X(T} * Z(T)
110 X(T+1) = X(T) - Y(T}
120 NEXT T
130 LPRINT " T X(T} Y(T) L(T)"
140 LPRINT "------------------------------------------------"
150 LPRINT 0,X(0),Y(0)
160 FOR T = 1 TO 10
170 LPRINT T,X(T),Y(T),L(T}
180 NEXT T
190 END
set t Time periods /0*10/;
variable L(t);
L.up(t) = 0;
loop(t, L.l(t) = L.l(t+1)+((1-L.l(t+1)/2)**2));
display L.l;
I want to code the following BASIC program into GAMS. This program computes variable Z based on variable L and assumes that L in the last period is zero (T= 0,...,10). Reversely, it computes L variable up to the first time. Below please find my loop command but it doesn't give me the correct loop answer.
Thanks for the help,
0 REM PROGRAM 1.1: MINE PROBLEM
20 DIM X(11},Y(11).Z(11).L(11}
30 L(10) = 0
40 FOR T = 9 TO 0 STEP -1
50 Z(T} = (1- L(T+1))
60 L(T) = L(T+1) + Z(T)^2
70 NEXT T
80 X(0) = 1000
90 FOR T = 0 TO 9
100 Y(T) = X(T} * Z(T)
110 X(T+1) = X(T) - Y(T}
120 NEXT T
130 LPRINT " T X(T} Y(T) L(T)"
140 LPRINT "------------------------------------------------"
150 LPRINT 0,X(0),Y(0)
160 FOR T = 1 TO 10
170 LPRINT T,X(T),Y(T),L(T}
180 NEXT T
190 END
set t Time periods /0*10/;
variable L(t);
L.up(t) = 0;
loop(t, L.l(t) = L.l(t+1)+((1-L.l(t+1)/2)**2));
display L.l;