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 CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by