MATLAB Answers

0

Too many input arguments - Fminsearch

Asked by Pedro Camargo on 19 Mar 2019 at 11:04
Latest activity Edited by Stephen Cobeldick on 20 Mar 2019 at 7:07
Good morning guys,
I have been stuck with fminsearch for over a day, as I keep getting too many input arguments error for all the times I try to apply the equation.
I am really stuck and any help would be severely appreciated.
Best regards,
Pedro
function fmin
clear all %começar limpando a memória
x0=0; %parâmetro de valor inicial para a condição
options=optimset('Display','iter','TolFun',0.1)
[x]=fminsearch(@f,x0,options);
function fx=f(x)
fx=2*x^2-5*x+6;

  2 Comments

Remove clear all, add two end at the end of your code.
Good morning Madhan,
I tried it but there was not change. I keep getting the following message:
[x]=fminsearch(@f,x0,options);
Error using fminsearch
Too many input arguments.
>> which fminsearch -all % what do you get?
/Applications/MATLAB_R2018b.app/toolbox/matlab/optimfun/fminsearch.p
/Applications/MATLAB_R2018b.app/toolbox/matlab/optimfun/fminsearch.m % Shadowed
>>
If you see more than 2 files then you may have created your own function named as fminsearch.m , please verify it and get back with the results.
Also try the below:
which f -all
which fmin -all
Hey Madhan, I have tried fiddling with everything:
That is what I got. Apparently the files are all right, and there is not any hiccups on the fminsearch when I look through its files.
>> which fminsearch -all
C:\Program Files\MATLAB\R2018a\toolbox\matlab\optimfun\fminsearch.p
C:\Program Files\MATLAB\R2018a\toolbox\matlab\optimfun\fminsearch.m % Shadowed
>>
>> which f -all
'f' not found.
>> which fmin -all
'fmin' not found.
>> disp(Answer)
Sorry, out of ideas
@Pedro Camargo: This shows us that MATLAB cannot find your function file/s:
>> which f -all
'f' not found.
>> which fmin -all
'fmin' not found.
  1. Do you know what the MATLAB Search Path is, and how to check it?
  2. Did you save the files on the MATLAB Search Path, or in the current directory?
  3. Did you save both functions in the same Mfile, or in two files?
  4. What are the file names of those Mfile/s?
  5. Are those two functions the only things saved in those Mfile/s?
  6. Have you added any third-party toolboxees that might change the Search Path?
  7. What is your Current Directory?

Sign in to comment.

1 Answer

Answer by Torsten
on 19 Mar 2019 at 11:09

function fmin
x0=0; %parâmetro de valor inicial para a condição
options=optimset('Display','iter','TolFun',0.1)
[x]=fminsearch(@f,x0,options)
end
function fx=f(x)
fx=2*x^2-5*x+6;
end
Save the code as fmin.m and load it into MATLAB. For me, it worked without problems.

  5 Comments

Torsten
on 19 Mar 2019 at 11:23
Did you create your own "fminsearch" version ?
I haven't Torsten.
I am using the one that comes in the Optimization Toolbox.
Regards
Hey Madhan,
This is what shows up:
which fminsearch -all
C:\Program Files\MATLAB\R2018a\toolbox\matlab\optimfun\fminsearch.p
C:\Program Files\MATLAB\R2018a\toolbox\matlab\optimfun\fminsearch.m % Shadowed
>>

Sign in to comment.