Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

21
Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation

Transcript of Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Page 1: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Scientific Computing

Partial Differential EquationsExplicit Solution of

Wave Equation

Page 2: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Partial Differential Equations

• Our study of PDE’s is focused on linear, second-order equations

• The following general form will be evaluated for B2 - 4AC (Variables – x and y/t)

A∂ 2u

∂x 2 + B∂ 2u

∂x∂y+C

∂ 2u

∂y 2 +D = 0

Page 3: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Partial Differential Equations

B2-4AC Category Example

< 0 Elliptic Laplace equation (steady state with 2 spatial dimensions)

= 0 Parabolic Heat conduction equation (time variablewith one spatial dimension)

>0 Hyperbolic Wave equation (time-variable with onespatial dimension)

∂2u

∂ t 2 = c 2 ∂2u

∂x 2

∂2u

∂x 2 +∂ 2u

∂y 2 = 0

∂u∂t

= α∂ 2u

∂x 2

Page 4: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation

Mechanical vibrations of a guitar string, or in the membrane of a drum, or a cantilever beam are governed by a partial differential equation, called the wave equation.

To derive the wave equation we consider an elastic string vibrating in a plane, as the string on a guitar. Assume u(x,t) is the displacement of the string away from its equilibrium position u=0.

Page 5: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation

u(x,t)

x

u

T(x+x,t)

T(x,t)

x x+x

Page 6: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation

Newton’s Law: F=maVertical:

where ρ is the mass density function of the stringHorizontal:

As we assume there is only vertical motion of the string

T(x+x,t)

T(x,t)

FVert = T(x + Δx, t)sinβ −T(x, t)sinα

ma = ρΔx∂ 2u

∂t 2

FHoriz = T(x + Δx, t)cosβ −T(x, t)cosα = 0

Page 7: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation

Let Then,

So, Fvert = ma implies, from the previous slide, that

Or,

T = T(x + Δx, t)cosβ = T(x, t)cosα

T(x + Δx, t) =T

cosβ, T(x, t) =

T

cosα

T

cosβsinβ −

T

cosαsinα = ρΔx

∂ 2u

∂t 2

T(tanβ − tanα ) = ρΔx∂ 2u

∂t 2

Page 8: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation

Now, tan β is just the slope of the string at x+Δx and tan α is the slope at x.

Thus,

So,

T(x+x,t)

T(x,t)

tanβ =∂u

∂x x+Δx

and tanα =∂u

∂x x

T(∂u

∂x x+Δx

−∂u

∂x x

) = ρΔx∂ 2u

∂t 2

1

Δx(∂u

∂x x+Δx

−∂u

∂x x

) =ρ

T

∂ 2u

∂t 2

Page 9: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation

Now, take the limit as Δx -> 0, to get

This the Wave Equation in one dimension (x) €

1

Δx(∂u

∂x x+Δx

−∂u

∂x x

) =ρ

T

∂ 2u

∂t 2

∂2u

∂t 2 = c 2 ∂2u

∂x 2

Page 10: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation-Boundary

Since the wave equation is second order in space and time, we need two boundary conditions for each variable. We will assume the string x parameter varies from 0 to 1.

Typical set-up is to give boundary conditions at the ends of the string in time:

u(0,t) = g0(t) u(1,t) = g1(t) and space initial conditions for the displacement and

velocity: u(x,0) = f1(x) ut(x,0)=f2(x)

Page 11: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Wave Equation

utt − c 2uxx = 0 0 ≤ x ≤1 0 ≤ t

u(0, t) = g0(t)

u(1, t) = g1(t)

u(x,0) = f1(x)

ut (x,0) = f2(x)

Page 12: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

• We will solve this equation for x and t values on a grid in x-t space:

One Dimensional Wave Equation

t

x00 x ix

nxh /1

jt

00 t

mTtk /

mtT

1nx

Approximatesolution uij=u(xi, tj) at grid points

Page 13: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

• To approximate the solution we use the finite difference approximation for the two derivatives in the wave equation. We use the centered-difference formula for the space and time derivatives:

Finite Difference Approximation

utt (x i, t j ) =1

k 2 u(x i, t j−1) − 2u(x i, t j ) + u(x i, t j+1)( )

c 2uxx (x i, t j ) =c 2

h2 u(x i−1, t j ) − 2u(x i, t j ) + u(x i+1, t j )( )

Page 14: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

• Then the wave equation (utt =c2 uxx ) can be approximated as

Or,

Let p = (ck/h) Solving for ui,j+1 we get:

Finite Difference Approximation

1

k 2 ui, j−1 − 2ui, j + ui, j+1( ) =c 2

h2 ui−1, j − 2ui, j + ui+1, j( )

ui, j+1 = p2ui−1, j + 2(1− p2)uij + p2ui+1, j − ui, j−1( )€

ui, j−1 − 2ui, j + ui, j+1( ) =k 2c 2

h2 ui−1, j − 2ui, j + ui+1, j( )

Page 15: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

• Note that this formula uses info from the j-th and (j-1)st time steps to approximate the (j+1)-st time step:

One Dimensional Wave Equation

t

x

1ix ix 1ix

1jt

jt

mtT

00 t

00 x 1nx

Page 16: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

• The solution is known for t=0 (j=0) but the formula uses values for j-1 , which are unknown. So, we use the initial condition ut(x,0)=f2(x) and the cenetered difference approximation for ut to get

• At the first time step, we then get

One Dimensional Wave Equation

ut (x i,0) = f2(x i) ≅ui,1 − ui,−1

2k⇒ ui,−1 = ui,1 − 2kf2(x i)

ui,1 = p2ui−1,0 + 2(1 − p2)ui0 + p2ui+1,0 − (ui,1 − 2kf2(x i))( )

Page 17: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

• Simplifying, we get

• So,

One Dimensional Wave Equation

ui,1 = 0.5p2ui−1,0 + (1− p2)ui0 + 0.5p2ui+1,0 + kf2(x i)( )

ui,1 = 0.5p2ui−1,0 + (1 − p2)ui0 + 0.5p2ui+1,0 + kf2(x i)( )

ui, j+1 = p2ui−1, j + 2(1 − p2)uij + p2ui+1, j − ui, j−1( )

Page 18: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

function z = explicitWave(f1, f2, g0, g1, T, n, m, c)%Explicit solution to wave equation % Constants, x and t vectors h = 1/n; k = T/m; p = c*k/h; x = 0:h:1; t = 0:k:T; % Boundary conditions u(1:n+1, 1) = f1(x)’; uprime(1:n+1, 1) = f2(x)'; u(1, 1:m+1) = g0(t); u(n+1, 1:m+1) = g1(t); % Solution for second row u(2:n, 2) = 0.5*(p^2)*u(1:n-1,1) + (1-p^2)*u(2:n,1)+0.5*(p^2)*u(3:n+1,1)+k*uprime(2:n,1); % compute solution forward in time from j=3 for j = 2:m u(2:n,j+1) = (p^2)*u(1:n-1,j) + 2*(1-p^2)*u(2:n,j) + (p^2)*u(3:n+1,j) - u(2:n,j-1); end z=u’; mesh(x,t,z);end

Matlab Implementation

Page 19: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Usage: f1= inline(‘x.*(1-x)’); f2=inline(‘0*x’); g0 = inline(‘0*t’); g1 = inline(‘0*t’); n=5; m=5; c=1; T=1.0; z = explicitWave(f1, f2, g0, g1, T, n, m, c);

Matlab Implementation

Page 20: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

Calculated solution appears correct:

Matlab Implementation

Page 21: Scientific Computing Partial Differential Equations Explicit Solution of Wave Equation.

It can be shown that the algorithm for the explicit solution is stable if |p| <= 1.

(Michael Heath – Scientific Computing: An Introductory Survey, McGraw-Hill)

Stability