第一次尝试使用loop
:
set i /6*10/
j /J1*J4/
k /K1*K4/;
Parameter S(i),p(J,K);
Scalar X / 5/
T / 20/;
Table q(j,k)'constants'
k1 k2 k3 k4
j1 0.513 -0.014 2.924145E-5 9.035697E-7
j2 0.012 -9.15682E-5 1.820453E-8 -7.9918E-10
j3 -1.36480E-5 1.068904E-7 -1.38111E-9 1.52978E-11
j4 1.021501E-8 0 0 0 ;
loop(i,
S(i)=0 ;
loop( j,
loop(k,
S(i)= S(i)+ sum((j,k), q(j,k)*(power(X,k-1)*power(T,y-1)) );
)
)
)
显示错误:
24 S(i)= S(i)+ sum((j,k), q(j,k)*(power(X,k-1)*power(T,y-1)) );
**** $125,125 $148,133,201$140
**** 125 Set is under control already
**** 133 Incompatible operands for addition
**** 140 Unknown symbol
**** 148 Dimension different - The symbol is referenced with more/less
**** indices as declared
**** 201 Invalid argument for function
25 )
26 )
27 )
**** 6 ERROR(S) 0 WARNING(S)
第二次尝试使用for
:
Set r 'rows'/r1*r4/
C 'columns' /c1*c4/
Parameter P(y,k),m(i);
scalar i,y,k,m
X /56.04/
T / 35/
cnt /0/
b;
Equation
S1 'Entropy eq';
Table E(r,c) 'constants'
c1 c2 c3 c4
r1 0.513 -0.014 2.924145E-5 9.035697E-7
r2 0.012 -9.15682E-5 1.820453E-8 -7.9918E-10
r3 -1.36480E-5 1.068904E-7 -1.38111E-9 1.52978E-11
r4 1.021501E-8 0 0 0 ;
for (y= 1 to 4,
for (k= 1 to 4,
P(y,k) = power(X,k-1)*power(T,y-1);
))
for(i=5 to 9,
m(i)=sum((r,c),E(r,c)*P(y,k));
display m(i)
)
)
我正在尝试获得P(1,1) = power(X,0)*power(T,0)
,P(1,2) = power(X,0)*power(T,1)
,P(1,3) = power(X,0)*power(T,2)
,...到P(4,4)
。
由于需要设置y,k而不是标量,因此在P(y,k)
处产生错误。如果我将P(y,k)
替换为P(r,c)
,则P(r,c)
中所有元素的最终值将是power(X,3)*power(T,3)
(意味着每次循环运行都会替换P中的所有值)