MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

Too many input arguments - Fminsearch

Pedro Camargo さんによって質問されました 2019 年 3 月 19 日
最新アクティビティ Stephen Cobeldick
さんによって 編集されました 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
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
Stephen Cobeldick
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?

サインイン to comment.

タグ

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 件のコメント

Torsten
2019 年 3 月 19 日
Did you create your own "fminsearch" version ?
Pedro Camargo 2019 年 3 月 19 日
I haven't Torsten.
I am using the one that comes in the Optimization Toolbox.
Regards
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
>>

サインイン to comment.



Translated by