⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x2linprog.m

📁 matlab介绍
💻 M
字号:
% 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -