lingo 找错 for循环有问题(在线等)
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/16 23:25:58
lingo 找错 for循环有问题(在线等)
我是初学者,运行时显示错误为:subscript out of range on attribute 似乎说是指标超出范围,不是很懂!
model:
sets:
year/1..5/:n,n1,n2,n3,n4,q4;
endsets
data:
n1=122000000000,;
n2=29700000000,;
n3=10100000000,;
n4=3290000000,;
enddata
max = @sum(year:(-17.86*0.42*q4(i)*n3(i)/(0.8+0.42*q4(i)))*(@exp(-2/3*(0.8+0.42*q4(i)))-1)-(22.99*q4(i)*n4(i)/(0.8+q4(i)))*(@exp(-2/3*(0.8+q4(i)))-1));
@for(year(j):n1(j+1)=122000000000*(n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900)/(122000000000+n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900));
@for(year(k):n2(k+1)=n1(k)*@exp(-0.8));
@for(year(l):n3(l+1)=n2(l)*@exp(-0.8));
@for(year(m):n4(m+1)=n3(m)*@exp(-2/3*(0.8+0.42*q4(m)))*@exp(-0.8/3)+n4(m)*@exp(-2/3*(0.8+q4(m)))*@exp(-0.8/3));
end
我是初学者,运行时显示错误为:subscript out of range on attribute 似乎说是指标超出范围,不是很懂!
model:
sets:
year/1..5/:n,n1,n2,n3,n4,q4;
endsets
data:
n1=122000000000,;
n2=29700000000,;
n3=10100000000,;
n4=3290000000,;
enddata
max = @sum(year:(-17.86*0.42*q4(i)*n3(i)/(0.8+0.42*q4(i)))*(@exp(-2/3*(0.8+0.42*q4(i)))-1)-(22.99*q4(i)*n4(i)/(0.8+q4(i)))*(@exp(-2/3*(0.8+q4(i)))-1));
@for(year(j):n1(j+1)=122000000000*(n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900)/(122000000000+n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900));
@for(year(k):n2(k+1)=n1(k)*@exp(-0.8));
@for(year(l):n3(l+1)=n2(l)*@exp(-0.8));
@for(year(m):n4(m+1)=n3(m)*@exp(-2/3*(0.8+0.42*q4(m)))*@exp(-0.8/3)+n4(m)*@exp(-2/3*(0.8+q4(m)))*@exp(-0.8/3));
end
改好的程序已经给出了,能够运行了,最主要的错误是j+1、k+1、l+1、m+1时超出范围,因为定义时j,k,l,m的最大值为5,而在限制条件中超出了范围!
model:
sets:
year/1..5/:n,n1,n2,n3,n4,q4;
endsets
data:
n1=122000000000,;
n2=29700000000,;
n3=10100000000,;
n4=3290000000,;
enddata
max=@sum(year(i):(-17.86*0.42*q4(i)*n3(i)/(0.8+0.42*q4(i)))*(@exp(-2/3*(0.8+0.42*q4(i)))-1)-(22.99*q4(i)*n4(i)/(0.8+q4(i)))*(@exp(-2/3*(0.8+q4(i)))-1));
@for(year(j)|j#le#4:n1(j+1)=122000000000*(n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900)/(122000000000+n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900));
@for(year(k)|k#le#4:n2(k+1)=n1(k)*@exp(-0.8));
@for(year(l)|l#le#4:n3(l+1)=n2(l)*@exp(-0.8));
@for(year(m)|m#le#4:n4(m+1)=n3(m)*@exp(-2/3*(0.8+0.42*q4(m)))*@exp(-0.8/3)+n4(m)*@exp(-2/3*(0.8+q4(m)))*@exp(-0.8/3));
end
model:
sets:
year/1..5/:n,n1,n2,n3,n4,q4;
endsets
data:
n1=122000000000,;
n2=29700000000,;
n3=10100000000,;
n4=3290000000,;
enddata
max=@sum(year(i):(-17.86*0.42*q4(i)*n3(i)/(0.8+0.42*q4(i)))*(@exp(-2/3*(0.8+0.42*q4(i)))-1)-(22.99*q4(i)*n4(i)/(0.8+q4(i)))*(@exp(-2/3*(0.8+q4(i)))-1));
@for(year(j)|j#le#4:n1(j+1)=122000000000*(n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900)/(122000000000+n3(j)*@exp(-2/3*(0.8+0.42*q4(j)))*110900*0.5+n4(j)*@exp(-2/3*(0.8+q4(j)))*110900));
@for(year(k)|k#le#4:n2(k+1)=n1(k)*@exp(-0.8));
@for(year(l)|l#le#4:n3(l+1)=n2(l)*@exp(-0.8));
@for(year(m)|m#le#4:n4(m+1)=n3(m)*@exp(-2/3*(0.8+0.42*q4(m)))*@exp(-0.8/3)+n4(m)*@exp(-2/3*(0.8+q4(m)))*@exp(-0.8/3));
end