数学建模 二次规划(普通求解方式 && 罚函数法)

匿名 (未验证) 提交于 2019-12-03 00:05:01

matlab一般求解方式


示例

可以看出
12xTHx=2x124x1x2+4x22\frac12x^THx=2x_1^2-4x_1x_2+4x_2^2

[x1x2][abcd][x1x2]=ax12+(b+c)x1x2+dx22=4x128x1x2+8x22\left[ \begin{matrix} x_1 & x_2 \\ \end{matrix} \right] \left[ \begin{matrix} a&b \\ c&d \\ \end{matrix} \right] \left[ \begin{matrix} x_1 \\ x_2 \\ \end{matrix} \right]=ax_1^2+(b+c)x_1x_2+dx_2^2=4x_1^2-8x_1x_2+8x_2^2

{a=4d=8b+c=8\left\{ \begin{aligned} a=4\\ d=8\\ b+c=-8 \end{aligned} \right.

但是H必须是对称矩阵(二次型),所以b=c=-4

所以matlab代码

% 二次规划 clc h=[4,-4;-4,8]; f=[-6;-3]; a=[1 1;4 1]; b=[3;9]; [x,value]=quadprog(h,f,a,b,[],[],zeros(2,1))

结果

 Minimum found that satisfies the constraints.  Optimization completed because the objective function is non-decreasing in  feasible directions, to within the default value of the optimality tolerance, and constraints are satisfied to within the default value of the constraint tolerance.  <stopping criteria details>   x =      1.9500     1.0500   value =    -11.0250  >> 

外罚函数法

罚函数类似于拉格朗日对偶问题里面的松弛变量(KKT乘子),把非线性的约束放到目标函数里去,变成一个无约束的极值问题

P(x,M)P(x,M)被称为增广目标函数,原优化问题被转化为以P(x,M)P(x,M)为目标函数的无约束极值问题
minP(x,M)\min P(x,M)
两个问题的最优解一样

非常聪明的方式

结果

>> main 警告: Gradient must be provided for trust-region algorithm; using quasi-newton algorithm instead.  > In fminunc (line 395)   In main (line 1)   Local minimum possible.  fminunc stopped because the size of the current step is less than the default value of the step size tolerance.  <stopping criteria details>   Local minimum possible.  fminunc stopped because it cannot decrease the objective function along the current search direction.  <stopping criteria details>   x =      1.2205     0.8829   y =     10.2692
% 主函数 [x,y]=fminunc('fa',rand(2,1))
% 外罚函数法求解二次规划 function f=fa(x); M=50000; g=x(1)^2+x(2)^2+8; f=g-M*min(x(1),0)-M*min(x(2),0)-M*min(x(1).^2-x(2),0)+M*abs(-x(1)-x(2).^2+2);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!