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!