gusucode.com > 使用Matlab在优化方面的程序项目 > 有约束条件多元变量函数最小值解法/example_2.m
% 使用平台 - Matlab7.0 %by akjuan %all rights preserved by www.4math.cn %2008.11 % 求最大值转化为求最小值 f=70*x1+120*x2 的最大值,当然x1,x2是有约束的。转化为求 % f=-(70*x1+120*x2)的最小值。 % 9*x1+4*x2<=3600;4*x1+5*x2<=2000;3*x1+10*x2<=3000;-x1,-x2<=0 clc clear f=[-70 -120]; A=[9 4;4 5;3 10]; B=[3600;2000;3000]; Aeq=[]; Beq=[]; lb=[0 0];ub=[inf inf]; x0=[1 1]; options=optimset('display','iter','Tolx',1e-8); [x,f,exitflag]=linprog(f,A,B,Aeq,Beq,lb,ub,x0,options) %[xmincon,fval,exitflag,output] = fmincon(@(x)-(70*x(1)+120*x(2)),x0,A,B,Aeq,Beq,lb,ub,[],options)