我需要运行2变量函数的优化,我为其提供渐变。代码在“内点”算法中正常运行,但在我尝试'sqp'算法时,它在第一次交互后停留。第一个算法从我预期的值中给出了5%的误差,所以我真的需要检查SQP是否给了我更好的结果。
deltaml=10^(-4);
deltaE=10^(-2);
Eo=[0;1];
Elb=[0;0];
Eub=[100;100000000000];
Alg='sqp'
f1=[subs(fdelta,ml,ml+deltaml);subs(fdelta,E,E+deltaE)];
f2=[subs(fdelta,ml,ml+deltaml/2);subs(fdelta,E,E+deltaE/2)];
gradobj = (4*f2-3*f-f1)./[deltaml;deltaE];
objfungrad = matlabFunction(fdelta,gradobj,'vars',{t},'outputs',{'f','gradf'});
opts_grad=optimset('Algorithm',Alg,'TolFun',1e-16,'TolX',1e-16,'Display','off','GradObj','on');
[xgrad fval] = fmincon(objfungrad,Eo,[],[],[],[],[Elb],[Eub],[],opts_grad);>
运行sqp时出错:
Error using deal (line 38)
The number of outputs should match the number of inputs.
Error in C:\Program
Files\MATLAB\R2013a\toolbox\symbolic\symbolic\symengine.p
Error in C:\Program
Files\MATLAB\R2013a\toolbox\optim\optim\private\evalObjAndConstr.p>evalObjAndConstr
(line 135)
Error in C:\Program
Files\MATLAB\R2013a\toolbox\optim\optim\sqpLineSearch.p>sqpLineSearch
(line 287)
Error in fmincon (line 910)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
sqpLineSearch(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...
Error in symb_optm_ml_E_mult (line 54)
[xgrad fval] =
fmincon(objfungrad,Eo,[],[],[],[],[Elb],[Eub],[],opts_grad);