我在用fmincon的时候遇到参数不足的错误,但是不知道哪里出问题了,求老师们帮忙
这是我的代码:
function [va,lamda] = optxestimatecon(wv,wa,g)
coder.extrinsic('myfmincon' )
x0=[1;1];
y=myfmincon(x0,wv,wa,g);
va=y(1);
lamda=y(2);
end
function y=myfmincon(x0,wv,wa,g)
f=@(x)myfuncon(x,wv,wa,g);
A = [];b = [];
Aeq = []; beq = [];
x=[0;0];
[x,fval]=fmincon(@myfuncon,x0,A,b,Aeq,beq,[0;-2*pi],[100;2*pi]);
y=x;
end
function F = myfuncon(x,wv,wa,g)
F=-(-g*(wv(3,1)-x(1)*sin(x(2)))/(x(1)*cos(x(2))+wv(1,1))+x(1)*(wa(1,1)*cos(x(2))-wa(3,1)*sin(x(2)))+wv(1,1)*wa(1,1)+wv(3,1)*wa(3,1));
end
然后是报错的:
输入参数的数目不足。
出错 myfmincon>myfuncon (line 17)
F=-(-g*(wv(3,1)-x(1)*sin(x(2)))/(x(1)*cos(x(2))+wv(1,1))+x(1)*(wa(1,1)*cos(x(2))-wa(3,1)*sin(x(2)))+wv(1,1)*wa(1,1)+wv(3,1)*wa(3,1));
出错 fmincon (line 552)
initVals.f = feval(funfcn{3},X,varargin{:});
出错 myfmincon (line 6)
[x,fval]=fmincon(@myfuncon,x0,A,b,Aeq,beq,[0;-2*pi],[100;2*pi]);
出错 optxestimatecon (line 5)
y=myfmincon(x0,wv,wa,g);
原因:
Failure in initial objective function evaluation. FMINCON cannot continue.