matlab版本是R2010b。
程序如下:
function x=main(H)
v1=zeros(N,1);
v2=ones(N,1);
x0=[zeros(N-1,1);1];
opt=[];
x=fmincon(@objfun1,x0,[],[],[],[],v1,v2,@consfun1,opt);
function f=objfun1(x)
f=-x'*H*x;
end
function [c1,c2]=consfun1(x)
c1=[];
c2=x'*x-1;
end
end
c=main(H)
运行之后出现:Warning: Trust-region-reflective algorithm does not solve this type of problem, using active-set algorithm. Youcould also try the interior-point or sqp algorithms: set the Algorithm option to 'interior-point' or 'sqp' andrerun. For more help, see Choosing the Algorithm in the documentation.
> In fmincon at 472
In main at 6
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current search direction is less thantwice the default value of the step size tolerance and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
2
3
4
6
16
17
20
21
25
c= 0.3036
-0.0000
-0.0000
0.0000
0.1650
0.0000
0.0200
0.0738
0.0862
0.0020
0.2012
0.2933
0.1685
0.2939
0.2910
0.0000
0.0000
0.1943
0.0561
0.0000
0.0000
0.2886
0.2374
0.2950
-0.0000
0.2511
0.2241
0.2893
0.2772
这儿的c值也就是W值还满足约束条件吗?如果有错应该怎么改?