Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fsolve anonymous function with two inputs

Tags:

matlab

I have the following function:

Eq = @(x1, x2) [x1-6, x2+3];
fsolve(Eq, [4 1])

but get the following error:

??? Input argument "x2" is undefined.

Error in ==> @(x1,x2)[x1-6,x2+3]


Error in ==> fsolve at 193
    fuser = feval(funfcn{3},x,varargin{:});

Error in ==> Untitled at 6
fsolve(Eq, [4, 1])

It works perfectly when I change the function to a one input function. Does anyone know what's going on here?

like image 764
Brian Avatar asked Aug 27 '10 00:08

Brian


1 Answers

You are passing in the vector [4 1] as the x1 argument.

Do this instead:

Eq = @(x) [x(1)-6, x(2)+3];
fsolve(Eq, [4 1])

The fsolve expects a function with one argument (either a vector or matrix), therefore a function with two arguments won't work.

like image 88
Gilead Avatar answered Nov 06 '22 23:11

Gilead