MATLAB: Fsolve

fsolve

Hi,
I'm solving a system of two non linear equations involving the same number of variables. I'm using the command fsolve, so before I've defined my functions:
function F = eqns(x)
F = [x(1).*A + (1-x(1)).*x(2).*B + (1-x(1)).*(1-x(2)).*C - b1;
x(1).*D + (1-x(1)).*x(2).*E + (1-x(1)).*(1-x(2)).*F - b2]
and save it as nle.m. A,B,C,D,E,F are constant values and b1 and b2 are my own data stored in two vectors in the workspace.
The command
x0 = [0 0];
[x,toll] = fsolve(@nle,x0)
solve my system only if I write the values of b1 and b2 in the equations defined into the m-file. Since I've thousand of b1 and b2 pairs, I would that fsolve find the zero capturing the current values of b1 and b2 from the workspace. How can I do this?
Thanks for the help

Best Answer

Hi,
add the b1, b2 to the function as variables:
function F = eqns(x, b1, b2)
F = ...
and call pass your b1, b2 to the call for fsolve:
b1 = 42;
b2 = 1;
fun = @(x) nle(x, b1, b2);
[x,toll] = fsolve(fun, x0);
Titus