When I execute the following code in Example 2 from the documentation for FMINSEARCH.
function f = myfun(x,a)f = x(1)^2 + a*x(2)^2;a = 1.5; % define parameter first
x = fminsearch(@(x) myfun(x,a),0,1)
I receive the following error:
Error Messages: ??? Attempted to access x(2); index out of bounds because numel(x)=1.
Best Answer