运筹学课上的小练习

笔者也是菜鸟一枚,这篇博客记录了我们课上的练习,如有错误请不吝赐教。

一、求和

题1:
求1+2+3+…100;

!lingo代码:;
sets:
	set/1..100/:x;
endsets

@for(set(i):x(i) = i);
sum = @sum(set(i):x(i));

输出结果:

题2:
求1+2+3+…+98+100;

!lingo代码:;
sets:
	set/1..98/:x;
endsets

data:
	a = 100;
enddata

@for(set(i):x(i) = i);
sum = @