To solve difference equations, you have to load the package differ.mac. You do this with the following command:
batch(differ);
You will see two messages telling you that this package redefines the definitions of the functions eigenvalues and eigenvectors. This is a surprise, but for most applications it should not cause problems.
The function to solve a difference equation or a system of difference equations is difference, it is called with two arguments. The first argument is either a difference equation or a list of difference equations; the second argument is either the unknown or a list of the unknowns.
deq1: g[n+1] = g[n]*3/2; 3 g n (%o19) g = ---- n + 1 2 difference (deq1, g[n]); n g 3 0 (%o20) g = ----- n n 2
**
(%i27) deq2: h[n+2]=h[n + 1]*2 + 3*h[n]; (%o27) h = 2 h + 3 h n + 2 n + 1 n (%i28) sol: difference(deq2, h[n]); 3 h 3 h 1 0 n (---- + ----) 3 h 3 h 4 4 1 0 n (%o28) h = ---------------- - (-- - ----) (- 1) n 3 4 4
To obtain an expression for a given value of n, e.g for 5, you can evaluate:
ev(sol, n = 5);
The same function
The function difference is not very flexible, to use it, you have to comply to these rules:
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: difference (first(%), y[t]); t t a (c - 1) y = y c + ---------- t 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