ProkopenkoV
ProkopenkoV

Reputation: 63

fsolve doesn't work with parametrized function handles

For example, I have defined the following function handles:

F = @(x, y, z)[x+y+z; x*y*z];  
funcc = @(x, y)F(x, y, 0);  

The call

res = fsolve(funcc, [10; 10]);  

Leads to an error:

Error using @(x,y)F(x,y,0)
Not enough input arguments.

Error in fsolve (line 219)
        fuser = feval(funfcn{3},x,varargin{:});

Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.

How can I fix it?

Upvotes: 1

Views: 56

Answers (1)

horchler
horchler

Reputation: 18484

Please re-read the requirements for the objective function in the documentation. The function must take a a single vector input and return a vector. You're trying to pass two scalars. Instead:

F = @(x, y, z)[x+y+z; x*y*z];
funcc = @(x)F(x(1), x(2), 0);  

The input to the objective function should match your initial guess, x0 ([10; 10]).

Upvotes: 3

Related Questions