x2linprog.m
来自「实用化工计算机模拟:MATLAB在化学工程中的应用 附录光盘程序」· M 代码 · 共 47 行
M
47 行
% x2LinProg.m
% 线性规划--函数linprog()的简单应用示例
%
% Author: HUANG Huajiang
% Copyright 2003 UNILAB Research Center,
% East China University of Science and Technology, Shanghai, PRC
% $Revision: 1.0 $ $Date: 2002/05/31 $
%
% 优化问题Optimization problem:
% min -2x1 - x2 + x3
% s.t. x1 + x2 + 2x3 = 6
% x1 + 4x2 - x3 <= 4
% x1>=0,x2>=0,x3<=5
%
% 注意:原问题不是标准形式,要先把原问题转化为最小化标准形式
% Notes: The original problem should be firstly transformed into the
% standard form of minimization as followings:
% Min f'(x)
% s.t. AX <= b
% AeqX = beq
% LB <= X <= UB
% that is:
% min -2x1 - x2 - x3' % 技巧:以(-x3')代替x3 substitute (-x3')for x3
% s.t.
% x1 + 4x2 + x3' <= 4
% x1 + x2 - 2x3' = 6
% x1>=0,x2>=0,x3'>=-5
clear
clc
f = [-2 -1 -1]';
A = [1 4 1
0 0 0
0 0 0 ];
b = [4 0 0]';
Aeq = [1 1 -2];
beq = [6];
lb = [0 0 -5];
[x, fval] = linprog(f,A,b,Aeq,beq,lb)
x(3) = -x(3);
disp('The optimal sulution:')
disp(x)
disp('The objective value of the original function:')
disp(fval)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?