B A
Posted on Saturday, 08 November, 2003 - 04:45 pm:

Hello!

I would like to know how to approximate differential equations by difference equations. I would be most grateful if you could help me started.

Kind regards,
B A
Zacky Choo
Posted on Saturday, 08 November, 2003 - 05:17 pm:

Though I used to think about this before, I have not had any formal teaching on it.

Anyhow, I guess you just want to get started, so I shall not talk too much. I suggest first noticing a possible correspondence with derivatives and difference terms.

E.g.
d^2y/dx^2 = p dy/dx + q y is a differential equation
and
An-2 = pAn-1 + qAn is a difference equation.

See the possible link?
B A
Posted on Saturday, 08 November, 2003 - 05:49 pm:

Zacky I'm sorry, that's as far as I got myself. I can only observe the apparent analogy between the two equations, but I can't get any further. I would appreciate any further hints. Thanks!
Andre Rzym
Posted on Saturday, 08 November, 2003 - 07:47 pm:

With a difference equation, the x-axis/time or whatever is discretised, and the function value is only considered at these discrete points.

To be concrete, consider a function of time, f(t) obeying:
d2 f(t) d t2 +m df(t) dt =- k2 f(t)

How do we create a discrete equivalent of this DE?

Consider time t, taking the discrete values 0, Δ, 2Δ, 3Δ, ... . Δ could be a year, day, second or whatever you fancy. Denote, for convenience:

f0 =f(0)

f1 =f(Δ)

f2 =f(2Δ)

f3 =f(3Δ)

etc.

Now recall Taylor expansions:

f(t+x)=f(t)+x.f'(t)+ x2 .f''(t)/2+...

Substitute t=kΔ, x=Δ and x=-Δ:

f(kΔ+Δ)=f(kΔ)+Δ.f'(kΔ)+ Δ2 f''(kΔ)/2+...

f(kΔ-Δ)=f(kΔ)-Δ.f'(kΔ)+ Δ2 f''(kΔ)/2+...

Using the discrete notation:

fk+1 = fk +Δ.f 'k + Δ2 f' 'k /2+...

fk-1 = fk -Δ-f 'k + Δ2 f' 'k /2+...

Adding and subtracting the last two equations (and ignoring higher terms beyond the third):

fk+1 + fk-1 =2. fk + Δ2 f' 'k

fk+1 - fk-1 =2.Δ.f 'k

Rearrange:

f' 'k =( fk+1 -2. fk + fk-1 )/ Δ2

f 'k =( fk+1 - fk-1 )/2Δ

These are the key equations for 'discretising' a DE.

Substituting in our example:

( fk+1 -2. fk + fk-1 )/ Δ2 +m.( fk+1 - fk-1 )/2Δ=- k2 fk

Andre

B A
Posted on Monday, 10 November, 2003 - 08:23 pm:

Thanks!!
Andre Rzym
Posted on Tuesday, 11 November, 2003 - 02:56 pm:

There is an 'arm-waving' argument for why these equations make sense as well. Firstly,

( fk+1 - fk )/Δ

is intuitively a sensible estimate for f 'k+1/2 . Similarly,

( fk - fk-1 )/Δ

is intuitively a sensible estimate for f 'k-1/2 . We are interested in f 'k , so the average of f 'k+1/2 and f 'k-1/2 is probably a good estimate:

f 'k =1/2(f 'k+1/2 +f 'k-1/2 )=1/2(( fk+1 - fk )/Δ+( fk - fk-1 )/Δ)

f 'k =1/2(( fk+1 - fk-1 )/2Δ)

This is the second equation above.

Now we need an estimate for f''. This is just the rate of change of f', and in particular we use the estimates we have for f' at (k-1/2) and (k+1/2):

f' 'k =(f 'k+1/2 -f 'k-1/2 )/Δ=(( fk+1 - fk )/Δ-( fk - fk-1 )/Δ)/Δ

f' 'k =(( fk+1 -2. fk + fk-1 )/ Δ2

Which is the first equation above.

Andre

B A
Posted on Tuesday, 18 November, 2003 - 06:50 pm:

Andre, I'm sorry to bother you yet again, but could you demonstate this with an example? That is, how do we actually approximate DE:s by Difference eqs?
Andre Rzym
Posted on Wednesday, 19 November, 2003 - 02:13 pm:

It's no bother.

I don't know whether this is any form of coursework, but if it is, you should declare any help - I would hope that as long as you use your own examples and work through them yourself, you should be OK.

Lets take a (fairly) real life problem: a particle hanging on a spring, with air resistance. We will (i) Use a bit of physics to derive the equation of motion, (ii) Solve the differential equation exactly, (iii) convert the differential equation to a difference equation, (iv) for particular initial conditions, use a spreadsheet to compare the differential/difference equations.

(i) Lets suppose we have a mass m hanging from a spring, the other end being tied to the ceiling. There will be a point at which the mass can hang without motion (i.e. the spring tension equals the force due to gravity). Now suppose the mass is moved a distance, x, above this rest point. The force due to gravity is unchanged, but the spring tension changes (reduces) by an amount proportional to x. Therefore the net force (downwards) is kx. Applying Newton's second law:

-k.x=m.x''

Now lets stick in some air resistance. Assume that this is proportional to (and in the opposite direction to) velocity, i.e. the resistance R=-r.x'. Including this in the equation above:

-k.x-r.x'=m.x''

Now we are not interested in actual masses, so let's just drop the m, and incorporate it into k and r:

x(t)''+r.x'(t)+k.x(t)=0

(ii)This is a fairly easy differential equation to solve. Assume a solution of the form

x(t)=A. ewt

Substitute (and a little cancelling):

w2 +rw+k=0

So w=(-r±( r2 -4k )1/2 )/2

Let us assume that r2 -4k<0, which amounts to saying that the damping is sufficiently low that the system exhibits oscillations that die away [an underdamped system]. For suitable choices of A we can form solutions

x(t)= e-pt sin(qt), x(t)= e-pt cos(qt)

where p=r/2, q=(4k- r2 )1/2 /2

Lets assume for simplicity that the initial displacement is zero (I'll leave you to do the general case) and the initial velocity, v0 =x'(0). A bit of thought should convince you that the solution is

x(t)= v0 /q. e-pt sin(qt)

(iii) Now let's convert the equation to a difference equation.

We start with

x(t)''+r.x'(t)+k.x(t)=0 (1)

then use the 'discretising' equations I posted previously to get:

[( xn+1 -2. xn + xn-1 )/ Δ2 ]+r.[( xn+1 - xn-1 )/2Δ]+k. xn =0

rearranging:

xn+1 =[-k. xn +r. xn-1 /2Δ+(2 xn - xn-1 )/ Δ2 ]/[1/ Δ2 +r/2Δ] (2)

Finally, we know x0 =0, and that x1 = v0 ×Δ. This allows us to compute xn for n=2, 3, ...

(iv) Now take a look at the attached spreadsheet. The spring constant and air resistance factor are inputs in E2 and E3 (they are in blue so you can change them). The initial velocity is in F5 (note that with the workings above, initial displacement is assumed to be zero so F4 is not used!). C10 is the value of Δ.

B15 downwards represents time, in accordance with the time spacing, Δ. C15 downwards represents the displacement computed according to the solution of the differential equation (1) above. D15 and down represents the discrete approximation, using equation (2) above.

Finally, I have included a graph, plotting the exact and discrete approximation. All you see is one line - that's because it works well! If you increase delta (to, say, 4) you see some divergence between the two curves.

There's quite a lot in this post, so if you want more explanation, let me know.

Andre

Andre Rzym
Posted on Wednesday, 19 November, 2003 - 02:24 pm:



application/vnd.ms-excels/s
ba.xls (21 k)


Andre
B A
Posted on Wednesday, 19 November, 2003 - 08:17 pm:

Andre, this is not a coursework excercise. The reason I'm asking is that I'm studying discrete maths on my own and approximating DEs with difference eqs is part of the syllabus.

Your approach was highly intriguing as I've recently read about dampened oscillations and this tied well with that.

Anyway, your help is much appreciated!!

B A
Andre Rzym
Posted on Wednesday, 19 November, 2003 - 10:54 pm:

if you have the interest and time, there are a couple of things you could investigate:

(i) Extend the solution to the differential equation to include a non-zero initial velocity and a non-zero initial displacement
(ii) Extend the s/s to implement (i) for both differential and difference equations
(iii) More realistically, air resistance is proportional to the square of the velocity. Consider how you might incorporate this in the difference equation.
(iv) If you are familiar with partial differential equations, consider how the techniques described might be applied to problems with multiple independent variables [e.g. heat diffusion]

Andre
B A
Posted on Saturday, 22 November, 2003 - 10:45 am:

Hmmm...... I have a question about the spreadsheet. I see you have used as x(n) always the "correctly calculated" value, so we always go only one step forward in the approximation. Is it okay to use the approximated x(n), so that we would need only one calculated value from which to start and then approximate all the steps forward?
Andre Rzym
Posted on Saturday, 22 November, 2003 - 04:42 pm:

No, there is a mistake in the s/s formulae. They should refer to the previous values from the difference equation.

I'll post a corrected s/s (later) for completeness.

Andre
Andre Rzym
Posted on Saturday, 22 November, 2003 - 05:56 pm:

Trying to attach the s/s is clearly not working. All you need to do is to amend D17 downwards, so that references to anything in C15 downwards is replaced by the corresponding column D reference.

If you then change delta from 1 to 2 you see a more pronounced distinction between the differential and difference solution.

Apologies for the confusion,

Andre
B A
Posted on Sunday, 23 November, 2003 - 12:28 pm:

no problem, you've been very kind to see so much effort in this
Andre Rzym
Posted on Monday, 24 November, 2003 - 12:32 pm:


application/vnd.ms-excelss
ba.xls (21 k)


Andre