matlab非线性规划实例
x= 0.7647 1.0588
fval = -2.0294
则有: ������1 = 0.7647; ������2 = 1.0588 最优解为-2.0294
用 MATLAB 求解非线性规划练习题目
题目一
Min
非线性规划
������ ������1 , ������2 = −2������1 − 6������2 + ������1 2 − 2������1 ������2 + 2������2 2
������1 + ������2 ≤ 2 s.t −������1 + 2������2 ≤ 2 ������1 ≥ 0, ������2 ≥ 0 运用 MATLAB 数学软件求解: 在界面中输入以下代码:
>> a=[1 -1 ;-1 2]; c=[-2;-6]; A=[1 1;-1 2]; b=[2;2]; Aeq=[]; >> beq=[]; >> VLB=[0;0];VUB=[]; >> [x,z]=quadprog(a,c,A,b,Aeq,beq,VLB,VUB)
运行结果:
Warning: Large-scale method does not currently solve this problem formulation, switching to medium-scale method. > In D:\MATLAB6p5\toolbox\optim\quadprog.m at line 213 Optimization terminated successfully. x= 0.6667 1.3333 z =-8.2222
运行结果为:
Warning: Large-scale (trust region) method does not currently solve this type of problem, switching to medium-scale (line search). > In D:\MATLAB6p5\toolbox\optim\fmincon.m at line 213 f= -2
建立 M 文件,并输入:
function f=fun3(x); f=-x(1)-2*x(2)+(1/2)*x(1)^2+(1/2)*x(2)^2
在界面中输入:
>> x0=[1;1];
A=[2 3;1 4];b=[6;5]; Aeq=[];beq=[]; VLB=[0;0];VUB=[]; [x,fval]=fmincon('fun3',x0,A,b,Aeq,beq,VLB,VUB)
则有 ������1 = 0.6667,������2 = 1.3333 最优解为 − 8.2222
题目 2 非线性规划
Min ������ = −������1 − 2������2 + ������1 2 + ������2 2
2 2
1
1
2������1 + 3������2 ≤ 6 s.t ������1 + 4������2 ≤ 5 ������1 ≥ 0, ������2 ≥ 0
f= -2
f= -2.0000
f= -2ቤተ መጻሕፍቲ ባይዱ0294
f= -2.0294
f= -2.0294 Optimization terminated successfully: First-order optimality measure less than options.TolFun and maximum constraint violation is less than options.TolCon Active Constraints: 4