Fmincon too many input arguments
Mostrar comentarios más antiguos
function [x,fval,exitflag,output] = try_no_gradient(u0)
% This is an auto generated M-file from Optimization Tool.
% Start with the default options
options=optimset('largescale','off','display','iter');
% options = optimset;
% Modify options setting
% options = optimset(options,'Display', 'iter-detailed');
% options = optimset(options,'PlotFcns', { @optimplotx @optimplotfval });
% options = optimset(options,'Algorithm', 'interior-point');
% options = optimset(options,'DerivativeCheck', 'on');
% options = optimset(options,'GradConstr', 'off');
% options = optimset(options,'GradObj', 'off');
% Initial Design
u0=[0,0];
% fmincon called
[u,fval,exitflag,output] = ...
fmincon(@try_obj,u0,[],[],[],[],[],[],@try_con,options);
beta=fval
x(1)=u(1)*3.8+38
x(2)=u(2)*2.7+54
% function for objective
function [f]=try_obj(u)
f = sqrt(u(1)^2+u(2)^2);
% gradient of the objective
% nargout: required number of arguments in the output
% function for objective
function [g ceq]=try_con(u)
g=[];
x(1)=u(1)*3.8+38;
x(2)=u(2)*2.7+54;
ceq=[x(1)*x(2)-1140];
I've tried to use objective function, initial condition and constraint formulation for my fmincon optimization. It's throwing an error saying too many input arguments. I've passed 10 inputs still it says so. Can anyone help me to resolve it here?
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 5 de Mayo de 2022
Editada: John D'Errico
el 5 de Mayo de 2022
0 votos
How are you using it? That is, how did you call the function try_no_gradient(u0)?
When you get an error message, show the COMPLETE error message. Otherwise, we must guess what you did wrong. Show EVERYTHING in red.
My guess is that you do not understand how to pass in the vector u0.
1 comentario
Mohammad Nazmus Saquib
el 5 de Mayo de 2022
Categorías
Más información sobre Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!