fmincon() error too many input arguments
Ältere Kommentare anzeigen
Dear peer users,
I got stuck with fmincon(). I tried different approaches but all showed different errors.
#1 codes are:
out=(f1-1)^2+(f2-1)^2+(f3-1)^2+(f4-1)^2;
x1=sym('x1',[1 4]);
subs(out,{x,phi,lamda2,lamda4},{x1(1),x1(2),x1(3),x1(4)});
out1=matlabFunction(out);
x0=[pi/6 pi/6 -1 -2];
lb=[0 0 -20 -20];
ub=[2*pi 2*pi 0 0];
[x1,fval,exitflag,output]=fmincon(out1,x0,[],[],[],[],lb,ub);
Errors are: ??? Error using ==> sym.matlabFunction>@()NaN Too many input arguments.
Error in ==> fmincon at 574 initVals.f = feval(funfcn{3},X,varargin{:});
Error in ==> solveequs_new at 77 [x1,fval,exitflag,output]=fmincon(out1,x0,[],[],[],[],lb,ub); Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
#2: Codes are out=(f1-1)^2+(f2-2)^2+(f3-3)^2+(f4-4)^2;
x1=sym('x1',[1 4]);
subs(out,{x,phi,lamda2,lamda4},{x1(1),x1(2),x1(3),x1(4)});
x0=[pi/6 pi/6 -1 -2];
lb=[0 0 -20 -20];
ub=[2*pi 2*pi 0 0];
[x1,fval,exitflag,output]=fmincon(@(x1)out,x0,[],[],[],[],lb,ub);
errors are ??? Error using ==> sym.sym>notimplemented at 2621 Function 'ge' is not implemented for MuPAD symbolic objects.
Error in ==> sym.sym>sym.ge at 823 notimplemented('ge');
Error in ==> nlconst at 739 elseif f >=0
Error in ==> fmincon at 758 [X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
Error in ==> solveequs_new at 76 [x1,fval,exitflag,output]=fmincon(@(x1)out,x0,[],[],[],[],lb,ub);
I understand I need to convert symbolic expression to function. But either of above is now working. Can you tell me why?
Thanks!
Antworten (1)
Walter Roberson
am 21 Jan. 2011
0 Stimmen
For more information about the "too many input parameters" problem, please see my comments in your previous question about minimization.
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!