Chapter 3

Needs["DiscreteMath`RSolve`"]

Question 1

({{(i), (Subscript[y, t + 2]) = (Subscript[y, t + 1]) - 0.5  (Subscript[y, t]) + 1, second - order, linear, autonomous, non - homogeneous}, {(ii), (Subscript[y, t + 2]) = 2  (Subscript[y, t]) + 3, second - order,  
            linear,  autonomous, non - homogeneous}, {(iii), (((Subscript[y, t + 1]) - (Subscript[y, t]))/(Subscript[y, t])) = 4, first - order, 
             linear,  autonomous,  homogeneous}, {(iv), (Subscript[y, t + 2]) - 2  (Subscript[y, t + 1]) + 3  (Subscript[y, t]) = t, second - order,  linear,  non - autonomous,  
            non - homogeneous}})

Question 2

RSolve[ {P[t] == (1 + r) P[t - 1]  -  R,  P[0] == P0}, P[t], 
      t]

Question 3

For periods 0 to n,
0	(Subscript[P, 0])
1	(1 + r) (Subscript[P, 0]) - (Subscript[R, 1])
2	\(TraditionalForm
      \`\((1 + r)\)[\((1 + r)\) P\_0 - R\_1] - R\_2 = 
        \(\((1 + r)\)\^2\) P\_0 - \((1 + r)\) R\_1 - R\_2\)
3	\(TraditionalForm
      \`\((1 + r)\)[\(\((1 + r)\)\^2\) P\_0 - \((1 + r)\) R\_1 - R\_2] - 
          R\_3 = \(\((1 + r)\)\^3\) P\_0 - \(\((1 + r)\)\^2\) R\_1 - 
          \((1 + r)\) R\_2 - R\_3\)
4	\(TraditionalForm
      \`\((1 + r)\)[
            \(\((1 + r)\)\^3\) P\_0 - \(\((1 + r)\)\^2\) R\_1 - 
              \((1 + r)\) R\_2 - R\_3] - R\_4 = 
	
        \(\((1 + r)\)\^4\) P\_0 - \(\((1 + r)\)\^3\) R\_1 - 
          \(\((1 + r)\)\^2\) R\_2 - \((1 + r)\) R\_3 - R\_4\)\(TraditionalForm
      \`\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ⋮\)

n	\(TraditionalForm
      \`\(\((1 + r)\)\^n\) P\_0 - \(\((1 + r)\)\^\(n - 1\)\) R\_1 - 
        \(\((1 + r)\)\^\(n - 2\)\) \(R\_2\) ⋯\ \  - 
        \((1 + r)\) R\_\(n - 1\) - R\_n\)

Hence
	\(TraditionalForm
      \`P\_n = \(\((1 + r)\)\^n\) P\_0 - \(\((1 + r)\)\^\(n - 1\)\) R\_1 - 
          \(\((1 + r)\)\^\(n - 2\)\) \(R\_2\) ⋯\ \  - 
          \((1 + r)\) R\_\(n - 1\) - R\_n\)

It is possible to check the consistency of this answer with the previous one. Let (Subscript[R, k]) = R for all k. Then
	\(TraditionalForm
      \`P\_n = \(\((1 + r)\)\^n\) P\_0 - \(\((1 + r)\)\^\(n - 1\)\) R - 
          \(\((1 + r)\)\^\(n - 2\)\) R⋯\ \  - \((1 + r)\) R - 
          R\)

Consider the terms involving R. Let the sum of these be denoted S. Then

S = (∑_(k = 0)^(n - 1))(1 + r)^k R

Substituting this into (Subscript[P, n]) we obtain
	\(TraditionalForm
      \`P\_n = \(\(\((1 + r)\)\^n\) P\_0 - \(R\/r\)[\((1 + r)\)\^n - 1]\  = \ 
          \(\((1 + r)\)\^n\) \((P\_0 - R\/r)\) + R\/r\)\)

Question 4

(i)

RSolve[ {y[t + 1] == -(1/2) y[t] + 3, y[0] == y0}, y[t], 
      t]

y1 = 2 + (((-(1/2)))^t) (-2 + y0)

points1 = Table[ {t, y1},  {t, 0, 20}]  /.  y0 -> 1;

ListPlot[points1,  PlotJoined -> True,  
        PlotRange -> All];

(ii)

RSolve[ {2*y[t + 1] == -3*y[t] + 4, y[0] == y0}, y[t], 
      t]

y2 = 
      (4/5) + (1/5) (((-(3/2)))^t) (-4 + 5 y0)

points2 = Table[ {t, y2},  {t, 0, 20}]  /.  y0 -> 1;

ListPlot[points2,  PlotJoined -> True, 
        PlotRange -> All];

(iii)

RSolve[{y[t + 1] == -y[t] + 6, y[0] == y0}, y[t], t]

y3 = 3 + (((-1))^t) (-3 + y0)

points3 = Table[ {t, y3}, {t, 0, 20}]  /.  y0 -> 1;

ListPlot[points3,  PlotJoined -> True, 
        PlotRange -> All];

(iv)

RSolve[ {y[t + 1] == (1/2)  y[t] + 3, y[0] == y0}, y[t], 
      t]

y4 = 6 + (2^(-t)) (-6 + y0)

points4 = Table[ {t, y4}, {t, 0, 20}]  /.  y0 -> 1;

ListPlot[points4, PlotJoined -> True, PlotRange -> All];

(v)

RSolve[ {4*y[t + 2] + 4*y[t + 1] - 2 == 0, y[0] == y0}, y[t], 
      t]

y5 = (1/4) + (1/4) (((-1))^t) (-1 + 4 y0)

points5 = Table[ {t, y5}, {t, 0, 20}]  /. y0 -> 1;

ListPlot[ points5,  PlotJoined -> True, 
        PlotRange -> All];

Question 5

(i)

Solve[a == a^3 - a^2 + 1, a]

Factor[a^3 - a^2 - a + 1]

(ii)

f[y_] := y^3 - y^2 - y + 1

f[1]

Plot[f[y],  {y, -2, 2}];

Question 6

Although this requests using a spreadsheet, we can use Mathematica equally well.

(i)

Clear[f, g]

f[y_] := (1 + a)*y - b*y^2

data1A = 
        NestList[f, 1, 10]  /.  {a -> 1.5,  b -> 0.1};

g[y_] := ((1 + a)*y)/(1 + b*y)

data1B = 
        NestList[g, 1, 10]  /.  {a -> 1.5,  b -> 0.1};

graph1A = ListPlot[data1A,  PlotJoined -> True];

graph1B = ListPlot[data1B, PlotJoined -> True];

Needs["Graphics`MultipleListPlot`"]

MultipleListPlot[data1A, data1B, PlotJoined -> True];

(ii)

data2A = 
        NestList[f, 22, 10]  /.  {a -> 1.5,  b -> 0.1};

data2B = 
        NestList[g, 22, 10]  /.  {a -> 1.5, b -> 0.1};

MultipleListPlot[data2A, data2B, PlotJoined -> True,  
        PlotRange -> All,  AxesOrigin -> {0, 6}];

(iii)

data3A = 
        NestList[f, 1, 10]  /.  {a -> 2.2,  b -> 0.1};

data3B = 
        NestList[g, 1, 10]  /.  {a -> 2.2,  b -> 0.1};

MultipleListPlot[data3A, data3B, PlotJoined -> True];

(iv)

data4A = 
        NestList[f, 25, 10]  /.  {a -> 2.2,  b -> 0.1};

data4B = 
        NestList[g, 25, 10]  /.  {a -> 2.2,  b -> 0.1};

MultipleListPlot[data4A, data4B, PlotJoined -> True,  
        AxesOrigin -> {0, 16}];

data5A = 
        NestList[f, 11.5, 10]  /.  {a -> 1.8,  b -> 0.15};

data5B = 
        NestList[g, 11.5, 10]  /.  {a -> 1.8,  b -> 0.15};

MultipleListPlot[data5A, data5B, PlotJoined -> True,  
        AxesOrigin -> {0, 11.4}];

Question 7

Clear[a, b, c, d, p]

RSolve[ {p[t] == ((a - c)/b) - (d/b)*p[t - 1], 
        p[0] == p0}, p[t], t]

sol1 = 
      RSolve[ {p[t] == ((a - c)/b) - (d/b)*p[t - 1], 
            p[0] == p0}, p[t], t]  /. {a -> 10, b -> 3, c -> 2, d -> 1, 
          p0 -> 1}

Simplify[
      (1/4) (3^(-t)) (6 (((-1))^t) - 2 (3^t) + 
            10 (-(((-1))^t) + (3^t)))]

sol2 = 
      RSolve[ {p[t] == ((a - c)/b) - (d/b)*p[t - 1], 
            p[0] == p0}, p[t], t]  /. {a -> 25, b -> 4, c -> 3, d -> 4, 
          p0 -> 1}

Simplify[
      (2^(-3 - 2 t)) (7 (((-4))^t) - 
            3 (4^t) + (((-1))^t) (4^(1 + t)) + 
            25 (-(((-4))^t) + (4^t)))]

sol3 = 
      RSolve[ {p[t] == ((a - c)/b) - (d/b)*p[t - 1], 
            p[0] == p0}, p[t], t]  /. {a -> 45, b -> 5/2, c -> 5, d -> 15/2, 
          p0 -> 1}

Simplify[
      (2^(-1 + t)) (5^(-1 - t)) ((((-3))^t) (2^(-1 - t)) (5^(1 + t)) - 
            (2^(-t)) (5^(1 + t)) + (((-3))^t) (2^(-1 - t)) (5^(2 + t)) + 
            45 (-(((-(15/2)))^t) + ((((5/2)))^t)))]

sol1[[1, 1, 2]]

Simplify[
      (1/4) (3^(-t)) (6 (((-1))^t) - 2 (3^t) + 
            10 (-(((-1))^t) + (3^t)))]

p1 = Table[ {t, sol1[[1, 1, 2]]} , {t, 0, 20}];

ListPlot[p1,  PlotJoined -> True,  PlotRange -> All];

p2 = Table[ {t, sol2[[1, 1, 2]]} , {t, 0, 20}];

ListPlot[p2,  PlotJoined -> True,  PlotRange -> All];

p3 = Table[ {t, sol3[[1, 1, 2]]} , {t, 0, 20}];

ListPlot[p3, PlotJoined -> True];

Question 8

The system of equations is
     (Subscript[C, t]) = a + b (Subscript[Y, t - 1])(Subscript[E, t]) = (Subscript[C, t]) + (Subscript[I, t]) + (Subscript[G, t])(Subscript[Y, t]) = (Subscript[E, t])
Substituting, where I and G are exogenous, we obtain
     (Subscript[Y, t]) = (a + I + G) + b (Subscript[Y, t - 1])

Solve[Y == (a + I + G) + b Y, Y]

RSolve[{Y[t] == (a + I + G) + b Y[t - 1], Y[0] == Y0}, Y[t], 
      t]

Apart[(((-1 + (b^t)) (I + a + G - Y0) + (-1 + (b^(1 + t))) Y0)/(-1 + b))]

Hence, the general solution is
	\(TraditionalForm
      \`Y\_n = \((\(a + I + G\)\/\(1 - b\))\) + 
          \(b\^n\)(Y\_0 - \(a + I + G\)\/\(1 - b\))\)

which is stable so long as 0 < b < 1.

Question 9

Readily obtain the difference equation Y(t) = (a + I + G) + b Y(t - 1)

Clear[Y]

solY = 
      RSolve[ {Y[t] == (50 + 10 + 20) + 0.8*Y[t - 1],  Y[0] == 20}, 
        Y[t], t]

Ystar = (50 + 10 + 20)/(1 - 0.8)

Yu = (1 + 0.01)*Ystar

Yl = (1 - 0.01)*Ystar

dataY = Table[ {t, solY[[1, 1, 2]]}, {t, 0, 30}];

ListPlot[dataY,  PlotJoined -> True,  
        AxesLabel -> {"t", "Y(t)"}];

lowerline = Table[{t, Yl},  {t, 0, 30}];

upperline = Table[{t, Yu},  {t, 0, 30}];

MultipleListPlot[dataY, lowerline, upperline,  PlotJoined -> True,  
        AxesLabel -> {"t", "Y(t)"} ];

solY2 = 
      RSolve[ {Y[t] == (50 + 10 + 20) + 1.2*Y[t - 1],  Y[0] == 20}, 
        Y[t], t]

dataY2 = 
        Table[ {t, solY2[[1, 1, 2]]},  {t, 0, 30}];

MultipleListPlot[dataY2, lowerline, upperline, PlotJoined -> True, 
        AxesLabel -> {"t", "Y(t)"}];

solY3 = 
      RSolve[ {Y[t] == (50 + 10 + 20) + 0.9*Y[t - 1],  Y[0] == 20}, 
        Y[t], t]

dataY3 = Table[{t, solY3[[1, 1, 2]]}, {t, 0, 30}];

Ystar3 = (50 + 10 + 20)/(1 - 0.9)

Yl3 = (1 - 0.01)*Ystar3

Yu3 = (1 + 0.01)*Ystar3

lowerline3 = Table[{t, Yl3}, {t, 0, 30}];

upperline3 = Table[{t, Yu3}, {t, 0, 30}];

MultipleListPlot[dataY3, lowerline3, upperline3, 
        PlotJoined -> True,  
        AxesLabel -> {"t", "Y(t)"}];

Question 10

(i)

Substituting we obtain the difference equation
	p(t) =((a - c)/b) -  (\(TraditionalForm
      \`\(d\/b)\) \((1 - e)\) \(p(t - 1)\) - 
        \((\(d\ e\)\/b)\) \(p(t - 2)\)\)
which is a second-order nonhomogeneous difference equation.

(ii)

Clear[p, p0, p1]

Substituting the values a = 10, b = 3, c = 2, d = 1 and e = 0.5 we can solve the following difference equation

solp = 
      RSolve[ {p[
              t] == (8/3)  -  (1/6) p[t - 1] - (1/6) 
                p[t - 2],  p[0] == 2,  p[1] == 3}, p[t], t]

seriesp = 
        Table[{t, N[solp[[1, 1, 2]]]}, {t, 0, 20}];

ListPlot[seriesp,  PlotJoined -> True,  PlotRange -> All,  
        AxesLabel -> {"t", "p(t)"}];

Furthermore, \(TraditionalForm
      \`q \((t)\)\  = \ 
        c\  + \ \(d[\(p(t - 1) - e \((p(t - 1) - p(t - 2)\)]\)\)\). Substituting the same values we find \(TraditionalForm
      \`q \((t)\)\  = \ 2 + 0.5 \( p(t - 1)\) + 0.5  p \((t - 2)\)\)

pricelist = Table[N[solp[[1, 1, 2]]], {t, 0, 20}];

pricelist2 = 
      Table[p[t] = N[solp[[1, 1, 2]]], {t, 0, 20}]

qlist = 
      Table[{t,  2 + 0.5*p[t - 1] + 0.5*p[t - 2]},  {t, 2, 20}]

ListPlot[qlist,  PlotJoined -> True,  PlotRange -> All,  
        AxesOrigin -> {2, 3.8},  
        AxesLabel -> {"t", "q(t)"}];

Question 11

Clear[p]

ds1 = 
      RSolve[{p[t] == (8/3) - (1/3)*p[t - 1], p[0] == 1}, p[t], 
        t]

ds2 = 
      RSolve[ {p[t] == (10/4) - (1/4)*p[t - 1], p[0] == 1}, p[t], 
        t]

ds1list = Table[{t, N[ds1[[1, 1, 2]]]}, {t, 0, 20}];

ds2list = Table[{t, N[ds2[[1, 1, 2]]]}, {t, 0, 20}];

MultipleListPlot[ds1list, ds2list, PlotJoined -> True,  
        PlotRange -> All];

dsdata = 
      TableForm[
        Table[{t, N[ds1[[1, 1, 2]]], N[ds2[[1, 1, 2]]]}, {t, 0, 
            20}] ]

pstar1 = Solve[p == (8/3) - (1/3) p, p]

Clear[p]

pstar2 = Solve[p == (10/4) - (1/4) p, p]

ds3 = 
      RSolve[{p[t] == (14/3) - (4/3) p[t - 1], p[0] == 1}, p[t], 
        t]

ds4 = 
      RSolve[ {p[t] == 6 - 2  p[t - 1], p[0] == 1}, p[t], t]

ds3list = Table[{t, N[ds3[[1, 1, 2]]]}, {t, 0, 20}];

ds4list = Table[{t, N[ds4[[1, 1, 2]]]}, {t, 0, 20}];

MultipleListPlot[ds3list, ds4list, PlotJoined -> True];

Question 12

Clear[p]

pbar = Solve[25 - 4*p == 3 + 4  p, p]

qbar = 25 - 4*pbar[[1, 1, 2]]

newp = 
      RSolve[{25 - 4  p[t] == 3 + 4  p[t - 1], p[0] == p0}, p[t], 
        t]

newlistp = 
      Table[p[t] = N[newp[[1, 1, 2]]], {t, 0, 20}]  /. 
        p0 -> 1

newlistp2 = 
      Table[p[t] = N[newp[[1, 1, 2]]], {t, 0, 20}]  /. 
        p0 -> 3

Question 13

Here we use Mathematica to solve the 3-cycle problem.

Clear[f, x]

f[x_] = 3.84  x (1 - x)

eq1 = f[f[f[x]]]

sol1 = Solve[eq1 == x, x]

Question 14

Assume \(TraditionalForm\`y\_1 = \(Y\^*\)\) and \(TraditionalForm\`y\_2 = \(tY\^*\)\) are linearly dependent, then
	\(TraditionalForm\`\(b\_1\) \(Y\^*\) + b\_2\ t\ \(Y\^*\) = 0\)
which implies that (Subscript[b, 1]) + (Subscript[b, 2]) t = 0 for all t only if (Subscript[b, 1]) = (Subscript[b, 2]) = 0. Hence \(TraditionalForm\`\(Y\^*\)\) and \(TraditionalForm\`t\ \(Y\^*\)\) are linearly independent.

Question 15

(i) Assume F if linearly homogeneous, then
	\(TraditionalForm
      \`Y\_t\/\(A\_t\ L\_t\) = 
        \(F(K\_t\/\(A\_t\ L\_t\), 1) = f(\(k\_t\)\&^)\)\)\(TraditionalForm\`	i . e . \ \ \ \ \ y\&^\_t = f(k\&^\_t)\)
Since \(TraditionalForm
      \`K\_\(t + 1\) - \((1 - δ)\) K\_t = s\ Y\_t\) then

	\(TraditionalForm
      \`K\_\(t + 1\)\/\(A\_t\ L\_t\) - 
          \((1 - δ)\) K\_t\/\(A\_t\ L\_t\) = 
        \(s\ Y\_t\)\/\(A\_t\ L\_t\)\)
	
	(((Subscript[K, t + 1])/((Subscript[A, t + 1]) (Subscript[L, t + 1])))) 
              (((Subscript[A, t + 1]) (Subscript[L, t + 1]))/((Subscript[A, t]) (Subscript[L, t])))-(1 - δ)((Subscript[K, t])/((Subscript[A, t]) (Subscript[L, t])))=((s (Subscript[Y, t]))/((Subscript[A, t]) (Subscript[L, t])))
	
	\(TraditionalForm
      \`\(k\&^\_\(t + 1\)\)(A\_\(t + 1\ L\_\(t + 1\)\)\/\(A\_t\ L\_t\)) - 
          \((1 - δ)\) k\&^\_t = s\ \(f(k\&^\_t)\)\)
	
But
	\(TraditionalForm
      \`A\_\(t + 1\ L\_\(t + 1\)\)\/\(A\_t\ L\_t\) = 
        \(\((\(\(γ\^\(t + 1\)\) A\_0\)\/\(γ\^t\ A\_0\))\) 
            L\_\(t + 1\)\/L\_t = γ(n + 1)\)\)
Therefore
	\(TraditionalForm
      \`\(γ(n + 1)\) k\&^\_t - \((1 - δ)\) k\&^\_t = 
        s\ \(f(k\&^\_t)\)\)
or
	\(TraditionalForm
      \`k\&^\_\(t + 1\) = 
        \(\((1 - δ)\) k\&^\_t + s\ \(f(k\&^\_t)\)\)\/\(γ(1 + n)
            \)\)

(ii) Let \(TraditionalForm\`\(k\&^\^*\)\) denote the positive equilibrium, then
	\(TraditionalForm
      \`k\&^\_\(t + 1\) = 
        f(\(k\&^\^*\)) + 
          \(\(f\^′\)(\(k\&^\^*\))\) \((k\&^\_t - \(k\&^\^*\))\)\)
But \(TraditionalForm\`f(\(k\&^\^*\)) = \(\(k\&^\)\^*\)\) and
	\(TraditionalForm
      \`\(f\^′\)(\(k\&^\^*\)) = 
        \(1 - δ\)\/\(γ(1 + n)\) + 
          \(s\ \(\(f\^′\)(\(k\&^\^*\))\)\)\/\(γ(1 + n)\)\)
Hence
	\(TraditionalForm
      \`k\&^\_\(t + 1\) = 
        \(k\&^\^*\) + 
          \((\(1 - δ\)\/\(γ(1 + n)\) + 
                \(s\ \(\(f\^′\)(\(k\&^\^*\))\)\)\/\(γ(1 + n)\))
              \) \((k\&^\_t - \(k\&^\^*\))\)\)

Question 16

Solving for (p^e)(t - 1) gives \(TraditionalForm
      \`\(p\^e\)(t - 1) = \(a - c\)\/d - \((b\/d)\) \(p(t - 1)\)\), using this we obtain the difference equation

\(\(p\_t = 
        \((1 - \(λ \((b + d)\)\)\/b)\) p\_\(t - 1\) + 
          \(λ \((a - c)\)\)\/b	\)\)

Clear[pbar, qbar, p, q, a, b, c, d]

pbar = 
      Solve[p == (1 - ((λ (b + d))/b)) 
              p + ((λ (a - c))/b), p]

qbar = a - b*pbar[[1, 1, 2]]

((b c + a d)/(b + d))

RSolve[ {u[t] == (1 - ((λ (b + d))/b)) u[t - 1], 
        u[0] == u0}, u[t], t]

{{u[t] -> 
          u0 (((1 - (((b + d) λ)/b)))^t)}}

Solve[
      1 - (((b + d) λ)/b) == -1, λ]

Solve[1 - (((b + d) λ)/b) == 1, λ]

Question 17

Our equation is (Subscript[P, n]) = (((1 + r))^n) ((Subscript[P, 0]) - (R/r)) + (R/r). In the present problem, taking note that we are dealing in months and the interest rate is per annum, we require zero payment after n = 3x12 = 36 monthly payments. Hence:
	(Subscript[P, n]) = 0, (Subscript[P, 0]) =  8000, r = (0.075/12) = 0.00625 and R = m = fixed monthly payment.

NSolve[(((1 + 0.00625))^36) (8000 - (m/((0.075/12)))) + 
          (m/((0.075/12))) == 0, m]

Hence the monthly payment is £248.85

Question 18

Since
(Subscript[n, t]) = 2  (Subscript[n, t - 1]) and (Subscript[n, 0]) = 1

RSolve[{n[t] == 2  n[t - 1], n[0] == 1}, n[t], 
      t]

NSolve[5 (10^6) == (2^t), t]

Hence, the bacteria becomes contagious in just over twenty-two minutes.

Question 19

Given the recursive equation
(Subscript[x, t + 1]) = ((Subscript[x, t])/(1 + (Subscript[x, t]))) with x(0) = (Subscript[x, 0])

RSolve[{x[t + 1] == x[t]/(1 + x[t]), x[0] == x0}, x[t], 
      t]

The fact that Mathematica returns the expression as entered means that it cannot solve it.
But now define

f[x_] := (x/(1 + x))

Simplify[NestList[f, x0, 10]]

The solution is clearly, then,
(Subscript[x, n]) = ((Subscript[x, 0])/(1 + n (Subscript[x, 0])))

Question 20

(a)

Here we shall use Mathematica to do this.

x[0] := 1; x[1] := 1;
x[n_] := x[n] = x[n - 1] + x[n - 2]
data = Table[x[n], {n, 0, 10}]

(b)

Solving

Clear[x]

sol = 
      RSolve[{x[n] == x[n - 1] + x[n - 2], x[0] == 1, 
          x[1] == 1}, x[n], n]

Table[N[sol], {n, 0, 10}]

Which gives the same sequence of numbers.