To solve difference equations, you have to load the package solve_rec.mac. You do this with the following command:
batch(solve_rec);
The function to solve a difference equation is solve_rec, it is called with two or more arguments. The first argument is a difference equation, and the second argument is the unknown variable. Additional arguments, if present, are initial conditions.
(%i3) deq1: g[n+1] = g[n]*3/2; 3 g n (%o3) g = ---- n + 1 2 (%i4) solve_rec (deq1, g[n]); n %k 3 1 (%o4) g = ------ n n 2
(%i6) deq2: h[n+2]=h[n + 1]*2 + 3*h[n]; (%o6) h = 2 h + 3 h n + 2 n + 1 n (%i7) sol: solve_rec(deq2, h[n]); n n (%o7) h = %k 3 + %k (- 1) n 1 2
To obtain an expression for a given value of n, e.g for 5, you can evaluate:
ev(sol, n = 5);
Initial values can be specified as optional arguments to solve_rec. Continuing the preceding example, we specify initial values of h[0] and h[1].
(%i8) sol: solve_rec(deq2, h[n], h[0] = h0, h[1] = h1);
n n
(h1 + h0) 3 (3 h0 - h1) (- 1)
(%o8) h = ------------ + ------------------
n 4 4
Economists use two essentially different approaches to set up models of economic processes:
A very simple model:
eq1: y[t + 1] = z[t]; eq2: z[t]=c[t] + i[t]; eq3: c[t]=c*y[t]; eq4: i[t]=a; eliminate([eq1, eq2, eq3, eq4], [ z[t], c[t], i[t]]); [y - c y - a] t + 1 t result: solve_rec (first(%), y[t], y[0]=y[0]); t a c t a (%o20) y = ----- + y c - ----- t c - 1 0 c - 1
The letters of the model follow established conventions of macro-economic theory. The meanings are:
The model assumes a constant investment, and a consumption that is proportional to income. The equation eq2 states that the total demand is the sum of consumption and investment, eq1 is also an assumption, namely that the income of period t equals the total demand of the previous period t-1. (the spendings of a period are the available income of the next period. This assumption postulates an entirely closed system.)
We can immediately explore the result:
(%i25) assume (c < 1); (%o25) [c < 1] (%i26) limit(result, t, inf); Is abs(c) - 1 positive, negative, or zero? negative; Is c positive, negative, or zero? positive; Is y positive, negative, or zero? 0 positive; Is a positive, negative, or zero? positive; a limit y = - ----- t -> inf t c - 1