Too many input arguments - Fminsearch

2 ビュー (過去 30 日間)
Pedro Camargo
Pedro Camargo 2019 年 3 月 19 日
編集済み: Stephen23 2019 年 3 月 20 日
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 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 20 日
編集済み: madhan ravi 2019 年 3 月 20 日
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
Stephen23
Stephen23 2019 年 3 月 20 日
編集済み: Stephen23 2019 年 3 月 20 日
@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?

サインインしてコメントする。

回答 (1 件)

Torsten
Torsten 2019 年 3 月 19 日
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 件のコメント
Pedro Camargo
Pedro Camargo 2019 年 3 月 19 日
I haven't Torsten.
I am using the one that comes in the Optimization Toolbox.
Regards
Pedro Camargo
Pedro Camargo 2019 年 3 月 19 日
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
>>

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by