a numerical approximation of the wave equation

Upload: anonymous-jshutp

Post on 06-Apr-2018

251 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    1/31

    A Numerical Approximation of theWave Equation

    Jay BorthenGeorgetown University

    Mathematics and Statistics

    December 17, 2010

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    2/31

    2

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    3/31

    Contents

    1 Abstract 7

    2 Derivation of the Wave Equation 92.1 A String in Tension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.3 Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    3 The Finite Difference Method 193.1 The Forward Difference Scheme (Explicit Method) . . . . . . . . . . . . . . 193.2 The Backward Difference Scheme . . . . . . . . . . . . . . . . . . . . . . . . 203.3 Central Difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.4 The Five-Point Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    4 Discretization of the Equation 25

    4.1 Semi-Discrete Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.2 Fully-Discrete Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

    5 Implementation 295.1 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.2 Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.3 Stability and Consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    6 Example 35

    3

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    4/31

    4 CONTENTS

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    5/31

    List of Figures

    2.1 Conceptual Wave Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.2 Example Mesh for Two-Dimensional Finite Difference Methods . . . . . . . 17

    6.1 Location of Wave Origin Selected on the 2D Square Membrane . . . . . . . 406.2 Finite Difference Approximation at Timestep 10 . . . . . . . . . . . . . . . 416.3 Finite Difference Approximation at Timestep 50 . . . . . . . . . . . . . . . 426.4 Finite Difference Approximation at Timestep 100 . . . . . . . . . . . . . . . 436.5 Finite Difference Approximation at Timestep 200 . . . . . . . . . . . . . . . 446.6 Finite Difference Approximation at Timestep 300 . . . . . . . . . . . . . . . 456.7 Finite Difference Approximation at Timestep 400 . . . . . . . . . . . . . . . 46

    5

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    6/31

    6 LIST OF FIGURES

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    7/31

    Chapter 1

    Abstract

    This paper explores numerical approximation of the partial differential equation known asthe Wave Equation. A derivation of the equation is presented first followed by a discussionof multiple Finite Difference schemes. Then, several types of boundary conditions andinitial conditions are covered before discussing the implementation of the Finite Differenceapproximation on a membrane in two-dimensional space.

    7

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    8/31

    8 CHAPTER 1. ABSTRACT

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    9/31

    Chapter 2

    Derivation of the Wave Equation

    There are multiple ways to derive the Wave Equation. The derivation presented here isrelatively straight forward and employs Newtons Second Law of Motion.

    2.1 A String in Tension

    If we consider a string in tension and focus on a small section of said string, namely,the part between x and x shown in Figure 2.1, then we can make the assumption that ifthe displacements in the y-direction are reasonably small then the tension, T, is equal butopposite on either side of the section.

    From here we can break the force, T, into its component forces, Fy and Fx.

    Fy = Tsin() + Tsin( + )

    For small angles, Tsin() T and Tsin( + ) T( + ), so Fy becomes

    Fy = T (2.1)

    Figure 2.1: Conceptual Wave Element

    9

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    10/31

    10 CHAPTER 2. DERIVATION OF THE WAVE EQUATION

    Our small section of string has mass dm such that, utilizing Newtons Second Law,F = ma, we have

    Fy = T = dmd2y

    dt2= x

    d2y

    dt2, (2.2)

    where is the density of the string (i.e. mass per unit length).

    If we now focus on a single point in time and consider the change in y with respect tothe change in x we see that

    y

    x= tan()

    and taking the derivative with respect to gives us

    1

    cos2()

    d

    dx=

    2y

    x2.

    Again, assuming small amplitudes,

    1

    cos2()

    d

    dx d

    dx= d

    dx=

    2y

    x2.

    Equation (2.2) then becomes

    xd2y

    dt2= Tx

    2y

    x2

    or

    d2y

    dt2= T

    2y

    x2

    If we define c as a wave celerity (velocity) such that

    c =

    T

    Then

    d2y

    dt2= c2

    2y

    x2(2.3)

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    11/31

    2.2. BOUNDARY CONDITIONS 11

    Equation (2.3) can be extended into additional dimensions. The resulting equation forthe wave in two-space is

    d2u

    dt2= c2(

    2u

    x2+

    2u

    y2). (2.4)

    Here u is our displacement function and is dependent on x, y, and t. In the preceedingderivation the displacement function is y which was only dependent on x and t.

    The form of a general linear second order partial differential equation is

    a(x, y)uxx + 2b(x, y)uxy + c(x, y)uyy + e(x, y)uy + g(x, y)u = f(x, y)

    and because b2 ac > 0 holds true for the Wave Equation the equation is said to behyperbolic.

    2.2 Boundary Conditions

    Figure 2.2 on the following page shows an example of a mesh used in Finite Differencemethods. Boundary conditions and initial conditions are applied to the mesh in order toprovide a stepping-off point of sorts. The three primary types of boundary conditions usedfor approximating partial differential equations include:

    1. Dirchlet conditions

    2. Neumann conditions

    3. Robin conditions

    Dirichlet boundary conditions are probably the easiest to implement. They exist whenthe displacement function,u(x , y , t), is defined on its physical boundaries (i.e. at (0, y , t),(Lx, y , t), (x, 0, t), and (x, Ly, t) where Lx and Ly are the length and width of the region). For

    the computer implementation presented later in this paper, Dirichlet boundary conditionsare used such that

    u(0, y , t) = 0

    u(Lx, y , t) = 0

    u(x, 0, t) = 0

    u(x, Ly, t) = 0.

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    12/31

    12 CHAPTER 2. DERIVATION OF THE WAVE EQUATION

    Neumann boundary conditions exist when the first derivatives of the underlying functionare given at the boundaries of the mesh. For example,

    u(0, y , t)

    y= gx1(0, y , t)

    u(Lx, y , t)

    y= gx2(Lx, y , t)

    u(x, 0, t)

    x= gy1(x, 0, t)

    u(x, Ly, t)

    x= gy2(x, Ly, t).

    Combining Dirichlet boundary conditions and Neumann boundary conditions we end upwith Robin boundary conditions which exist when the following conditions are imposed onthe boundaries.

    1u(0, y , t) + 1u(0, y , t)

    y= gx1(0, y , t)

    1u(Lx, y , t) + 1u(Lx, y , t)

    y= gx2(Lx, y , t)

    2u(x, 0, t) + 2u(x, 0, t)

    x= gy1(x, 0, t)

    2u(x, Ly, t) + 2u(x, Ly, t)

    x = gy2(x, Ly, t)

    Here 1, 2, 1, and 2 are non-zero constants.

    2.3 Initial Conditions

    Initial conditions are like boundary conditions for the time variable. In the exampleprovided later, the initial conditions include u(x,y, 0) and u(x,y, 0). Because the WaveEquation is of second order, the underlying function as well as the first derivative need tobe defined at t=0. For an n-order partial differential equation the displacement function upto its (n-1)-derivative is needed to satisfy the initial conditions. The provided example has

    the following initial conditions,

    u(x,y, 0) = 0

    and

    tu(x,y, 0) = 0

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    13/31

    2.3. INITIAL CONDITIONS 13

    Figure 2.2: Example Mesh for Two-Dimensional Finite Difference Methods

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    14/31

    14 CHAPTER 2. DERIVATION OF THE WAVE EQUATION

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    15/31

    Chapter 3

    The Finite Difference Method

    In this section multiple Finite Difference schemes are discussed. We assume here that ourfunction u(x) is differentiable up to a high order.

    3.1 The Forward Difference Scheme (Explicit Method)

    The Forward Difference method is explicit in that it is possible to determine new valuesin time directly from the previously known values. The scheme itself can be derived fromthe Taylor Series,

    u(x + h) = u(x) +u(x)

    1!h +

    u(x)

    2!h2 +

    u3(x)

    3!h3 + ...

    Solving for u(x) we get

    u(x) =u(x + h) u(x)

    h

    u(x)

    2!h2 +

    u(3)(x)

    3!h3 + ...

    . (3.1)

    The infinite series in the parentheses is our error term, , such that

    = O

    u(x)

    2!h2

    .

    So, from (3.1) we have our Forward Difference quotient

    u(x) u(x + h) u(x)h

    . (3.2)

    3.2 The Backward Difference Scheme

    The Backward Difference method is implicit.

    u(x h) = u(x) u(x)

    1!h +

    u(x)

    2!h2 u

    3(x)

    3!h3 + ...

    15

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    16/31

    16 CHAPTER 3. THE FINITE DIFFERENCE METHOD

    Solving for u(x) we get

    u(x) =u(x) u(x h)

    h+

    u(x)

    2!h2 u

    (3)(x)

    3!h3 + ...

    . (3.3)

    Like the Forward Difference scheme, the infinite series in the parentheses above is ourerror term, , such that

    = O

    u(x)

    2!h2

    .

    So, from (3.3) we have our Backward Difference quotient

    u(x) u(x) u(x h)h

    . (3.4)

    The Backward Difference method is unconditionally stable. Larger time steps can beused in the Backward Difference scheme than in the Forward Difference scheme. This willbe verified in a later section.

    3.3 Central Difference

    The first-order Central Difference quotient is found by taking the average of the ForwardDifference quotient and the Backward Difference quotient. The result is as follows,

    u(x) u(x + h) u(x h)2h

    . (3.5)

    The second-order Central Difference quotient is,

    u(x) u(x + h) 2u(x) + u(x h)h2

    . (3.6)

    3.4 The Five-Point Scheme

    The Five-Point Finite Difference scheme utilizes more terms of the Taylor Series and so

    the error term is smaller. Specifically, the error term of a Five-Point scheme is of order h4

    ,whereas the previous schemes contained errors on the order of h2. The Five-Point FiniteDifference quotient is given below but was not been implemented into the sample code.

    u(x) u(x + 2h) + 8u(x + h) 8u(x h) + u(x 2h)12h

    . (3.7)

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    17/31

    Chapter 4

    Discretization of the Equation

    4.1 Semi-Discrete Equation

    In the context of the Wave Equation, semi-discrete refers to the discretization of the twospace dimensions. We start by plugging the second-order Central Difference quotient intothe Wave Equation for each second derivative with respect to a space dimension, leaving thepartial with respect to time on the left-hand side in continuous form.

    d2u

    dt2= c2

    u(x + h , y , t) 2u(x , y , t) + u(x h , y , t)

    h2+

    u(x, y + h, t) 2u(x , y , t) + u(x, y h, t)h2

    .

    4.2 Fully-Discrete Equation

    Discretizing time, our equation above becomes

    u(x , y , t + k) 2u(x , y , t) + u(x , y , t k)k2

    = (4.1)

    c2

    u(x + h , y , t) 2u(x , y , t) + u(x h , y , t)h2

    +u(x, y + h, t) 2u(x , y , t) + u(x, y h, t)

    h2

    .

    If we define so that

    = c

    k

    h

    and we solve for u(x , y , t + k) in equation (4.1) then

    u(x , y , t + k) = 2(u(x + h , y , t) 4u(x , y , t) + u(x h , y , t)+ (4.2)u(x, y + h, t) + u(x, y h, t)) + 2u(x , y , t) u(x , y , t k).

    17

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    18/31

    18 CHAPTER 4. DISCRETIZATION OF THE EQUATION

    At time zero, u(x , y , t k) does not exist. Therefore, the first-order Central Differencequotient and the initial value of the first time-derivative are used to find an approximationto u(x , y , t k), that is, one without t k.

    u(x , y , t + k) u(x , y , t k)2k

    = g(x , y , t)

    u(x , y , t k) = u(x , y , t + k) 2kg(x , y , t) (4.3)

    Now if we plug equation (4.3) into equation (4.2) and again solve for u(x , y , t + k) thent = 0 and

    u(x , y , t + k) = 2(u(x + h , y , t)

    4u(x , y , t) + u(x

    h , y , t)+ (4.4)

    u(x, y + h, t) + u(x, y h, t)) + 2u(x , y , t) u(x , y , t + k) + 2kg(x , y , t).

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    19/31

    Chapter 5

    Implementation

    5.1 Software

    Matlab was used for the implementation of the example in this paper, however, there area variety of programs and programming languages that can be used to work with the WaveEquation and its Finite Difference schemes. No matter what software is used or developed,though, there will always be error when utilizing approximation methods like the FiniteDifference method. If there wasnt error then it wouldnt be called an approximation.

    5.2 Error

    Error is unavoidable in numerical analysis and this includes rounding error as well astruncation error. If we look at formula (3.1) we can clearly see that the interval h and theerror have a positive relationship. The smaller h is the smaller the error is. However, this iswhere an artform begins to emerge because a trade-off needs to be made between the size ofthe error and the computer run-time. More time is needed for the computer to approximatea solution the smaller h is.

    For the Forward Difference scheme, Backward Difference scheme, and the Central Differ-ence scheme the local truncation error at the value a is, is

    = Of(a)

    2!(x

    a)2 .

    It is readily apparent from the formula above that the error increases quadratically asthe distance from the initial point, a, gets larger.

    5.3 Stability and Consistency

    Stability and consistency are, together, necessary and sufficient for numerical convergenceof discrete approximations of PDEs. Neither condition is sufficient by itself.

    19

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    20/31

    20 CHAPTER 5. IMPLEMENTATION

    Stability is a primary concern most often in explicit schemes. It refers to the magnificationof truncation and round-off errors. Courant et al. proved that in order for an explicit finitedifference to be stable (for the wave equation) the following inequality must hold,

    ck

    h 1

    N,

    where N is the number of space dimension, in this case two. This is called the CFLcondition. And as much as I hate to quote Wikipedia, the Wikipedia stub related to theCFL condition describes the inequality succinctly,

    If a wave is crossing a discrete grid, then the timestep must be less than thetime for the wave to travel adjacent grid points.

    Another concern in numerical approximation is consistency. Dr. Wang explains that afinite difference scheme is said to be consistent if the local truncation error satisf[ies] the following condition:

    limh0

    max

    1iN1|i(h)|

    = 0

    This implies that the truncation error is a function of the step size, h. As h approacheszero the error should as well.

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    21/31

    Chapter 6

    Example

    Central Difference quotients are applied here to the Wave Equation. A two-dimensionalmesh is considered. The third space dimension is the wave height, u(x,y,t). A forth dimen-sion, time, is also part of the Wave Equation and is used to create an animation of a waveapproximation in three-space.

    MATLAB CODE:

    function SurfaceWave(h,k,c,T,L)

    % SurfaceWave.m

    % Written by Jay Borthen (Dec 2010)

    % Georgetown University, Mathematics and Statistics

    % h is the mesh step size in both the x and y directions

    % k is the time step size

    % c is the wave celerity (velocity)

    % T is the total number of time steps

    % L is the length and width of the square membrane

    % Example: SurfaceWave(1,0.8,0.7,401,50)

    Lx=L; %bx is the length of the membrane in the x direction

    Ly=L; %by is the length of the membrane in the y direction

    %Check CFL conditionif c*(k/h)

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    22/31

    22 CHAPTER 6. EXAMPLE

    axis xy

    grid on

    [rx, ry]=getpts;

    u=zeros(Lx,Ly,T);

    for j=1:T-1

    for ii=1:Ly

    for i=1:Lx

    %Implement x-dimension boundary condition

    if i==1 || i==Lx

    u(i,ii,j)=0;

    else

    %Implement y-dimension boundary condition

    if ii==1 || ii==Ly

    u(i,ii,j)=0;

    else

    %Implement initial conditions

    if j==1

    u(i,ii,j)=0;

    ut(i,ii,j)=(1/60*pi)*exp(-(1/2)*((((1+i*h)-ry)^2)+

    (((1+(ii)*h)-rx)^2)));

    %Finite difference

    u(i,ii,j+1)=(sigma^2)*(u(i+1,ii,j)-4*u(i,ii,j)+

    u(i-1,ii,j)+u(i,ii+1,j)+u(i,ii-1,j))+

    2*u(i,ii,j)-u(i,ii,j+1)+2*k*ut(i,ii,j);

    else

    u(i,ii,j+1)=(sigma^2)*(u(i+1,ii,j)-4*u(i,ii,j)+

    u(i-1,ii,j)+u(i,ii+1,j)+u(i,ii-1,j))+2*u(i,ii,j)-

    u(i,ii,j-1);

    end

    end

    end

    end

    end

    if j==10 || j==50 || j==100 || j==200 || j==300 || j==400 || j==500

    figure

    subplot(2,1,1)

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    23/31

    23

    surf(u(:,:,j))

    title([Homogeneous Wave Equation at , num2str(j), timesteps of

    length , num2str(k)])

    view(-37.5,70)

    colormap(winter)

    axis([0 Lx 0 Ly -0.07 0.07])

    subplot(2,1,2)

    contour(u(:,:,j))

    axis([0 Lx 0 Ly])

    end

    end

    fprintf(The origin of the wave occured at (%1.1f, %1.1f).\n,rx,ry)

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    24/31

    24 CHAPTER 6. EXAMPLE

    Figure 6.1: Location of Wave Origin Selected on the 2D Square Membrane

    MATLAB COMMAND LINE INPUT/OUTPUT:

    >> SurfaceWave(1,0.8,0.7,401,50)

    The origin of the wave occured at (11.5,36.8).

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    25/31

    25

    Figure 6.2: Finite Difference Approximation at Timestep 10

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    26/31

    26 CHAPTER 6. EXAMPLE

    Figure 6.3: Finite Difference Approximation at Timestep 50

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    27/31

    27

    Figure 6.4: Finite Difference Approximation at Timestep 100

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    28/31

    28 CHAPTER 6. EXAMPLE

    Figure 6.5: Finite Difference Approximation at Timestep 200

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    29/31

    29

    Figure 6.6: Finite Difference Approximation at Timestep 300

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    30/31

    30 CHAPTER 6. EXAMPLE

    Figure 6.7: Finite Difference Approximation at Timestep 400

  • 8/3/2019 A Numerical Approximation of the Wave Equation

    31/31

    Bibliography

    [1] Courant, R., K. Friedrichs and H. Lewy, On the partial difference equations of math-ematical physics, IBM Journal, March 1967, pp. 215-234, English translation ofthe 1928 German original. (http://www.stanford.edu/class/cme324/classics/courant-

    friedrichs-lewy.pdf)

    [2] Dong, Shuonan, Finite Difference Methods for the Hyper-bolic Wave Partial Differential Equations, MIT, Spring 2006.(http://web.mit.edu/dongs/www/publications/projects/2006-04-12 18.085 Wave.pdf)

    [3] Lewin, Walter, Vibrations and Waves Physics Lecture. MIT - Fall 2004.(http://ocw.mit.edu/courses/physics/8-03-physics-iii-vibrations-and-waves-fall-2004/video-lectures/lecture-7/)

    [4] Sauer, Timothy, Numerical Analysis. Pearson/Addison Wesley, New York, 2006.

    [5] Wang, Junping, Numerical Methods for Partial Differential Equations Lecture Notes.Georgetown University - Fall, 2010.