Section 4 Linear difference equations

  • How to solve homogeneous and inhomogeneous linear difference equations
  • Solving for probability of ruin and expected duration of the gambler’s ruin

In the previous section, we looked at the probability of ruin and expected duration of the gambler’s ruin process. We set up linear difference equations to find these. In this section, we’ll learn how to solve these equations.

A linear difference equation is an equation that looks like akxn+k+ak1xn+k1++a1xn+1+a0xn=f(n) for n=0,1,, where the ai are given constants, f(n) is a given function, and we want to solve for the sequence (xn). The equation normally comes with some extra conditions, such as the value of the first few xns.

When the right-hand side of (4.1) is zero, so f(n)=0, we say the equation is homogeneous; when the right-hand side is nonzero, it is inhomogeneous. The number k, where there are k+1 terms on the left-hand side, is called the degree of the equation; we are mostly interested in second-degree linear difference equations, which have three terms on the left-hand side.

4.1 Homogeneous linear difference equations

We start with the homogeneous case, which is simpler.

Consider a homogeneous linear difference equation. We shall use the second-degree example xn+25xn+1+6xn=0subject to x0=4,x1=9. Here, the conditions on x0 and x1 are initial conditions, because they tell us how the sequence (xn) starts.

For the moment, we shall put the initial conditions to the side and just worry about the equation xn+25xn+1+6xn=0. We start by guessing there might be a solution of the form xn=λn for some constant λ. We can find out if there is such a solution by substituting in xn=λn, and seeing if there’s a λ that solves the equation. For our example, we get λn+25λn+1+6λn=0. After cancelling off a common factor of λn, we get λ25λ+6=0. This is called the characteristic equation. For a general homogeneous linear difference equation (4.1), the characteristic equation is akλk+ak1λk1++a1λ+a0=0. When writing out answers to questions, you can jump straight to the characteristic equation.

We can now solve the characteristic equation for λ. In our example, we can factor the left-hand side to get (λ3)(λ2)=0, which has solutions λ=2 and λ=3. Thus xn=2n and xn=3n both solve our equation. In fact, since the right-hand side of the equation is 0, any linear combination of these two solutions is a solution also, thus we get the general solution xn=A2n+B3n, which is a solution for any values of the constants A and B.

For a general characteristic equation with distinct roots λ1,λ2,,λk, the general solution is xn=C1λn1+C2λn2++Ckλnk. If we have a repeated root – say, λ1=λ2==λr is repeated r times – than you can check that a solution is given by xn=(D0+D1n++Dr1nr1)λn1, which should take its place in the general solution.

Once we have the general solution, we can use the extra conditions to find the values of the constants. In our example, we can use the initial conditions to find out the values of A and B. We see that x0=A20+B30=A+B=4,x1=A21+B31=2A+3B=9. We can now solve this pair of simultaneous equations to solve for A and B. By subtracting twice the first equation from the second we get B=1, and substituting this into the first equation we get A=3. Thus the solution is xn=32n+3n.

In conclusion, the process here was:

  1. Find the general solution by writing down and solving the characteristic equation.
  2. Use the extra conditions to find the values of the constants in the general solution.

Here are two more examples. These also give an idea of how I would expect you to set out your own answers to similar problems.

Example 4.1 Solve the homogeneous linear difference equation xn+2xn+16xn=0subject tox0=3,x1=4.

Step 1. The characteristic equation is λ2λ6=0. We can solve this by factorising it as (λ3)(λ+2)=0, to find the solutions λ1=2 and λ2=3. Thus the general solution is xn=A(2)n+B3n.

Step 2. Substituting the initial conditions into the general solution, we have x0=A(2)0+B30=A+B=3x1=A(2)1+B31=2A+3B=4. We can add twice the first equation to the second to get 5B=10, so B=2. We can substitute this into the first equation to get A=1.

The solution is therefore xn=1(2)n+23n=(2)n+23n.

Example 4.2 Solve the homogeneous linear difference equation xn+2+4xn+1+4xn=0subject tox0=2,x1=6.

Step 1. The characteristic equation is λ2+4λ+4=0. We can solve this by factorising it as (λ+2)2=0, to find a repeated root λ1=λ2=2. Thus the general solution is xn=(A+Bn)(2)n.

Step 2. Substituting the initial conditions into the general solution, we have x0=(A+B0)(2)0=A=2x1=(A+B1)(2)1=2A2B=6. The first immediately gives A=2, and substituting this into the second equation gives B=1.

The solution is therefore xn=(2+n)(2)n.

4.2 Probability of ruin for the gambler’s ruin

In the last lecture we saw that probability of ruin for the gambler’s ruin process is the solution to pri+1ri+qri1=0subject tor0=1, rm=0, where the extra conditions here are boundary conditions, because they tell us what happens at the boundaries of the state space.

The characteristic equation is pλ2λ+q=0. We can solve the characteristic equation by factorising it as (pλq)(λ1)=0. (It might take a moment to check this really is a factorisation of the characteristic equation. Hint: we’ve used that p+q=1.) So the characteristic equation has roots λ=q/p, which we called ρ last time, and λ=1. Now, if ρ=1 (so p=q=12) we have a repeated root, while if ρ1 we have distinct roots, so we’ll need to deal with the two cases separately.

First, the case ρ1. Since the two roots are distinct, we have the general solution ri=Aρi+B1i=Aρi+B.

We can now use the boundary conditions to find A and B. We have r0=Aρ0+B=A+B=1,rm=Aρm+B=0. From the first we get B=1A, which we substitute into the second to get Aρm+1A=0A=11ρm, and hence B=1A=111ρm=ρm1ρm. Thus the solution is ri=11ρmρiρm1ρm=ρiρm1ρm, as we claimed last time.

Second, the case ρ=1. Now we have a repeated root λ=1, so the general solution is ri=(A+Bi)1i=A+Bi.

Again, we use the boundary conditions, to get r0=A+B0=A=1,rm=A+Bm=0, and we immediately see that A=1 and B=1/m. Thus the solution is ri=11mi=1im, as claimed last time.

4.3 Inhomogeneous linear difference equations

Solving inhomogeneous linear difference equations requires three steps:

  1. Find the general solution to the homogeneous equation by writing down and solving the characteristic equation.
  2. By making an “educated guess”, find a solution (a “particular solution”) to the inhomogeneous equation. The general solution to the inhomogeneous equation is a particular solution plus the general solution to the homogeneous equation.
  3. Use the extra conditions to find the values of the constants in the general solution.

This idea works because, once you have a particular solution, adding a solution to the homogeneous equation to the left-hand side adds zero to the right-hand side, so maintains a solution to the inhomogeneous equation.

Let’s work through the example xn+25xn+1+6xn=2subject to x0=4,x1=9.

We already know from earlier that the general solution to the homogeneous equation xn+25xn+1+6xn=0 (with a zero on the right-hand side) is xn=A2n+B3n.

We now need to find a particular solution – that is, any solution – to our new inhomogeneous equation. The usual process here is to guess a solution with the same “shape” as the right-hand side. For example, if the right-hand side is a constant, try a constant for the particular solution. Here our right-hand side is the constant 2, so we should try a constant xn=C. Substituting this into the inhomogeneous equation gives us C5C+6C=2, thus 2C=2 and C=1, giving a particular solution xn=1. The general solution to the inhomogeneous equation is therefore xn=1+A2n+B3n, the sum of the particular solution xn=1 and the general solution to the homogeneous equation.

Because the right-hand side was a constant, we guessed a constant – this is the main case we will deal with. Other cases you could come across include:

  • If the right-hand side is a polynomial of degree d, try a polynomial of degree d.
  • If the right-hand side is αn for some α, try Cαn.
  • If the right-hand side is a constant, but a constant C doesn’t work, try Cn. If that still doesn’t work, try Cn2, and so on. A general rule is that is 1 is a root of the characteristic equation with multiplicity m, you need to try Cnm. We discuss this case further in the next subsection.

Continuing with the example, we use the initial conditions to get the constants A and B. We have x0=1+A20+B30=1+A+B=4,x1=1+A21+B31=1+2A+3B=9. The second equation minus twice the first gives 1+B=1, so B=2, and substituting that back into the first gives A=1. Thus the solution is xn=1+12n+23n=1+2n+23n.

Here’s another example.

Example 4.3 Solve the inhomogeneous linear difference equation 10xn+27xn+1+xn=8subject tox0=0,x1=1310.

Step 1. The characteristic equation is 10λ27λ+1=0. We can solve this by factorising it as (2λ1)(5λ1)=0, to find the solutions λ1=12 and λ2=15. Thus the general solution of the homogeneous equation is xn=A(12)n+B(15)n.

Step 2. Since the right hand side of the inhomogeneous equation is a constant, we guess a constant particular solution with shape xn=C. Substituting in this guess, we get 10C7C+C=4C=8 with solution C=2. Thus a particular solution is xn=2, and the general solution to the inhomogeneous equation is xn=2+A(12)n+B(15)n.

Step 3. Substituting the initial conditions into the general solution, we have x0=2+A(12)0+B(15)0=2+A+B=0A+B=2x1=2+A(12)1+B(15)1=2+A12+B15=13105A+2B=7. We can take twice the first equation abd subtract the second to get 3A=3, so A=1. We can substitute this into the second equation to get B=1.

The solution is therefore xn=2(12)n(15)n.

4.4 Expected duration for the gambler’s ruin

From last time, the expected duration of the gambler’s ruin game solves pdi+1di+qdi1=1subject tod0=0, dm=0. As before, we divide cases based on whether or not ρ=1.

First, the case ρ1. We already know that the general solution to the homogeneous equation is di=Aρi+B.

Now we need a particular solution. It’s tempting to guess a constant C for a particular solution, but we know that constants solve the homogeneous equation, since di=B is a solution, so a constant will give right-hand side 0, not 1. (We could try out xi=C if we wanted; we would get (p1+q)C=1, but p1+q=0, and 0×C=1 has no solution.) The next best try is to go one degree up: let’s guess xi=Ci instead. This gives 1=pC(i+1)Ci+qC(i1)=C(pi+pi+qiq)=C((p+q1)i+(pq))=C(pq), since p+q1=11=0. This C=1/(pq)=1/(qp). Finding a solution for C shows that our guess worked. The general solution to the inhomogeneous equation is di=iqp+Aρi+B.

Then to find the constants, we have d0=0qp+Aρ0+B=A+B=0,dm=mqp+Aρm+B=0, which you can check gives A=B=mqp11ρm. Hence, the solution is di=iqp+mqp11ρmρimqp11ρm=1qp(im1ρi1ρm).

Second, the case ρ=1, so p=q=12. We already know that the general solution to the homogeneous equation is di=A+Bi.

We need a particular solution. Since 1 is a double root of the characteristic equation, both constants xi=A and linear xi=Bi terms solve the homogeneous equation. (You can check that guessing xi=C or xi=Ci doesn’t work, if you like.) So we’ll have to go up another degree and try xi=Ci2. This gives 1=12C(i+1)2Ci2+12C(i1)2=12C(i2+2i+12i2+i22i+1)=12C((12+1)i2+(22)i+(1+1))=C, so the general solution to the inhomogeneous equation is di=i2+A+Bi.

Then to find the constants, we have d0=02+A+B0=A=0,dm=m2+A+Bm=0, giving A=0,B=m. The solution is di=i2+0+mi=i(mi).

In the next section, we move on from the specific cases we’ve looked at so far to the general theory of discrete time Markov chains.