tags:

views:

26

answers:

1

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?

+5  A: 

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.

Gilead
any way to do it without changing my equation?
Brian
Well, you could write another function `g = @(z) Eq(z(1),z(2))` and do `fsolve(g,[4 1])`. But ultimately, you have got to pass a single-argument function to `fsolve`.
Gilead

related questions