Fmincon too many input arguments

4 ビュー (過去 30 日間)
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;
% 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
% fmincon called
[u,fval,exitflag,output] = ...
% 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)
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?


Walter Roberson
Walter Roberson 2022 年 5 月 5 日
You named your own function fmincon.m and at line 18 of that file you have a call to fmincon. You intended that the Mathworks fmincon should be called at that point but when matlab searched for fmincon it found it right there, the same file. . You should have named the file try_no_gradient.m if it starts by defining try_no_gradient

その他の回答 (1 件)

John D'Errico
John D'Errico 2022 年 5 月 5 日
編集済み: John D'Errico 2022 年 5 月 5 日
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 件のコメント
Mohammad Nazmus Saquib
Mohammad Nazmus Saquib 2022 年 5 月 5 日
Here's the error message:
"Error using fmincon
Too many input arguments.
Error in fmincon (line 18)
[u,fval,exitflag,output] = fmincon(@try_obj,u0,[],[],[],[],lbnd,ubnd,@try_con,options);"
Yes I'm comparatively new in this field. I'm still learning how to pass vector and its dimension related problems.





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by