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!

採用された回答

Torsten
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 件のコメント
Sean
Sean 2017 年 6 月 7 日
編集済み: Sean 2017 年 6 月 7 日
Thanks a lot. But could I insert pi*(pi-1)' - beta*pi*(pi-1)' == (v/(alpha*gamma))*(c+g)^((1+eps)/alpha)+((1-v)/gamma)*(c+g)*c^(-sigma) after the fun=@(c)? Or should I drop the accent ('), I mean pi is a vector right?
It should be looking something like the picture I added, but by following these lines of code I seem to get negative consumption (c).
Torsten
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 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by