# Simple linear 2nd order difference equation

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 = .02;
pi = .025;

ListLinePlot[Table[pi[i], {i, 0, 65}], PlotStyle -> Black,
Frame -> True, Axes -> None, AspectRatio -> 1/3,
FrameLabel -> {"Zeit", "Inflationsrate"}, PlotRange -> All]

• 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] – David D. Dec 6 '16 at 14:36
• Would the definition of $pi$ have $a*(u[t-1] - un)$ instead of $a*(u[t] - un)$. Then you only need to specify $pi$ and $u$. – Suba Thomas Dec 6 '16 at 15:04
• 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 – MarcoB Dec 6 '16 at 15:05

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 == 2/100, pi == 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] 