Not getting the right output using 'fsolve'
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mrrox
el 29 de Nov. de 2014
Comentada: mrrox
el 1 de Dic. de 2014
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
3 comentarios
Respuesta aceptada
Matt J
el 29 de Nov. de 2014
Editada: Matt J
el 29 de Nov. de 2014
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;
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!