       Re: difference equation

• To: mathgroup at smc.vnet.net
• Subject: [mg24361] Re: difference equation
• From: Leszek Sczaniecki <lsczan at home.com>
• Date: Sun, 9 Jul 2000 04:53:03 -0400 (EDT)
• Organization: @Home Network
• References: <8k3l8a\$3af@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```
Wilfried Stock wrote:

> Hi
> I would like to built a difference equatition like:
> Yt=A+b*Yt-1-c*Yt-2
> with Y=f(X)
> I don't find an easy solution.
> Can anyone provide a solution?
>
> Wilfried

In old days this type of equations used to be often solved in the
following way (subtle mathematical details omitted)

y[n+2] == a + b y[n+1] - c y[n]
y == y1 , y(0) == y0

There is time for some tricks now. We multiply both sides of the
equation by x^n/n!

y(n+2) x^n/n! == a x^n/n! + b y(n+1)x^n/n - c y(n)x^n/n

(d/dx)^2 y[n+2] x^(n+2)/(n+1)! == a x^n/n!
+ b (d/dx)y(n+1)x^(n+1)/(n+1!) - c y(n)x^n/n!

We define a function ( called the generating function)

f(x) == Sum[y(n) x^(n)/(n+1)!, {n, 0, Infinity}]

The original equation has been transformed to a second order
differential equation with constant coefficients (and known solution
:-))

(d/dx)^2 f[x] - b (d/dx) f[x] + c f[x] == a Exp[x]

with initial conditions

((d/dx) f) == y1  and f == y0 .

y[n] is the n-th derivative of the generating function f with respect to
x taken at x==0.

These days happy owners of Mathematica have another option.

In:= << "DiscreteMath`RSolve`"

In:= sol = RSolve[{y[n + 2] == a + b*y[n + 1] - c*y[n], y == y1,
y == y0}, y[n], n] // FullSimplify

Out= {{y[n] -> 1/(Sqrt[b^2 - 4*c]*(-1 + b - c))*
2^(-1 - n)*(Sqrt[b^2 - 4*c]*(a*(-2^(1 + n) + (b - Sqrt[b^2 -
4*c])^n +
(b + Sqrt[b^2 - 4*c])^n) + ((b - Sqrt[b^2 - 4*c])^n + (b +
Sqrt[b^2 - 4*c])^
n)*(-1 + b - c)*y0) + (b - Sqrt[b^2 - 4*c])^n*(a*(-2 + b) +
(-1 + b - c)*(b*y0 - 2*y1)) - (b + Sqrt[b^2 - 4*c])^n*
(a*(-2 + b) + (-1 + b - c)*(b*y0 - 2*y1)))}}

In:= y[n_] = y[n] /. First[sol];

In:= FullSimplify[y]
Out= y0

In:= FullSimplify[y]
Out= y1

It looks like this is a correct solution (at least for 0 <= n <=10).

In:= Table[FullSimplify[y[n + 2] - (a + b*y[n + 1] - c*y[n])], {n, 1,
10}]
Out= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Regards,

-- Leszek Sczaniecki

```

• Prev by Date: RE: With[{software=Mathematica}, Frustration]
• Next by Date: Re: Transposing a triangular matrix.
• Previous by thread: Re: difference equation
• Next by thread: Contour labeling