You are on page 1of 20

The Wave Equation: 2

Solution Using the Finite Difference Method

Basic Problem
We wish to solve the following problem: Wave Equation:
2 2u u 2 =c 2 t x 2

Boundary Conditions:
u(0,t) = 0

and u(L, t) = 0

for all t

Initial Conditions

u(x,0) = f(x) u = g(x ) t t =0


CM3900 Lecture 4 2

Discretisation Method
We consider a mesh in one space and one time dimension xi xN = L x1 x2 x3 x4 x0
t0 t1 t2 t3

x
x i = x 0 + i x

t (xi, tj)

where N x = L and t j = t 0 + j t

tj

We write u(xi ,t j ) = ui,j t


CM3900 Lecture 4 3

Discretisation of the Equation


The power series expansion for a function f(x) at the point x + h is given by 2

h f(x + h) = f(x) + h f (x) + f (x) + K 2!

and about x - h is

h2 f(x h) = f(x) h f (x) + f (x) + K 2!

Adding these two equations and keeping terms to second order in h, we obtain

f(x + h) + f(x h) = 2f(x) + h2 f (x)


4

CM3900 Lecture 4

Discretisation of the Equation


Hence, we see that an approximation to the second derivative is given by

f(x + h) 2f(x) + f(x h) f (x) = h2

CM3900 Lecture 4

Discretisation of the Equation


We can therefore discretise the second derivatives in the wave equation using this formula
u(xi ,t j + t) 2u(xi ,t j ) + u(xi ,t j t) 2u (xi ,t j ) = 2 t ( t)2

i.e.

ui,j+1 2ui,j + ui,j1 2u (xi ,t j ) = 2 t ( t)2

CM3900 Lecture 4

Discretisation of the Equation


Similarly
u(xi + x,t j ) 2u(xi ,t j ) + u(xi x,t j ) 2u (xi , t j ) = 2 ( x)2 x

ui+1,j 2ui,j + ui1,j 2u (xi , t j ) = 2 x ( x)2

CM3900 Lecture 4

Discretisation of the Equation


2 2 u u , becomes 2 So the wave equation =c 2 t x 2

u i, j+1 2u i, j + u i, j1 ( t )
2

=c

u i+1, j 2u i, j + u i1, j ( x ) 2

or

c(t) ui,j+1 = ui+1,j 2ui,j + ui1,j + 2ui,j ui,j1 (x)

i.e.

ui,j+1 = ui+1,j + (2 2)ui,j + ui1,j ui,j1

where

ct = x
CM3900 Lecture 4 8

Discretisation of the Equation


In terms of the mesh points ui,j-1 -1 ui-1,j ui,j 22 ui,j+1 ui+1,j t = tj+1 t = tj t = tj-1

we can construct a diagram to show the relative contribution of the preceding points to ui,j+1
CM3900 Lecture 4 9

Discretisation of the Equation


To advance the solution from the tj to the tj+1 time-slice, we use the boundary conditions together with the main equation

ui,j+1 = ui+1,j + (2 2)ui,j + ui1,j ui,j1


for i = 1, 2, N 1

There is however a problem with the initial step from t0 to t1. Because the wave equation is a p.d.e. which is second order in the time variable, the discretised version approximates the function at on the next time-slice by using information from the preceding, as well as the current time.
10

CM3900 Lecture 4

Discretisation of the Equation


At j = 0, the information for this time-slice is provided by the initial condition u( x,0 ) = f ( x ) which is discretised to u i,0 = f ( x i ) Unfortunately there is no previous data corresponding to j = -1. However, we do have initial conditions which give the initial

u derivative function t

= g( x )
t =0

CM3900 Lecture 4

11

Discretisation of the Equation


Discretising this derivative using

u( x i , t j + t ) u( x i , t j t ) u (x i , t j ) = 2t t =
setting j = 0, we get:

u i, j+1 u i, j1 2t

ui,1 ui,1 u = t i,0 2t


and so

u ui,1 = ui,1 2( t) = ui,1 2t g(xi ) t i,j=0


CM3900 Lecture 4 12

Discretisation of the Equation


To get started therefore, we have
u i,1 = (u i+1,0 + u i1,0 ) + (2 2)u i,0 u i,1 = (u i+1,0 + u i1,0 ) + (2 2)u i,0 [u i,1 2t g( x i )]

Hence

u i,1 = (u i+1,0 + u i1,0 ) + (2 2)u i,0 u i,1 1 = { (u i+1,0 + u i1,0 ) + (2 2)u i,0 + 2t g( x i )} 2 = [u i+1,0 + u i1,0 ] + (1 )u i,0 + t g( x i ) 2
CM3900 Lecture 4 13

Discretisation of the Equation


The diagram for the initial step is therefore

/2

1-

/2
t g(xi)

t = t0

t = t1

CM3900 Lecture 4

14

Summary
For the initial step we use:

j = 0: j = 1:

ui,0 = f(xi ) ui,1 = + (1 )ui,0 + t g(xi ) ui+1,0 + ui1,0 2

and for subsequent steps

j = 2,3,K : ui,j+1 = ui+1,j + (2 2)ui,j + ui1,j ui,j1

CM3900 Lecture 4

15

Example
2 2 u u 2 Numerically solve the 1-D wave equation = c 2 2 t x with c = 1, subject to

i) ii)

u(0, t) = u(1, t) = 0

for all t

x 0 x < 0.5 u(x,0) = 1 x 0.5 x 1 u =0 0 x 1 t t =0

using x = 0.1 and t = 0.05 i.e. find u(x, t) for x = 0.0 to 1.0 in steps of 0.1 and t = 0.00 to 2.00 in steps of 0.05.
CM3900 Lecture 4 16

Solution
We first calculate = Initial step:
1/8 3/4 1/8 t = t0

1 ct = 4 x

and note that g(x) = 0.

t = t1

CM3900 Lecture 4

17

Solution
Subsequently
-1

1/4

3/2

1/4

CM3900 Lecture 4

18

Solution
The calculation can be set out as a table
x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 t 0.05 0.000 0.100 0.200 0.300 0.400 0.500 0.400 0.300 0.200 0.100 0.000 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 etc
CM3900 Lecture 4 19

0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000

0.100 0.100 0.100 0.100 0.100 0.099 0.096 0.085 0.063

0.200 0.200 0.200 0.200 0.197 0.187 0.164 0.123 0.065

0.300 0.300 0.298 0.290 0.266 0.222 0.160 0.094 0.035

0.400 0.394 0.369 0.319 0.253 0.188 0.136 0.097 0.060

0.475 0.412 0.341 0.283 0.243 0.208 0.164 0.105 0.042

0.400 0.394 0.369 0.319 0.253 0.188 0.136 0.097 0.060

0.300 0.300 0.298 0.290 0.266 0.222 0.160 0.094 0.035

0.200 0.200 0.200 0.200 0.197 0.187 0.164 0.123 0.065

0.100 0.100 0.100 0.100 0.100 0.099 0.096 0.085 0.063

0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000

Solution
The solution can be graphed for various values of t
0.5 u0,i u2,i u5,i 0 u8,i u10,i 0.2 0.4 0.6 0.8 1 0.5

0.5 0.5 0 xi 1

CM3900 Lecture 4

20

You might also like