MATLAB: Fminsearch returns Not enough input arguments.

fminsearch

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!

Best Answer

x = fminsearch(@objfun,[2,2])
Related Question