solution to a single nonlinear equation with a parameter

I want to get the solution to a nonlinear single equation, that carries a parameter the functional form is complicated:
the function that I want to solve is:
w = (1-alpha)*A*x^alpha;
r = alpha*A*x^(alpha-1);
xs = d2*(1+r);
d1*(w-(r-n)*b)/(1-xs)=(1+n)*(x+b); % this is the function I looking
The parameter that I want to experiment in order to find different solutions is the b,
I have created this function
function y = f(x,b)
global alpha A d1 d2 n
w = (1-alpha)*A*x^alpha;
r = alpha*A*x^(alpha-1);
xs = d2*(1+r);
y = d1*(w-(r-n)*b)/(1-xs)-(1+n)*(x+b);
end
where the other parameters of the equations are:
global alpha d1 d2 n debt
beta =0.3; % discount factor
delta =0.10; % altruism
A =9.37; % TFP
alpha =0.3; % income share of capital
n =1.81; % growth rate of population
d1 =(1+delta)*beta/(1+(1+delta)*beta); % MPS
d2 =delta/(1+n)*(1+delta); % degree affecting altruism
Can someone assist me with how to call fzero, in order to look for solutions at different values of b ? As guidance, b is between (0,0.10)

Respuestas (1)

Matt J
Matt J el 10 de Nov. de 2016
Editada: Matt J el 10 de Nov. de 2016
Get rid of the global variables (because they're just bad) and redefine the function as follows
function y = f(x,b, alpha, A, d1, d2, n)
w = (1-alpha)*A*x^alpha;
r = alpha*A*x^(alpha-1);
xs = d2*(1+r);
y = d1*(w-(r-n)*b)/(1-xs)-(1+n)*(x+b);
end
Then to use fzero,
beta =0.3; % discount factor
delta =0.10; % altruism
A =9.37; % TFP
alpha =0.3; % income share of capital
n =1.81; % growth rate of population
d1 =(1+delta)*beta/(1+(1+delta)*beta); % MPS
d2 =delta/(1+n)*(1+delta); % degree affecting altruism
xsol = fzero(@(x) f(x,b, alpha, A, d1, d2, n) , x0)

4 comentarios

msh
msh el 10 de Nov. de 2016
Thank you, I always had a problem with an error, and indeed once I removed the global values it was fixed. But, I cannot find a solution and returns NAN, which should not be the case.
What value of the initial guess x0 did you choose and why did you choose that value?
msh
msh el 10 de Nov. de 2016
I just make random guess, x= should be nearly 0.5 to 1.5. So I play with values in this interval.
Matt J
Matt J el 10 de Nov. de 2016
Editada: Matt J el 10 de Nov. de 2016
x= should be nearly 0.5 to 1.5. So I play with values in this interval.
Did you plot your function to verify if this is true? When I plot it, I see that it comes nowhere near zero in the interval [0.5,1.5] and in fact appears to decrease monotonically in [0.5,inf] starting from a value of about -0.8 at x=0.5.

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Programming and Mixed-Integer Linear Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

msh
el 10 de Nov. de 2016

Editada:

el 10 de Nov. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by