fminsearch returns Not enough input arguments.

조회 수: 8 (최근 30일)
xueqi
xueqi 2016년 4월 16일
편집: Minghao Luo 2020년 3월 9일
Hi I have defined a function objfun as follows.
% function z = objfun(x)
z=x(1)^2+x(2)^2;
end
Then I tried to find its minimum (I know it is (0,0) ... I just want to do some tricks on top of this function) by using the following
% x = fminsearch(objfun,[2,2])
and got the following error
Not enough input arguments.
Error in objfun (line 3)
z=x(1)^2+x(2)^2;
Error in try1 (line 3)
x = fminsearch(objfun,[2,2])
Could anyone help me with this please? Thank you!

채택된 답변

Walter Roberson
Walter Roberson 2016년 4월 16일
x = fminsearch(@objfun,[2,2])
  댓글 수: 1
Minghao Luo
Minghao Luo 2020년 3월 9일
편집: Minghao Luo 2020년 3월 9일
I have met this annoying problem as well. I am very grateful your answer helped me solve it.
BTW I found you almost answered every question on this forum about fminsearch 'Not enough input arguments'. What a nice guy you are

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by