+ All Categories
Home > Documents > Numerical 2

Numerical 2

Date post: 14-Apr-2018
Category:
Upload: bittu
View: 218 times
Download: 0 times
Share this document with a friend

of 44

Transcript
  • 7/30/2019 Numerical 2

    1/44

    Numerical Methods

    Marisa Villano, Tom Fagan,

    Dave Fairburn, Chris Savino,

    David Goldberg, Daniel Rave

  • 7/30/2019 Numerical 2

    2/44

    An Overview

    The Method of Finite DifferencesError Approximations and DangersApproxmations to DiffusionsCrank Nicholson SchemeStability Criterion

  • 7/30/2019 Numerical 2

    3/44

    Finite Differences

    Best known numerical method ofapproximation

    Marisa Villano

  • 7/30/2019 Numerical 2

    4/44

    Finite Differences

    Approximating the derivative with adifference quotient from the Taylor series

    Function of One VariableChoose mesh size x

    Then u j ~ u( j x)

  • 7/30/2019 Numerical 2

    5/44

    First Derivative Approximations

    Backward difference: ( u j u j-1) / x

    Forward difference: ( u j+1 u j) / x

    Centered difference: ( u j+1 u j-1) / 2 x

  • 7/30/2019 Numerical 2

    6/44

    Taylor Expansionu( x + x) = u( x) + u ( x) x + 1/2 u ( x)( x)

    + 1/6 u ( x)( x) + O( x)

    u( x x) = u( x) u ( x) x + 1/2 u ( x)( x)- 1/6 u ( x)( x) + O( x)

    2

    3

    4

    4

    2

    3

  • 7/30/2019 Numerical 2

    7/44

    Taylor Expansionu ( x) = u( x) u( x x) + O( x)

    x u ( x) = u( x + x) u( x) + O( x)

    x u ( x) = u( x + x) u( x x) + O( x)

    2 x

    2

  • 7/30/2019 Numerical 2

    8/44

    Second Derivative Approximation

    Centered difference: ( u j+1 2u j + u j-1) / ( x)

    Taylor Expansionu ( x) = u( x + x) 2u( x) + u( x x) + O( x)

    ( x)

    2

    2

    2

  • 7/30/2019 Numerical 2

    9/44

    Function of Two Variables

    u( j x, nt ) ~ u j Backward difference for t and x

    ( j x, nt ) ~ (u j u j ) / t

    ( j x, nt ) ~ (u j u j ) / x

    n

    n n-1

    n-1

    n

    u t

    u x

  • 7/30/2019 Numerical 2

    10/44

    Function of Two Variables

    Forward difference for t and x

    ( j x, nt ) ~ (u j u j ) / t

    ( j x, nt ) ~ (u j u j ) / x

    n+1

    n+1 n

    nu t

    u x

  • 7/30/2019 Numerical 2

    11/44

    Function of Two Variables

    Centered difference for t and x

    ( j x, nt ) ~ (u j u j ) / (2 t )

    ( j x, nt ) ~ (u j u j ) / (2 x)

    n+1

    n+1 n-1

    n-1u t

    u x

  • 7/30/2019 Numerical 2

    12/44

    Error Truncation Error: introduced in the solution by theapproximation of the derivative

    Local Error: from each term of the equationGlobal Error: from the accumulation of localerror

    Roundoff Error: introduced in the computation bythe finite number of digits used by the computer

  • 7/30/2019 Numerical 2

    13/44

  • 7/30/2019 Numerical 2

    14/44

    Example from 8.1

    Consider u t = u xx u(x,0) = h(x)We will use the finite difference method toapproximate the solutionForward difference for u tCentered difference for u xxRe-write equation in terms of the finitedifference approximations

  • 7/30/2019 Numerical 2

    15/44

    Finite Difference Eqn.

    u jn+1 - u jn = u n j+1 - 2u jn + u n j-1

    t x( ) 2

    Error: The local truncation error is O( t)

    from the left hand side and is O( x) 2 from

    the right hand side.

  • 7/30/2019 Numerical 2

    16/44

    Assumptions

    Assume that we choose a small change inx, and that the denominator on both sides

    of the equation are equal.We are now left with the scheme:

    u jn+1 = u n j+1 - u n j + u n j-1Solving u with this scheme is now easy todo once we have the initial data.

  • 7/30/2019 Numerical 2

    17/44

    Initial Data

    Let u(x,0) = h(x) = a step function withthe following properties:

    h(x) = 0 for all j except for j = 5, soh j = 0 0 0 0 1 0 0 0 0 0 0 .

    Initially, only a certain section, which is

    at j = 5 is equal to the value of 1. j serves as the counter for the xvalues.

  • 7/30/2019 Numerical 2

    18/44

    How to solve?We know u 0 j = 1 at j = 5 and 0 at all other jinitially (given by superscript 0).We can plug into our scheme to solve for u 1

    jat

    all js. u1 j = u 0 j-1 - u 0 j + u 0 j+1u15 = -1; u 14 = 1; u 16 = 1

    Now we can continue to increase the # ofiterations, n, and create a table

  • 7/30/2019 Numerical 2

    19/44

    Solution for 4 iterations4 1 -4 10 - 16 19 -16 10 -4 1 0

    3 0 1 -3 6 -7 6 -3 1 0 0

    2 0 0 1 -2 3 -2 1 0 0 0

    1 0 0 0 1 -1 1 0 0 0 0

    0 0 0 0 0 1 0 0 0 0 0

    1 2 3 4 5 6 7 8 9 10

    j values

    n-valu

    es

  • 7/30/2019 Numerical 2

    20/44

    Analysis of SolutionIs this solution viable?Maximum principle states that the solution must

    be between 0 and 1 given our initial dataAt n = 4, our solution has already ballooned to u= 19!Clearly, there are cases when the finitedifference method can pose serious problems.

  • 7/30/2019 Numerical 2

    21/44

    Charting the ErrorAssume the solution is constant and equal to 0.5 (halfway betweenthe possible 0 and 1)

  • 7/30/2019 Numerical 2

    22/44

    Lessons Learned

    While the finite difference method is easyand convenient to use in many cases,

    there are some dangers associated withthe method.We will investigate why the assumption

    that allowed us to simplify the schemecould have been a major contributor tothe large error.

  • 7/30/2019 Numerical 2

    23/44

    Approximations of Diffusions

    Neumann Boundary Conditions

    and the Crank-Nicolson Scheme

    Chris Savino

  • 7/30/2019 Numerical 2

    24/44

    Approximations of DiffusionsErrors have accumulated from theapproximations of the derivatives using theprevious schemeThe problem is the choice of the mesh tto the mesh x Let s=

    can solve scheme

    2( )t

    x

    11 1( ) (1 2 )n n n n j j j ju s u u s u

  • 7/30/2019 Numerical 2

    25/44

    Neumann Boundary Conditions0 x l

    Simplest Approximations are

    (0, ) ( ) xu t g t ( , ) ( ) xu l t h t

    1 0n n nu u g x

    1n n j j nu u h x

  • 7/30/2019 Numerical 2

    26/44

    To get smallest error, we use centereddifferences for the derivatives on the boundaryIntroduce ghost points

    Boundary Conditions become1

    nu 1n

    ju

    1 1

    2

    n nnu u

    g x1 1

    2

    n n j j nu u

    h x

  • 7/30/2019 Numerical 2

    27/44

    Crank-Nicolson Scheme

    Can avoid any restrictions on stabilityconditions

    Unconditionally stable no matter what thevalue of s is.

  • 7/30/2019 Numerical 2

    28/44

    Centered Second Difference:

    Pick a number theta between 0 and 1Theta scheme:

    1 122

    2( )( )

    n n n j j j

    n ju u u

    u x

    12 2 1(1 )( ) ( )

    n n j j n n

    j ju u

    u ut

  • 7/30/2019 Numerical 2

    29/44

    We analyze the scheme by plugging in aseparated solution

    Therefore

    1 2(1 ) (1 cos )( )

    1 2 (1 cos )

    s k xk

    s k x

    ( ) ( ( ))n ik x j n ju e k

  • 7/30/2019 Numerical 2

    30/44

    Must Check stability condition

    If then

    Therefore

    is always true

    ( ) 1k

    ( ) 1k (1 2 )(1 cos ) 1 s k x

    1 2 0

  • 7/30/2019 Numerical 2

    31/44

    If then there is no restriction on the sizeof s for stability to holdThe scheme is unconditionally stableWhen theta = it is called the Crank-NicolsonschemeIf theta < then the scheme is stable if

    11

    2

    2

    1( ) 2 4

    t s

    x

  • 7/30/2019 Numerical 2

    32/44

    Stability Criterion

    Approximations of the diffusion

    equation, u t=u xx

    David Goldberg

  • 7/30/2019 Numerical 2

    33/44

    Stability Criterion

    The method of finite differences gives ananswer, but it does not guarantee that thisanswer is meaningful.Values must be chosen appropriately, toensure that the results make sense andare applicable to real world scenarios.This condition, that values must satisfy inorder to be worthwhile, is called thestability criterion.

  • 7/30/2019 Numerical 2

    34/44

    Example

    As per the book, take, for instance, thediffusion problem:

    , 0 = = in 0, 2 in 2 ,

    = for 00

    = 0 at x=0, , that is0, = , = 0

  • 7/30/2019 Numerical 2

    35/44

    Example, continued

    As can be easily shown, the graph of (x)looks like this.

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    1.41.6

    1.8

    0 0.5 1 1.5 2 2.5 3 3.5

  • 7/30/2019 Numerical 2

    36/44

    Example, continued

    In attempting to use the method of finitedifferences, we are using a forwarddifference for u

    t and a centered difference

    for u xx.This means that

    It is important to note here that thesuperscript n denotes a counter on the tvariable, and the subscript j denotes a

    counter on the x variable.

    +1

    = +1 2 + 1

    2

  • 7/30/2019 Numerical 2

    37/44

    Example, continued

    In order to make the calculations a bitcleaner, we are introducing a variable, s ,which is defined by

    Rearranging, we have

    It would be nice if we could just plug in

    values and get a valid result

    2( )

    t

    x s

    11 1

    11 1

    11 1

    2

    2

    1 2

    n n n n n j j j j j

    n n n n n j j j j j

    n n n n j j j j

    u s u u u u

    u s u s u u s u

    u s u u s u

  • 7/30/2019 Numerical 2

    38/44

    Example, continued

    However, putting in different values can lead to theresults being close to, or far from, that actual answer.For instance, letting x= /20, and letting s=5/11, we geta relatively nice result. Letting s=5/9 does not get sucha nice result.

    So what, of significance, changes?

    0

    0.5

    1

    1.5

    2

    0 1 2 3 40

    0.5

    1

    1.5

    2

    0 1 2 3 4

  • 7/30/2019 Numerical 2

    39/44

    Example, Continued

    As it turns out, changing the value of s cansignificantly change the validity of the

    solution. To see why, we return to ourequation. 1 1 1

    1 11

    ...

    1 2

    Seperate variables

    So, by combining like terms,

    1 2

    n n n n j j j j

    n j j n

    j jn

    n j

    u s u u s u

    u XT u X T

    X X T s s

    T X

  • 7/30/2019 Numerical 2

    40/44

    Example, continuedSince the left hand side is a function of Tand the right hand side is a function of X,they must be equal to a constant.

    1 11

    11 0

    1 1

    ...

    1 2

    and also

    1 2

    j jn

    n j

    nnn n n

    n

    j j

    j

    X X T s s

    T X

    T T T T T

    T

    X X s s

    X

  • 7/30/2019 Numerical 2

    41/44

    Example, continued

    This is a discrete version of an ODE,which when solved gives

    0

    ...

    1 2 ( )1 2 2 cos( )

    Since, as discovered before,

    if 1, T will grow without bound.

    By above,

    1 4 1

    1So 1 4 1,

    2

    ik x ik x

    nn

    s s e e s s k x

    T T

    s

    s s

  • 7/30/2019 Numerical 2

    42/44

    Example, finished

    Thus, to achieve stability, . This iswhy setting s=5/9 didnt give a valid

    result.It is to be noted that usually the necessarycriterion is that , but

    that in this case it was irrelevant.So the stability criterion must be workedout before one can effectively use the

    method of finite differences.

    1 ( ) instead of 1O t

    212

    t

    x

  • 7/30/2019 Numerical 2

    43/44

    Approximations of Diffusions

    Example from 8.2

    Daniel Rave

  • 7/30/2019 Numerical 2

    44/44

    Summary

    Breif Review of Methods

    Wide Applicability

    Importance of Stability


Recommended