MATLAB: Not getting the right output using ‘fsolve’

fsolve

Hi all,
I am trying to practice with 'fsolve' and have not figured out fully what's been going on with the following code. Can anyone please shed some light on it?
function N=productivity1(N,Ac,Aw)
global Thetac Thetaw tau a b
N=[N(1),N(2)];
N=[N(1)-(Thetac/a)^(1/b)*(1+tau)*Ac;
N(2)-(Thetaw/a)^(1/b)*(1+tau)*Aw;
N(1)+N(2)-1]; %this meant to be a constraint...
end
N0=[0.7,0.3]; %initial guess for x
option=optimset('Display','iter');
result=fsolve(@(N)productivity1(N,Ac0,Aw0),N0,option);*
I must be coding it incorrectly. Much appreciated! Thank you

Best Answer

R,
Below is what I think you're trying to implement. Note that, according to your own description, Ac and Aw are unknowns so you shouldn't be treating them as constants, as you are in your original post. Further, it makes little sense to "solve" for N1 and N2 when they depend so trivially on Ac and Aw. I've removed them accordingly and simply solve for Ac and Aw.
Your practice example is a doubtful one, however, because there are more unknowns than equations, leading to infinite solutions. That would be true whether you include N1 and N2 as unknowns or not. However, fsolve does succeed in finding one of the infinite solutions.
q1=(Thetac/a)^(1/b)*(1+tau);
q2=(Thetaw/a)^(1/b)*(1+tau);
option=optimset('Display','iter');
fun=@(x)productivity1(x,q1,q2);
x0=[Ac,Aw]; %initial guess for x
result=fsolve(fun,x0,option)
function F=productivity1(x,q1,q2)
N1=q1*x(1);
N2=q2*x(2);
F=N1+N2-1;