2
$\begingroup$

I'm trying to run the following code. Unfortunately, there's a mistake in it, which I can't find. Can anyone of you help me? I guess it's very simple. Thanks so much in adavance!

Clear [pi, a, b, c, un, ma, pistern, gn, u, g, m];

pi[t_] := pi[t] = pi[t - 1] - a*(u[t] - un);

u[t_] := u[t] = u[t - 1] - b*(g[t] - gn);

g[t_] := g[t] = m[t] - pi[t];

m[t_] := m[t] = ma + c*(pistern - pi[t - 1]);

pistern = .02;
ma = .03;
gn = .01;
a = 1;
b = .35;
c = .8;
un = .05;

pi[0] = .02;
pi[1] = .025;

ListLinePlot[Table[pi[i], {i, 0, 65}], PlotStyle -> Black, 
 Frame -> True, Axes -> None, AspectRatio -> 1/3, 
 FrameLabel -> {"Zeit", "Inflationsrate"}, PlotRange -> All]
$\endgroup$
  • $\begingroup$ Sorry guys the last line of the code is missing:ListLinePlot[Table[pi[i], {i, 0, 65}], PlotStyle -> Black, Frame -> True, Axes -> None, AspectRatio -> 1/3, FrameLabel -> {"Zeit", "Inflationsrate"}, PlotRange -> All] $\endgroup$ – David D. Dec 6 '16 at 14:36
  • 1
    $\begingroup$ Would the definition of $pi$ have $a*(u[t-1] - un)$ instead of $a*(u[t] - un)$. Then you only need to specify $pi[0]$ and $u[0]$. $\endgroup$ – Suba Thomas Dec 6 '16 at 15:04
  • 2
    $\begingroup$ It seems that you have circular definitions, I.e. pi defined in terms of u and g, but g itself is defined in terms of pi. It would also help if you indicate exactly what errors you receive, how exactly the code is incorrect $\endgroup$ – MarcoB Dec 6 '16 at 15:05
2
$\begingroup$

How about an alternative approach

Clear[pi, a, b, c, un, ma, pistern, gn, u, g, m];
pistern=2/100; ma=3/100; gn=1/100; a=1; b=35/100; c=8/10; un=5/100;
g[t] = m[t]-pi[t];
m[t] = ma+c*(pistern-pi[t-1]);
FullSimplify[N[ComplexExpand[RSolve[{pi[t] == pi[t-1]-a*(u[t]-un),
  u[t] == u[t-1]-b*(g[t]-gn),pi[0] == 2/100, pi[1] == 25/1000}, {pi[t], u[t]}, t]]]]

which quickly gives you a closed form solution for pi[t] and u[t].

(* {{pi[t] -> 0.02 + 0.00863966 E^(-0.150052 t) Sin[0.737473 t], 
     u[t] -> 0.05 + E^(-0.150052 t) (-0.00675 Cos[0.737473 t] - 
   0.00120955 Sin[0.737473 t])}} *)

Plot[0.02+0.00863966 E^(-0.150052 t)Sin[0.737473 t], {t,0,65}, PlotRange->All]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.