How do I solve an equation numerically for a grid of values and then plot the relationship with the dependent variable?
1 view (last 30 days)
Show older comments
Hi!
I would like to solve the following equation for pi = linspace(0.95,1.08,30) eqn = pi*(pi-1)' - beta*pi*(pi-1)' == (v/(alpha*gamma))*(c+g)^((1+eps)/alpha)+((1-v)/gamma)*(c+g)*c^(-sigma); Where all the parameters are specified and only c is unknown. How can I solve this relationship for all the different values of pi and how can I plot this relationship with c?
Thanks in advance!
0 Comments
Accepted Answer
Torsten
on 7 Jun 2017
beta=...;
v=...;
alpha=...;
gamma=...;
g=...;
eps=...;
sigma=...;
c0=...;
pin=linspace(0.95,1.08,30);
for i=1:numel(pin)
pi_actual=pin(i);
fun=@(c) (1-beta)*pi_actual*(pi_actual-1)-(v/(alpha*gamma))*(c+g).^((1+eps)/alpha)+((1-v)/gamma).*(c+g).*c.^(-sigma);
c_sol(i)=fzero(fun,c0);
c0=c_sol(i);
end
plot(pin,c_sol)
Best wishes
Torsten.
2 Comments
Torsten
on 7 Jun 2017
I don't know what pi*(pi-1)' should indicate, but I assume that you want to determine c for each value of the vector pi, and that this single value should be inserted as pi*(pi-1). At least this is what the code from above does.
To get an impression of your function, you should plot it first and see whether it may have multiple zeros.
Best wishes
Torsten.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!