第10章 Lingo软件包及其应用 联系客服

发布时间 : 星期四 文章第10章 Lingo软件包及其应用更新完毕开始阅读c1025834ee06eff9aef807c2

x+y>30;

@free(x);@free(y); end

执行后得到结果:

Linearization components added: Constraints: 30 Variables: 20 Integers: 12

Global optimal solution found at iteration: 34 Objective value: 150.0000

Variable Value Reduced Cost FX 0.000000 0.000000 FY 150.0000 0.000000 X 0.000000 0.000000 Y 30.00000 0.000000 Row Slack or Surplus Dual Price 1 150.0000 -1.000000 2 0.000000 -1.000000 3 0.000000 -1.000000 4 0.000000 -3.000000 即,目标函数fmin?150,最优解x?0,y?30。

注:在Mathematica软件包中,编程画图如下:

Plot[{0,If[x>0,2x+100,2x]+If[x<30,60+3(30-x),2(30-x)]},{x,-40,40}] 执行后得到图形如下:

25020015010050-40-2020

例10-4 在Lingo软件包中,求解下列变量可取负值的优化问题:

5

minf?4x1?x2?2x3?12?3x1?2x2?x3?9?s.t.?x1?x2?x3??1?x,x,xfree?123222

在Lingo软件包中编程如下: min=4*x1^2-x2^2+2*x3^2+12; 3*x1+2*x2+x3=9; x1+x2+x3=-1;

@free(x1);@free(x2);@free(x3);

执行后得到结果:

Local optimal solution found at iteration: 6 Objective value: 152.0000

Variable Value Reduced Cost

X1 0.9999950 -0.5434437E-08 X2 8.000010 0.000000 X3 -10.00001 0.000000

Row Slack or Surplus Dual Price 1 152.0000 -1.000000 2 0.000000 -23.99999 3 0.000000 64.00000

即,目标函数fmin?152,最优解x1?1,x2?8,x3??10。

§9.2 利用Lingo求解不等式组和方程组

Lingo软件包可以有效地求解不等式组,特别是非线性不等式组,这是Lingo软件包的特色之一。不过,Lingo求解不等式组只能给出单独的解,而不能给出区间解。在求解方程组时,只能求解实数解。

例10-5 在Lingo软件包中,求解下列非线性不等式组:

?3x1*y1?x3*y1?3x2*y2?x3*y2?3y1?3x1*y1?x3*y1?3x2*y2?x3*y2?3y2??3x1*y1?x3*y1?3x2*y2?x3*y2?y1?y2??x1*y1?2x2*y1?3x3*y1?2x1*y2?3x2*y2?x3*y2?x1?2x2?3x3??x1*y1?2x2*y1?3x3*y1?2x1*y2?3x2*y2?x3*y2?2x1?3x2?x3?x1?x2?x3?1??y1?y2?1?x1,x2,x3,y1,y2?0?

6

在Lingo软件包中编程如下: model:

3*x1*y1+x3*y1+3*x2*y2+x3*y2>=3*y1; 3*x1*y1+x3*y1+3*x2*y2+x3*y2>=3*y2; 3*x1*y1+x3*y1+3*x2*y2+x3*y2>=y1+y2;

x1*y1+2*x2*y1+3*x3*y1+2*x1*y2+3*x2*y2+x3*y2>=x1+2*x2+3*x3; x1*y1+2*x2*y1+3*x3*y1+2*x1*y2+3*x2*y2+x3*y2>=2*x1+3*x2+x3; x1+x2+x3=1; y1+y2=1;

执行后得到结果:

Feasible solution found at iteration: 72 Variable Value

X1 0.000000 Y1 0.000000 X3 0.000000 X2 1.000000 Y2 1.000000 Row Slack or Surplus 1 3.000000 2 0.000000 3 2.000000 4 1.000000 5 0.000000 6 0.000000 7 0.000000

即,得到此不等式组的一组解:

?x1?0?x2?1???x3?0 ?y1?0???y2?1

例10-6 在Lingo软件包中,求解下列方程组:

33?x13?x2?3?1?222?x1?x2?x3?2 ?x?x?x?123?1

解:在Lingo软件包中编程如下: model:

x1^3+x2^3+x3^3=3; x1^2+x2^2+x3^2=2;

7

x1+x2+x3=1; @free(x1); @free(x2); @free(x3);

执行后,Lingo提示没有得到可行解(即,没有得到实数解),给出的结果是: Variable Value X1 -0.2228950 X2 1.445790 X3 -0.2228950 Row Slack or Surplus 1 0.000000 2 -0.1896733 3 0.000000

我们可以验证x1??0.2228950,x2?1.445790,x3??0.228950不是方程组的解。

例10-7 在Lingo软件包中

(1)求解 lnx?sinx?0,其中lnx表示自然对数。 在Lingo软件包中编程如下: @log(x)-@sin(x)=0;

执行后得到结果:

Feasible solution found at iteration: 0 Variable Value X 2.219107 Row Slack or Surplus 1 0.000000

即,得到方程的根 x?2.219107。

(2)求解 lgx?sinx?0,其中lgx表示以10为底的常用对数。 在Lingo软件包中编程如下: @log(x)/@log(10)-@sin(x)=0;

执行后得到结果:

Feasible solution found at iteration: 0 Variable Value X 2.696257 Row Slack or Surplus 1 0.000000

即,得到方程的根 x?2.696257。

注:此方程共有3个根(用Mathematica软件包求出的根是:x?2.69626,

8