How do I solve an equation numerically for a grid of values and then plot the relationship with the dependent variable?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Torsten
2017-6-7
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 个评论
Torsten
2017-6-7
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!