the wave equation douglas wilhelm harder, m.math. lel department of electrical and computer...

52
The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca [email protected] © 2012 by Douglas Wilhelm Harder. Some rights

Upload: dwight-beasley

Post on 24-Dec-2015

222 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

The Wave Equation

Douglas Wilhelm Harder, M.Math. LELDepartment of Electrical and Computer Engineering

University of Waterloo

Waterloo, Ontario, Canada

ece.uwaterloo.ca

[email protected]

© 2012 by Douglas Wilhelm Harder. Some rights reserved.

Page 2: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

2

Outline

This topic discusses numerical solutions to the wave equation:– Discuss the physical problem and properties– Examine the equation– Approximate solutions using a finite-difference equation

• Consider numerical stability• Examples

– What about Crank-Nicolson?

Wave Equation

Page 3: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

3

Outcomes Based Learning Objectives

By the end of this laboratory, you will:– Understand the wave equation– Understand how to approximate partial differential equations

using finite-difference equations– Set up solutions in one spatial dimension– Deal with insulated boundary conditions

Wave Equation

Page 4: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

4

Motivating Example

Suppose we start with a string at rest

Wave Equation

Page 5: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

5

Motivating Example

Someone comes along and plucks the string

Wave Equation

Page 6: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

6

Motivating Example

After letting go, the string begins to vibrate– Energy is transferred to the air producing sound

Wave Equation

Page 7: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

7

Motivating Example

Some things to note: The string– Is at rest when it is a solution to Laplace’s equation– Acceleration is towards the solution of Laplace’s equation

Wave Equation

Page 8: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

8

Motivating Example

In addition, if we reduce the length of a string, the vibrations increase:– Halve the length of a string, double the frequency– If a string of a certain length is middle C, a string of half the

length is one octave higher

Wave Equation

Page 9: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

9

Motivating Example

Waves are not restricted to strings:– The vibrations on the face of a drum– The ripples on the surface of a pond– The movement of light (microwaves, radio waves, etc.)

Wave Equation

Page 10: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

10

The Wave Equation

The equation that describes the propagation of waves under somewhat ideal circumstances is given by the partial differential equation

where u(x, t) is a real-valued function of space and time and c is the propagation speed of the wave

Sound in air at 20 oC c ≈ 343 m/s = 1234.8 km/h ≈ 1 km/3 s

Light c = 299 792 458 m/s

22 2

2u c u

t

Wave Equation

Page 11: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

11

The Wave Equation

For water in a deep ocean, the speed is proportional to the square root of the wave length:

Wavelength(m)

Speed(m/s)

1 2.5

10 4

100 12.5

1000 39 140 km/h

Wave Equation

Page 12: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

12

The Laplacian Operator

Notice if that u(x, t) already satisfies Laplace’s equation,

then

or

That is, if a solution already satisfies Laplace’s equation, it will not be accelerating– In one dimension, if the string is already tight (a straight line), it

will not begin vibrating– If it’s not moving, either, it will remain fixed

2 0u

22 2

20u c u

t

2

20u

t

Wave Equation

Page 13: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

13

Acceleration Proportional to Concavity

In one dimension, what does this equation mean?

Wave Equation

2 22

2 2

u uc

t x

Page 14: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

14

Acceleration Proportional to Concavity

We can see this visually:

– If the function u is concave up at (x, t), the acceleration of u over time will be positive

2

20

u

x

Wave Equation

0u

t

0u

t

2 22

2 2

u uc

t x

Page 15: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

15

Acceleration Proportional to Concavity

We can see this visually:

– If the function u is concave down at (x, t), the acceleration of u over time will be negative

2

20

u

x

Wave Equation

2 22

2 2

u uc

t x

0u

t

0

u

t

Page 16: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

16

Initial and Boundary Conditions

For a 2nd-order ODE, we require either two initial conditions

or a boundary condition:

(2) (1)1 2 3

a

b

c y x c y x c y x g x

y a y

y b y

(2) (1)

1 1

(1) (1)1 1

, ,y t f t y t y t

y t y

y t y

Time variables are usuallyassociated with initial conditions

Space variables are usuallyassociated with boundary conditions

Wave Equation

Page 17: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

17

Initial and Boundary Conditions

For the wave equation,

we have two second partial derivatives:– One in time– One in space

2 22

2 2

u uc

t x

Wave Equation

Page 18: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

18

Initial and Boundary Conditions

For the wave equation,

we require– For each space coordinate:

• An initial value at each point, and• An initial velocity at each point

– For each time coordinate• Boundary conditions at the end points in space

Wave Equation

2 22

2 2

u uc

t x

Page 19: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

19

The Wave Equation

Given the wave equation

and the two approximations of the second partial derivatives

we will substitute the approximations into the equation

2

2 2

2

22

, 2 , ,,

, 2 , ,,

u x h t u x t u x h tu x t

x hu x t t u x t u x t t

u x tt t

Wave Equation

2 22

2 2

u uc

t x

Page 20: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

20

The Wave Equation

This gives us our finite-difference equation

22 2

, 2 , , , 2 , ,u x t t u x t u x t t u x h t u x t u x h tc

ht

Wave Equation

Page 21: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

21

The Wave Equation

This gives us our finite-difference equation

Note that there is only one term in the future: u(x, t + Dt)– We assume we have approximations for t and t – Dt– Solve for u(x, t + Dt)

Wave Equation

22 2

, 2 , , , 2 , ,u x t t u x t u x t t u x h t u x t u x h tc

ht

Page 22: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

22

The Wave Equation

This gives us our finite-difference equation

Substituting

we get

22

2, 2 , , , 2 , ,

c tu x t t u x t u x t t u x h t u x t u x h t

h

2c t

rh

, 2 , , , 2 , ,u x t t u x t u x t t r u x h t u x t u x h t

Wave Equation

Page 23: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

23

The Wave Equation

As before, we will substitute

and recognize that

to get

, 1 , , 1 1, , 1,2 2i k i k i k i k i k i ku u u r u u u

,,i k i ku x t u

1

1

i i

k k

x h x

t t t

Wave Equation

Page 24: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

24

Initial and Boundary Conditions

The boundary conditions will be given by the functions– uinit(x) The initial value of the function u(x, t0)

– Duinit(x) The initial rate of change u(x, t0)

– abndry(t) The boundary value of the function u(a, t)

– bbndry(t) The boundary value of the function u(b, t)

As with the previous cases, we will define the latter two as a single vector-valued function

t

Wave Equation

Page 25: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

25

Initial and Boundary Conditions

We will define two functions

u_init( x ) du_init( x ) u_bndry( t )

where– u_init and u_bndry are the same as before

– du_init takes an n-dimensional column vector x as an argument and returns an n-dimensional vector of the initial

speeds 0,iu x tt

Wave Equation

Page 26: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

26

Approximating the Solution

Just as we did with BVPs and the heat-conduction/diffusion equation, we will divide the spacial interval [a, b] into nx points or nx – 1 sub-intervals

Wave Equation

Page 27: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

27

Approximating the Solution

We want to approximate the state at time t = t2 but consider the formula with k = 1:

, 1 , , 1 1, , 1,2 2i k i k i k i k i k i ku u u r u u u

We don’t have access to ui,0

Wave Equation

Page 28: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

28

Approximating the Solution

To solve this, we will use the initial conditions:

ui,2 = ui,1 + Dt Dui,1

– This is simply an application of Euler’s method

Wave Equation

Page 29: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

29

Approximating the Solution

For the next point, t = t3 , however, we can go back to using the finite-difference formula:

,3 ,2 ,1 1,2 ,2 1,22 2i i i i i iu u u r u u u

Wave Equation

Page 30: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

30

Approximating the Solution

And from here on, we can continue using the formula

, 1 , , 1 1, , 1,2 2i k i k i k i k i k i ku u u r u u u

Wave Equation

Page 31: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

31

Insulated Boundaries

As this is a forward solving algorithm, if we have insulated boundaries, it is straight forward– Insulated boundaries reflect waves

We will solve for the values at times k = 1, …, nt – 1

– We will first solve for the values u2, k through un – 1, k ,

– If u1, k is marked as insulated (NaN), we will replace it with u2, k

– If un , k is marked as insulated (NaN), we will replace it with un – 1, k

x

x x

Wave Equation

Page 32: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

32

Steps to the Problem

Previously, the steps were:1. Error checking (if necessary)

2. Initialization

3. Solving the problem

When we solve BVPs, Step 3. was broken into:a. Generate the matrix and vector for solving Muintr = b

b. Modify the first and last entries of b

c. Solve the system of linear equations

d. Add ua and ub back to the result

Wave Equation

Page 33: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

33

Steps to the Problem

Previously, the steps were:1. Error checking (if necessary)

2. Initialization

3. Solving the problem

When we solve the heat-conduction/diffusion equation, Step 3. was broken into:For each time step k = 1, 2, …, nt – 1 a. Apply the formula to approximate ui, k + 1

Wave Equation

Page 34: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

34

Steps to the Problem

Previously, the steps were:1. Error checking (if necessary)

2. Initialization

3. Solving the problem

When we applied the Crank-Nicolson method, Step 3. was broken into:For each time step k = 1, 2, …, nt – 1 a. Generate the matrix and vector for solving Muintr = b

b. Modify the first and last entries of b

c. Solve the system of linear equations to approximate ui, k + 1

Wave Equation

Page 35: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

35

Steps to the Problem

Previously, the steps were:1. Error checking (if necessary)

2. Initialization

3. Solving the problem

When we applied the Crank-Nicolson method adding insulated boundary conditions, Step 3. was broken into:For each time step k = 1, 2, …, nt – 1 a. Generate the matrix and vector for solving Muintr = b

b. Modify, as appropriate, the vector b or the matrix M

c. Solve the system of linear equations to approximate ui, k + 1

d. As appropriate, update any insulated boundary conditions

Wave Equation

Page 36: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

36

Steps to the Problem

Now we are solving the wave equation:

1. Error checking:

2. Initialization

3. Solve for the special case at time t2

4. Solving the problem for the general case

When we solved the adding insulated boundary conditions, Step 4 was broken into:For each time step k = 2, 3, …, nt – 1 a. Apply the formula to approximate ui, k + 1

b. As appropriate, update any insulated boundary conditions

2

0.5c t

h

Wave Equation

Page 37: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

37

Step 1: Error Checking

Once the parameters are validated, the next step is to ensure

If this condition is not met, we should exit and provide a useful error message to the user:– For example,

The ratio (c*dt/h)^2 = ??? >= 1, consider using nt = ???

where• The first ??? is replaced by the calculated ratio, and

• The second ??? is found by calculating the smallest integer for nt that would be acceptable to bring this ratio under 1

– You may wish to read up on the floor and ceil commands

2

1c t

h

Wave Equation

Page 38: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

38

Step 1: Error Checking

Essentially, given c, t0, tfinal and h, find an appropriate value (that is, the smallest integer value) of nt

* to ensure that

Very similar to constraints on for the heat-

conduction/diffusion equation

2

final 0* 1

1t

t tc

n

h

Wave Equation

2

t

h

Page 39: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

39

Step 2: Initialization

It would still be useful to initialize the matrix U and then use the values as appropriate

init 1 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

init 2

init 3

init 4

init 5

init 6

init 7

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ?

u x a t a t a t a t a t a t a t a t a t a t a t

u x

u x

u x

u x

u x

u x

init 8

init 9 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?u x

u x b t b t b t b t b t b t b t b t b t b t b t

nx

nt

Wave Equation

Page 40: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

40

Step 3: Solving at time t2

We then proceed to evaluate the next column using the straight-forward application of Euler’s method

init 1 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

init 2

init 3

init 4

init 5

init 6

init 7

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ?

u x a t a t a t a t a t a t a t a t a t a t a t

u x

u x

u x

u x

u x

u x

init 8

init 9 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ?u x

u x b t b t b t b t b t b t b t b t b t b t b t

nx

nt

init 2 init 2

init 3 init 3

init 4 init 4

init 5 init 5

init 6 init 6

init 7 init 7

init 8 init 8

u x t u x

u x t u x

u x t u x

u x t u x

u x t u x

u x t u x

u x t u x

Wave Equation

Page 41: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

41

Step 4: Solving

Thus, we have approximations for the values u2, 2 through un – 1, 2 – We may have to adjust these if we have insulated boundary

conditions

init 1 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

init 2 2,2

init 3 3,2

init 4 4,2

init 5 5,2

init 6 6,2

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ?

u x a t a t a t a t a t a t a t a t a t a t a t

u x u

u x u

u x u

u x u

u x u

init 7 7,2

init 8 8,2

init 9 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

u x u

u x u

u x b t b t b t b t b t b t b t b t b t b t b t

nx

nt

Wave Equation

x

Page 42: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

42

Step 4: Solving

As with the previous case, we will find solutions for the interior points for t2 through tn

nx

nt

t

init 1 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

init 2 2,2

init 3 3,2

init 4 4,2

init 5 5,2

init 6 6,2

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ?

u x a t a t a t a t a t a t a t a t a t a t a t

u x u

u x u

u x u

u x u

u x u

init 7 7,2

init 8 8,2

init 9 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

u x u

u x u

u x b t b t b t b t b t b t b t b t b t b t b t

Wave Equation

Page 43: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

43

Step 4: Solving

As with the previous case, we will find solutions for the interior points for t2 through tn – Again, at each step, we may have to adjust any boundary values

indicating insulated boundary conditions

nx

nt

t

init 1 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

init 2 2,2

init 3 3,2

init 4 4,2

init 5 5,2

init 6 6,2

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ?

u x a t a t a t a t a t a t a t a t a t a t a t

u x u

u x u

u x u

u x u

u x u

init 7 7,2

init 8 8,2

init 9 bndry 2 bndry 3 bndry 4 bndry 5 bndry 6 bndry 7 bndry 8 bndry 9 bndry 10 bndry 11 bndry 12

? ? ?

? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ?

u x u

u x u

u x b t b t b t b t b t b t b t b t b t b t b t

Wave Equation

Page 44: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

44

Example 1

As a first example:[x4a, t4a, U4a] = wave1d( 1, [0, pi], 10, [0, 10], 42, @u4a_init, @du4a_init,

@u4a_bndry );size(x4a)ans = 10 1

>> size(t4a)ans = 1 30

>> size(U4a)ans = 10 30

>> mesh( t4a, x4a, U4a )

ta = 0t0 = 0

tfinal = 10

nt = 42nx = 10

c = 1.0

x

a4a,bndry (t) = 0.0

b = p

b4a,bndry (t) = 0.0

u4a,init(x) = sin(x)Du4a,init(x) = 0

Wave Equation

Page 45: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

45

Example 1

As a first example:[x4a, t4a, U4a] = wave1d( 1, [0, pi], 10, [0, 10], 42, @u4a_init, @du4a_init,

@u4a_bndry );mesh( t4a, x4a, U4a )

t

b = p

a = 0t0 = 0

u4a,init(x) = sin(x)

b4a,bndry (t) = 0.0

a4a,bndry (t) = 0.0

nt = 42nx = 10

c = 1.0

Du4a,init(x) = 0

function [u] = u4a_init(x) u = sin(x);end

function [u] = du4a_init(x) u = 0*x;end

function [u] = u4a_bndry(t) u = [0*t; 0*t];end

x

Wave Equation

tfinal = 10

Page 46: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

46

Example 1

Selecting the Rotate 3D icon allows you to rotate the image

Wave Equation

Page 47: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

47

Example 2

If we start with a straight line and create a pulse (likewith slinkies), we get the following wave[x4b, t4b, U4b] = wave1d( 1, [0, 10], 50, [0, 45], 350, @u4b_init, @du4b_init,

@u4b_bndry );mesh( t4b, x4b, U4b );frames4b = animate( U4b );frames2gif( frames4b, 'plot4b.i.gif' );

tfunction [u] = u4c_bndry(t) u = [(1 - cos(t)).*(t <= 2*pi); 0*t];end

1

–1

0

Wave Equation

x

Page 48: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

48

Example 2

Suppose we allow the one end to move freely:– This would represent an insulated boundary [x4b, t4b, U4b] = wave1d( 1, [0, 10], 50, [0, 45], 350, @u4b_init, @du4b_init,

@u4b_bndry );mesh( t4b, x4b, U4b );frames4b = animate( U4b );frames2gif( frames4b, 'plot4b.ii.gif' );

function [u] = u4c_bndry(t) u = [(1 - cos(t)).*(t <= 2*pi); NaN*t];end

t

2

–2

0

1

–1

Wave Equation

x

Page 49: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

49

Example 3

If we exceed 1, the approximation diverges:

[x4b, t4b, U4b] = wave1d( 1, [0, 10], 50, [0, 45], 221, @u4b_init, @du4b_init, @u4b_bndry );mesh( t4b, x4b, U4b );frames4b = animate( U4b, [-3, 3] );frames2gif( frames4c, 'plot4b.iii.gif' );

2

1.0046c t

h

x t

3

–3

0

Wave Equation

Page 50: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

50

Crank-Nicolson and Implicit Methods?

What about using the ideas from the Crank-Nicolson approach– Without justification, I tried to incorporate the method– The method, however, did not decrease the error—it significantly

increased it

Wave Equation

Page 51: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

51

Summary

We have looked at the wave equation– Considered the physical problem– Considered the effects in one dimension– Found a finite-difference equation approximating the wave

equation

• Saw that

• Examples

– We considered insulated boundaries

2

1c t

h

Wave Equation

Page 52: The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada

52

References

[1] Glyn James, Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2007, p.778.

[2] Glyn James, Advanced Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2011, p.164.

Wave Equation