目标函数程序
function f = objfun(x,H)
f = -x*H*x';
约束条件程序
function [c,ceq] =confun(x)
% 非线性不等式约束
c = [];
% 非线性等式约束
ceq = x*x'-1;
x0是1*29行向量,已赋值;
l是1*29行向量,已赋值为0;
H 是29*29矩阵,已赋值;
调用fmincon函数
[x, fval] = fmincon(@(x)objfun(x,H),x0, [], [], [], [], l, [], @confun);
结果显示
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 500
Warning: Your current settings will run a different algorithm (interior-point) in
a future release.
> In fmincon at 505
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 2900 (the default value).
迭代次数超限制,但结果显然不受条件约束,请教为何?
2.44538174517926e+16 2.53751686447813e+16 4.78432047182774e+16 7.28633632307613e+16 2.27625959789299e+16 1.2786571 0133476e+16 6.86918182864094e+16 3.18967767788137e+16。。。。。。。