用MATLAB fmincon函数求解一个有约束非线性问题,麻烦给个程序和结果,谢谢

2025-04-28 09:53:49
推荐回答(1个)
回答1:

求解代码如下:

function zd1381661017193379500
fmincon(@(x)4*(x(1)-5)^2+(x(2)-6)^2,[5 6],[],[],[],[],[],[],@noncon)
function [c,ceq] = noncon(x)
c(1)=-(x(1)^2+x(2)^2-64);
c(2)=x(2)-x(1)-10;
c(3)=x(1)-10;
ceq = [];

保存成M文件运行即可。

 

运行输出如下:

>> zd1381661017193379500
Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you
have specified. FMINCON will use the active-set algorithm instead. For information on applicable
algorithms, see Choosing the Algorithm in the documentation. 
> In fmincon at 504
  In zd1381661017193379500 at 2 
Warning: Your current settings will run a different algorithm (interior-point) in a future release. 
> In fmincon at 509
  In zd1381661017193379500 at 2
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints are 
satisfied to within the default value of the constraint tolerance.

Active inequalities (to within options.TolCon = 1e-06):
  lower      upper     ineqlin   ineqnonlin
                                     1
ans =
    5.0427    6.2105