欢迎光临我的Blog,虽然这里还很简陋,但未来一定会焕发生机的!

线性规划例题及解答(1)——炎泽汐 の Blog

数模 yanzexi 3年前 (2022-06-14) 959次浏览 已收录 0个评论 扫描二维码
文章目录[隐藏]

1.1 分别用 Matlab 与 Lingo 求解下列线性规划问题

线性规划例题及解答(1)——炎泽汐 の Blog
Matlab 语句:

>> f = [-3; 1; 1];
>> a = [1, -2, 1; 4, -1, -2];
>> b = [11; -3];
>> aeq = [-2, 0, 1];
>> beq = [1];
>> [x,fval] = linprog(f, a, b, aeq, beq, zeros(3, 1));
>> x, fval = -fval

Lingo 语句:

model: 
      sets:
            row/1..2/: b;
            col/1..3/: c, x, aeq;
            links(row, col): a; 
      endsets 

      data:
            c = 3 -1 -1;	
            a = 1 -2 1 4 -1 -2;
            b = 11 -3;
            aeq = -2 0 1;
      enddata

      min = @sum(col:c*x);

      @for(row(i) : @sum(col(j) : a(i, j) * x(j) ) <= b(i));
      @sum(col : aeq * x) = 1;

1.2 分别用 Matlab 与 Lingo 求解下列线性规划问题

线性规划例题及解答(1)——炎泽汐 の Blog
      本题并不是一个标准的线性规划模型,需要先进行一些变形,记 ui = (xi + |xi|)/2 , vi = (xi – |xi|)/2。
得到Matlab 语句:

>> f = [1; 2; 3; 4; 1; 2; 3; 4];
>> aeq = [1, -1, -1, 1, 1, -1, -1, 1; 1, -1, 1, -3, 1, -1, 1, -3; 1, -1, -2, 3, 1, -1, -2, 3];
>> beq = [0; 1; -0.5];
>> [u,fval] = linprog(f, [], [], aeq, beq, zeros(8, 1));
>> x = [u(1) + u(5); u(2) + u(6); u(3) + u(7); u(4) + u(8);]
>> fval = -fval 

以及Lingo 语句:

model: 
      sets:
            row/1..3/: b;
            col/1..8/: c, x, aeq;
            links(row, col): a; 
      endsets 

      data:
            c = 1 2 3 4;	
            a = 1 -1 -1 1 1 -1 -1 1 1 -1 1 -3 1 -1 1 -3 1 -1 -2 3 1 -1 -2 3;
            b = 0 1 -0.5;
      enddata

      min = @sum(col:c*x);

      @for(row(i) : @sum(col(j) : a(i, j) * x(j) ) = b(i));
喜欢 (2)
[炎泽汐de收款码]
分享 (0)

您必须 登录 才能发表评论!