t 5 open methods

Upload: varunsingh214761

Post on 02-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 t 5 Open Methods

    1/58

    Motilal Nehru National Institute of Technology

    Civil Engineering Department

    Computer Based Numerical Techniques

    CE-401

    Roots of the equations: Open Methods

  • 8/10/2019 t 5 Open Methods

    2/58

    Open Methods

    Bracketing methodsare based on assuming aninterval of the function which brackets the root.

    The bracketing methodsalways convergeto theroot.

    Open methodsare based on formulas thatrequire only a single starting value of x or twostarting values that do not necessarily bracket

    the root. These method sometimes divergefrom the true

    root.

  • 8/10/2019 t 5 Open Methods

    3/58

    1. Simple Fixed-Point Iteration

    Rearrange the function so that x is onthe left side of the equation:

    )(

    )(0)(

    1 ii xgx

    xxgxf

    Bracketing methods are convergent.

    Fixed-point methods may sometime diverge,depending on the stating point (initial guess) andhow the function behaves.

  • 8/10/2019 t 5 Open Methods

    4/58

    Simple Fixed-Point Iteration

    Examples:1.

    2. f(x) = x 2-2x+3 x = g(x)=(x2+3)/2

    3. f(x) = sin x x = g(x)= sin x + x

    3. f(x) = e-x- x x = g(x)= e-x

    x

    xg

    or

    xxg

    or

    xxg

    xxxxf

    21)(

    2)(

    2)(

    02)(

    2

    2

  • 8/10/2019 t 5 Open Methods

    5/58

    Simple Fixed-Point Iteration Convergence

    x = g(x) can be

    expressed as a pair of

    equations:

    y1= x

    y2= g(x). (component

    equations)

    Plot them separately.

  • 8/10/2019 t 5 Open Methods

    6/58

    Simple Fixed-Point Iteration Convergence

    Fixed-point iteration converges if :

    ( ) 1 (slope of the line ( ) )g x f x x

    When the method converges, the erroris roughly proportional to or less than the

    error of the previous step, therefore it is

    called linearly convergent.

  • 8/10/2019 t 5 Open Methods

    7/58

    Simple Fixed-Point Iteration-Convergence

  • 8/10/2019 t 5 Open Methods

    8/58

  • 8/10/2019 t 5 Open Methods

    9/58

  • 8/10/2019 t 5 Open Methods

    10/58

  • 8/10/2019 t 5 Open Methods

    11/58

  • 8/10/2019 t 5 Open Methods

    12/58

    Steps of Simple Fixed Pint Iteration

    1. Rearrange the equation f(x) = 0 so that x ison the left hand side and g(x) is on the righthand side.

    e.g f(x) = x2-2x-1 = 0x= (x2-1)/2

    g(x) = (x2-1)/2 2. Set xiat an initial guess xo.

    3. Evaluate g(xi)

    4. Let xi+1= g(xi) 5. Find a=(Xi+1xi)/Xi+1, and set xi at xi+1 6. Repeat steps 3 through 5 until |a|

  • 8/10/2019 t 5 Open Methods

    13/58

    Example: Simple Fixed-Point Iteration

    1.f(x)is manipulated so that we get

    x=g(x)g(x) = e-x

    2.Thus, the formula predicting the

    new value of x is: xi+1= e-xi

    3.Guess xo = 0

    4.The iterations continues till theapprox. error reaches a certain

    limiting value

    f(x)

    Root x

    f(x)

    x

    f(x)=e-x- x

    g(x) = e-x

    f1(x) = x

    f(x) = e-x

    - x

  • 8/10/2019 t 5 Open Methods

    14/58

    Example: Simple Fixed-Point Iteration

    i xi g(xi) % t%

    0 0 1.01 1.0 0.367879 100 76.3

    2 0.367879 0.692201 171.8 35.13 0.692201 0.500473 46.9 22.14 0.500473 0.606244 38.3 11.85 0.606244 0.545396 17.4 6.896 0.545396 0.579612 11.2 3.83

    7 0.579612 0.560115 5.90 2.28 0.560115 0.571143 3.48 1.249 0.571143 0.564879 1.93 0.70510 0.564879 1.11 0.399

  • 8/10/2019 t 5 Open Methods

    15/58

    Example: Simple Fixed-Point Iteration

    i xi g(xi) % t%

    0 0 1.01 1.0 0.367879 100 76.3

    2 0.367879 0.692201 171.8 35.13 0.692201 0.500473 46.9 22.14 0.500473 0.606244 38.3 11.85 0.606244 0.545396 17.4 6.896 0.545396 0.579612 11.2 3.83

    7 0.579612 0.560115 5.90 2.28 0.560115 0.571143 3.48 1.249 0.571143 0.564879 1.93 0.70510 0.564879 1.11 0.399

  • 8/10/2019 t 5 Open Methods

    16/58

    Example

  • 8/10/2019 t 5 Open Methods

    17/58

    Flow ChartFixed Point

    Start

    Input: xo, s, maxi

    i=0

    a=1.1s

    1

  • 8/10/2019 t 5 Open Methods

    18/58

    Stop

    1

    while

    amaxi

    xn=0

    x0=xn

    100%n oan

    x xx

    Print:xo, f(xo) ,a, i 01

    nx g x

    i i

    False

    True

  • 8/10/2019 t 5 Open Methods

    19/58

    2. The Newton-Raphson Method

    Most widely used method.

    Based on Taylor series expansion:

    )(

    )(

    )(0

    g,Rearrangin

    0)f(xwhenxofvaluetheisrootThe

    ...!2)()()()(

    1

    1

    1i1i

    2

    1

    i

    iii

    iiii

    iiii

    xf

    xfxx

    xx)(xf)f (x

    x

    xfxxfxfxf

    Solve for

    Newton-Raphson formula

  • 8/10/2019 t 5 Open Methods

    20/58

    The Newton-Raphson Method

    A tangent tof(x)at theinitial pointxiis extended

    till it meets the x-axis at

    the improved estimate of

    the rootxi+1.

    The iterations continues

    till the approx. error

    reaches a certain limiting

    value.

    f(x)

    Root x

    xixi+1

    f(x) Slope f/(xi)

    f(xi)

    )(

    )(

    )()(

    /

    /

    i

    ii1i

    1ii

    ii

    xf

    xfxx

    xx

    0xfxf

  • 8/10/2019 t 5 Open Methods

    21/58

    Example: The Newton Raphson Method

    11)(

    )(/1

    x

    x

    ix

    x

    i

    i

    iii

    e

    xex

    e

    xex

    xf

    xfxx

    Use the Newton-Raphson method to find theroot of e-x-x= 0f(x) = e-x-xand f`(x)= -e-x-1;thus

    Iter. xi

    t%

    0 0 100

    1 0.5 11.8

    2 0.566311003 0.147

    3 0.567143165 0.00002

    4 0.567143290

  • 8/10/2019 t 5 Open Methods

    22/58

    Flow ChartNewton Raphson

    Start

    Input: xo, s, maxi

    i=0

    a=1.1s

    1

  • 8/10/2019 t 5 Open Methods

    23/58

    Stop

    1

    while

    a>s &

    i

  • 8/10/2019 t 5 Open Methods

    24/58

    M-file for Newton Raphsons Method

    function [root,ea,iter]=newtraph(func, dfunc, xr, es, maxit, varargin)

    % newtraph: Newton-Raphson root location zeroes

    % [root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,p1,p2,...):% uses Newton-Raphson method to find the root of func

    % input:

    % func = name of function

    % dfunc = name of derivative of function

    % xr = initial guess% es = desired relative error (default = 0.0001%)

    % maxit = maximum allowable iterations (default = 50)

    % p1,p2,... = additional parameters used by function

    % output:

    % root = real root% ea = approximate relative error (%)% iter = number of iterations

  • 8/10/2019 t 5 Open Methods

    25/58

    M-file for Newton Raphsons Method

    if nargin

  • 8/10/2019 t 5 Open Methods

    26/58

    Pitfalls of The Newton Raphson Method

    Cases where Newton Raphson method diverges or exhibit poor

    convergence.a) Reflection point b) oscillating around a local optimum

    c) Near zero slope , and d) zero slope

  • 8/10/2019 t 5 Open Methods

    27/58

    Example Newton Raphsons Method

    Evaluate 29 to five decimal places by Newton-Raphsons iterative method

  • 8/10/2019 t 5 Open Methods

    28/58

    Solution

    Evaluate 29 to five decimal places by Newton-Raphsons iterative method

  • 8/10/2019 t 5 Open Methods

    29/58

    Solution

  • 8/10/2019 t 5 Open Methods

    30/58

    3. The Secant Method

    The derivative is

    sometimes difficult to evaluateby the computer program. It

    may be replaced by a backward

    finite divided difference

    )()(

    ))((

    i1i

    i1iii1i

    xfxf

    xxxfxx

    Thus, the formula

    predicting thexi+1is:

    / 1

    1

    ( ) ( )( ) i ii

    i i

    f x f xx

    x x

    / ( )i

    x

  • 8/10/2019 t 5 Open Methods

    31/58

    The Secant Method

    Requires two initial estimates of x , e.g, xo, x1.However, because f(x) is not required to change

    signs between estimates, it is not classified as a

    bracketing method.

    The scant method has the same properties asNewtons method. Convergence is not

    guaranteed for all xo, x1,f(x).

  • 8/10/2019 t 5 Open Methods

    32/58

    Secant Method:Example

    Determine a root of the equation sinx + 3 cos x

    2 = 0using the secant method. The initial approximations

    x0 and x1are 0 and 1.5.

  • 8/10/2019 t 5 Open Methods

    33/58

  • 8/10/2019 t 5 Open Methods

    34/58

    Comparison of convergence of False Position and

    Secant Methods

    False Position Secant Method

    Use two estimatexland xu Use two estimatexiand xi-1

    f(x) must changes signs betweenxl

    and xu

    f(x) is not required to change signs

    betweenxiand xi-1

    Xrreplaces whichever of the original

    values yielded a function value with

    the same sign as f(xr)

    Xi+1replace xiXi replace xi-1

    Always converge May be diverge

    Slower convergence than Secant in

    case the secant converges.

    If converges, It does faster then False

    Position

    1

    1

    1

    ( )( )

    ( ) ( )

    i i i

    i i

    i i

    f x x xx x

    f x f x

    ( )( )

    ( ) ( )

    u l u

    r u

    l u

    f x x xx x

    f x f x

  • 8/10/2019 t 5 Open Methods

    35/58

    Comparison of convergence of False Position and

    Secant Methods

    Use the false-position and secant method to find the root off(x)=logex. Start computation with xl=xi-1=0.5, xu=xi= 5.

    1. False position method

    2. Secant methodIter xi-1 xi xi+1

    1 0.5 5.0 1.8546

    2 5 1.8546 -0.10438

    Iter xl xu xr

    1 0.5 5.0 1.8546

    2 0.5 1.8546 1.2163

    3 0.5 1.2163 1.0585

  • 8/10/2019 t 5 Open Methods

    36/58

    Comparison of

    the true percentrelative Errors Et

    for the methods

    to the determine

    the root off(x)=e-x-x

  • 8/10/2019 t 5 Open Methods

    37/58

    Flow ChartSecant Method

    Start

    Input: x-1, x0,s, maxi

    i=0

    a=1.1s

    1

  • 8/10/2019 t 5 Open Methods

    38/58

    Stop

    1

    while

    a>s &

    i < maxi

    Xi+1=0

    Xi-1=xiXi=xi+1

    1

    1100%

    i ia

    i

    x x

    x

    Print:xi, f(xi) ,a, i1

    1

    1

    ( )( )

    ( ) ( )

    1

    i i ii i

    i i

    f x x xx x

    f x f x

    i i

    False

    True

  • 8/10/2019 t 5 Open Methods

    39/58

    Modified Secant Method

    Rather than using two initial values, an alternative

    approach is using a fractional perturbation of the

    independent variable to estimate

    1

    ( )

    ( ) ( )

    i i

    i i

    i i i

    x f xx x

    f x x f x

    is a small perturbation fraction

    / ( ) ( )( ) i i iii

    f x x f xxx

    / ( )i

    f x

  • 8/10/2019 t 5 Open Methods

    40/58

    Modified Secant Method:Example

    Use the modified secant method to find the root of

    f(x) = e-x-x and, x0=1 and =0.01

    0 0

    0 0 0 0

    1 1

    1 1

    1 1 1 1

    2 1

    1 0.63212

    1.01 0.64578

    ( )0.537263

    First Iteration

    Second Iteration

    5.3%( ) ( )

    0.537263 0.047083

    0.542635 0.038579

    ( )

    (

    i ii i t

    i i i

    i ii i

    x f x

    x x f x x

    x f xx x x

    f x x f x

    x f x

    x x f x x

    x f xx x x

    f x

    0.56701 0.0236%

    ) ( ) t

    i i ix f x

  • 8/10/2019 t 5 Open Methods

    41/58

    Multiple Roots

    x

    f(x)= (x-3)(x-1)(x-1)= x3- 5x2+7x -3

    f(x)

    1x

    3

    Doubleroots

    f(x)= (x-3)(x-1)(x-1)(x-1)

    = x4- 6x3+ 125 x2- 10x+3

    f(x)

    1 3

    tripleroots

  • 8/10/2019 t 5 Open Methods

    42/58

    Multiple Roots

    Multiple root corresponds to a pointwhere a function is tangent to the x axis.

    Difficulties- Function does not change sign with double

    (or even number of multiple root), therefore,

    cannot use bracketing methods.

    - Both f(x) and f(x)=0, division by zero withNewtons and Secant methods which maydiverge around this root.

  • 8/10/2019 t 5 Open Methods

    43/58

    4. The Modified Newton Raphson Method by

    Ralston and Rabinowitz

    Another u(x)is introduced such that u(x)=f(x)/f/(x);

    Getting the roots of u(x) using Newton Raphsons

    technique:

    )()()(

    )()(

    )]([

    )()()()(

    )(

    )(

    )(

    //2/

    /

    1

    2/

    /////

    /1

    iii

    iiii

    i

    iiiii

    i

    iii

    xfxfxf

    xfxfxx

    xf

    xfxfxfxf

    xu

    xu

    xuxx

    This function has rootsat all the same locations

    as the original function

  • 8/10/2019 t 5 Open Methods

    44/58

    Modified Newton Raphson Method: Example

    Using the Newton Raphson and Modified Newton

    Raphson evaluate the multiple roots off(x)= x3-5x2+7x-3with an initial guess ofx0=0

    )106)(375()7103(

    )7103)(375(

    )()()()()(

    2322

    223

    //2/

    /

    1

    iiiiii

    iiiiii

    iii

    iiii

    xxxxxx

    xxxxxx

    xfxfxfxfxfxx

    7x10x33x7x5xx

    xfxfxx 2

    i

    i

    2

    i

    3

    ii

    i

    ii1i

    )()(/

    Newton Raphson formula:

    Modified Newton Raphson formula:

    M difi d N t R h M th d E l

  • 8/10/2019 t 5 Open Methods

    45/58

    Newton Raphson Modified Newton-Raphson

    Iter xi t% iter xi t%

    0 0 100 0 0 100

    1 0.4286 57 1 1.10526 11

    2 0.6857 31 2 1.00308 0.31

    3 0.83286 17 3 1.000002 00024

    4 0.91332 8.7

    5 0.95578 4.46 0.97766 2.2

    Newton Raphson technique is linearly converging towards thetrue value of 1.0 while the Modified Newton Raphson is

    quadratically converging.For simple roots, modified Newton Raphson is less efficientand requires more computational effort than the standard

    Newton Raphson method

    Modified Newton Raphson Method: Example

  • 8/10/2019 t 5 Open Methods

    46/58

    Systems of Nonlinear Equations

    Roots of a set of simultaneous equations:

    f1(x1,x2,.,xn)=0

    f2 (x1,x2,.,x

    n)=0

    fn (x1,x2,.,xn)=0

    The solution is a set of x values that

    simultaneously get the equations to zero.

  • 8/10/2019 t 5 Open Methods

    47/58

    Systems of Nonlinear Equations

    Example:x2

    + xy = 10& y + 3xy2

    = 57u(x,y)= x2+ xy -10 = 0

    v(x,y)= y+ 3xy2 -57 = 0

    The solution will be the value of x and y which makesu(x,y)=0and v(x,y)=0

    These arex=2and y=3

    Numerical methods used are extension of the openmethods for solving single equation; Fixed point

    iteration and Newton-Raphson. (we will only discuss

    the Newton Raphson)

  • 8/10/2019 t 5 Open Methods

    48/58

    Systems of Nonlinear Equations:

    2.Newton Raphson Method

  • 8/10/2019 t 5 Open Methods

    49/58

    Systems of Nonlinear Equations:

    2.Newton Raphson Method

  • 8/10/2019 t 5 Open Methods

    50/58

    x 2+ xy =10 and y + 3xy 2 = 57are two nonlinear simultaneous equations with two unknown x and y they canbe expressed in the form: use the point (1.5,3.5) as initial guess.

    2

    2 ,

    3 , 1 6

    u u

    x y xx y

    v vy xy

    x y

    i xi yi Ui Vi ui,x ui,y vi,x vi,ya,x

    a,y

    0 1.5 3.5 -2.5 1.625 6.5 1.5 36.75 32.5

    1 2.03603 2.84388 -.06435 -4.7560 6.91594 2.03603 24.26296 35.74135 26.3 23.1

    2 1.9987 3.00229 1.87 5.27

    Systems of Nonlinear Equations:

    2.Newton Raphson Method

  • 8/10/2019 t 5 Open Methods

    51/58

    i xi yi Ui Vi ui,x ui,y vi,x vi,y a,x a,y

    0 1.5 3.5 -2.5 1.625 6.5 1.5 36.75 32.5

    1 2.03603 2.84388 -.06435 -4.7560 6.91594 2.03603 24.26296 35.74135 26.3 23.1

    2 1.9987 3.00229 1.87 5.27

    Systems of Nonlinear Equations:

    2.Newton Raphson Method

  • 8/10/2019 t 5 Open Methods

    52/58

    Problem

    The polynomial f (x) = x3 -6x2 +11x- 6.1 has a real root

    between 3 and 5. Apply the Newton-Raphsonsmethod to

    this function using an initial guess ofx0= 3.5. Explain your

    results

    Problem

  • 8/10/2019 t 5 Open Methods

    53/58

    Problem

    The polynomial f (x) = x3 -6x2 +11x- 6.1 has a real root

    between 3 and 5. Apply the Newton-Raphsonsmethod to

    this function using an initial guess of x0= 3.5. Explain your

    results

    Problem

  • 8/10/2019 t 5 Open Methods

    54/58

    Problem

    The polynomial f (x) = x3 -6x2 +11x- 6.1 has a real root

    between 3 and 5. Apply the Newton-Raphsonsmethod to

    this function using an initial guess of x0= 3.5. Explain your

    results

    Problem

  • 8/10/2019 t 5 Open Methods

    55/58

    Problem

    The polynomial f (x) = x3 -6x2 +11x- 6.1 has a real root

    between 3 and 5. Apply the Newton-Raphsonsmethod to

    this function using an initial guess of x0= 3.5. Explain your

    results

    Problem

  • 8/10/2019 t 5 Open Methods

    56/58

    Problem

    Find the root of polynomial f (x) = x3 -6x2+11x- 6.1. Apply

    the Secantsmethod to this function using an initial guess

    of x-1= 2.5 and x0= 3.5.

    Problem

  • 8/10/2019 t 5 Open Methods

    57/58

    Problem

    Find the root of polynomial f (x) = x3 -6x2+11x- 6.1. Apply

    the Secantsmethod to this function using an initial guess

    of x-1= 2.5 and x0= 3.5.

    Problem

  • 8/10/2019 t 5 Open Methods

    58/58

    Problem

    Find the root of polynomial f (x) = x3 -6x2+11x- 6.1. Apply

    the Secantsmethod to this function using an initial guess

    of x-1= 2.5 and x0= 3.5.