1
votes

I'm using this code:

y1=symfun(c^2+p^2, [c,p]);
y2=matlabFunction(y1)
[x,fval]=fminsearch(y2, [0 0])

but it returns

Error using makeFhandle/@(c,p)c.^2+p.^2
Not enough input arguments.

Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});

How can I get around this?

Note that I'm using symfun rather than a function-handle, because I'm adding several functions.

1

1 Answers

0
votes

I recommend looking at the documentation for fminsearch and, in particular, the the multi-dimensional examples given. The y2 function output from matlabFunction does not meet these requirements. You can change it by hand or you can try the 'Vars' option (as in this example). You'll need to specify your initial guess as a column vector, but your example can be re-written as:

syms c p;
y1 = symfun(c^2+p^2, [c,p]);
y2 = matlabFunction(y1,'Vars',{[c;p]})
[x,fval] = fminsearch(y2, [0;0])

which of course returns the trivial solution [0;0] in this case.