Lecutre 7 Student

download Lecutre 7 Student

of 31

description

matlab course

Transcript of Lecutre 7 Student

  • CE 6011

    Non linear equations

    in MATLAB

    Lecture 7

    Riddhi Singh

    Email: [email protected]

    1

  • Todays outline

    Non-linear equations

    System of non-linear equations

    2

  • NON-LINEAR EQUATIONS

    3

  • A non-linear system does not follow the rules of a

    linear system: additivity and homogeneity

    4

    An equation, f(x)=K, is linear if it satisfies the principles above,

    nonlinear otherwise

    additivity : ( ) ( ) ( )

    homogeneity : _______________________

    superposition : _______________________

    f x y f x f y

  • 5xf(

    x)

    x

    g(x)

    Nonlinear systemLinear system

  • Examples of non linear equations

    6

    2

    1/3

    2

    ( ) 1

    ( ) sin( )

    ( ) 1

    ( ) log( ) 2

    ....

    f x x x

    f x x

    f x x

    f x x

  • Non linear equations can have one or more than

    one (system of equations) unknowns

    7

    In case of more than one unknown, the solutions is a _______

    2( ) 1

    ( ) sin( )

    f x x x

    f x x

    1. ______ unknown solution is a ___________________

    2. ______________ unknown: _______________________

    2

    1 1 2

    2 1 2

    ( ) 1

    ( ) sin( ) cos(x )

    f x x x

    f x x

  • We need to find the value of x at which:

    8

    ( ) f x

    1. One unknown solution is a scalar

    2. More than one unknown: system of non-linear equations

    ( ) if x

    Also termed, ___________

  • Case I. Single unknown: All method are iterative

    9

    1. _____________ identification

    2. _____________ method

    3. _____________ method

    4. _____________ method

    5. _____________ method

    Case II. Multiple unknowns in a system of non-

    linear equations

  • 10

    Each method uses more information about f(x)

    than the previous one

    Interval identification

    Bisection

    False position

    Newton-Raphson

    Secant

    Signs of f(x)

    Signs of f(x)

    Signs and values of f(x)

    Values of f(x) and its

    derivatives

    Values of f(x), computes

    derivatives using f(x)

    Method Information used

    Incr

    eas

    ing

    com

    ple

    xity

  • NON-LINEAR EQUATIONS

    WITH ONE UNKNOWN

    11

  • MATLAB has inbuilt solvers to solve any type of

    equation. The key command is solve

    12

    %define an unknown

    >> syms x;

    %solve a nonlinear equations in x

    >>solve(x^3-3*x+1)

    %get the output in numbers

    >>eval(solve(x^3-3*x+1))

    %define a system of equations:

    >> syms x1 x2 x3

    >> S = solve('x1+x2+x3=3','x1^2+x2^2+x3^2=5','exp(x1)+x1*x2-x1*x3=1')

    >> Sx1 = S.x1;

    >> Sx2 = S.x2;

    >> Sx3 = S.x3;

  • Method I. Interval identification is based on the

    Intermediate value theorem

    13

    If a function f is continuous on the closed interval [a,b], and if f(a)yf(b)

    or f(b)yf(a), then there exists a point c such that acb and f(c)=y

    If a root of f(x) lies in the interval [a,b],

    then at some point r,

    f(r) =_____. Therefore, f(a)and f(b) are

    of ____________ signs, or

    xf(

    x)

    a br0

    ( ) 0 ( )

    f a f b

  • Method I. Interval identification algorithm*

    14

    1. Start with a guess (eg. xo=0) and interval width x2. Let x1=xo and x2=xo + x3. While f(x1)*f(x2)>0

    new x1 = x2new x2 = x1 + x

    4. Root lies in the interval [x1,x2]

    *Limitations:

    1. Cannot detect double roots

    2. Cannot detect closely spaced roots if the chosen interval

    is too large

  • Method 2. Bisection method is an extension of

    the interval identification method

    15

    Repeat the interval identification method for successively small intervals

    If a root of f(x) lies in the interval

    [a,b], then construct a new interval,

    c=(a+b)/2. Reevaluate:

    xf(

    x)

    a br0

    c

    c

    ( )* ( ),

    ( )* ( )

    f a f c and

    f b f c

  • Method 2. Bisection method algorithm*

    16

    1. If the root lies in the interval [x1,x2]2. While error>tolerable error

    c=(x1+x2)/2 error = (x2-x1)/2If f(x1)*f(c)>0

    x1=cElse

    x2=c

    *Limitations:

    1. Slow convergence than other methods that use more

    information

  • Method 3. False position is an extension of the

    interval identification method

    17

    Instead of using the mid-point, this method uses the point where the secant

    between f(a) and f(b) intersects the x-axis

    The triangles formed by the secant

    are similar, therefore:

    xf(

    x)

    a b0

    ( ) ( )

    b c c a

    f b f a

    a, f(a)

    b, f(b)

    c

  • Method 3. False position algorithm (faster than

    bisection)

    18

    1. If the root lies in the interval [x1,x2]2. While error>tolerable error

    c=

    If f(x1)*f(c)>0x1=c

    Elsex2=c

    ( ) ( )

    ( ) ( )

    af b bf a

    f b f a

    *Limitations:

    1. May select the same endpoint- in that case will converge

    slowly

  • Method 4. Newton-Raphson approximates the

    curve with a tangent

    19

    This method assumes that the function f is differentiable.

    The curve at xo is approximated

    using:

    xy

    01

    ( ) ( )( ) ( )

    o o o

    o

    l x f x x x f x

    x x

    tangent

    y=f(x)

    xox1r

  • Method 4. Newton-Raphson algorithm

    20

    1. Assume an initial estimate of the root, xo2. fx=f(xo), fp=f(xo)3. While precision>prescribed_precision

    x=x- fx/fpfx= f(x)fp=f(x)precision= abs(fx/fp);

    *Limitations:

    1. Sensitive to the nature of the function may get trapped

    if the tangent to the curve is parallel to the x-axis

    2. Detects a multiple root (root of the function is also a

    root of its derivative) only with linear convergence

  • Method 5. Secant method approximates the

    derivative instead of estimating them analytically

    21

    This method is the same as Newton-Raphson except that the derivatives

    are approximated

    The derivative at xo is approximated

    as:

    xy

    0

    0

    1

    1

    1

    ( ) ( )( ) lim

    ( ) ( )( )

    ____________ ( )

    oh

    n nn

    n n

    n n n

    f x h f xf x

    h

    f x f xf x

    x x

    x x f x

    secant

    y=f(x)

    xn-1xn+1r xn

  • Method 5. Secant method algorithm

    22

    1. Assume two intial intervals in which the root will lie, x1 and x22. fx1=f(x1), fx2=f(x2)3. While precision>prescribed_precision

    x1 = x2fx1 = fx2fp = (fx2-fx1)/(x2-x1)x2 = x2-fx2/fpprecision = fx2/fp

    *Limitations:

    1. Slower than Newton-Raphson (although faster than bisection)

    2. Can diverge instead of converging

  • SYSTEM OF NONLINEAR

    EQUATIONS

    23

  • Goal: to identify the vector, x such that:

    24

    1 1 2

    2 1 2

    1 2

    ( , ,..., ) 0

    ( , ,..., ) 0

    .

    .

    .

    ( , ,..., ) 0

    n

    n

    n n

    f x x x

    f x x x

    f x x x

    Matrix notation:

    ( ) 0F X

  • The ___________ : derivatives for vectors

    25

    In case of an unknown vector, the derivative of the function can be

    estimated w.r.t each component of the vector

    Then, the derivative of a function, f, w.r.t the vector

    X is given by the ________ vector:

    1 2[ , ,..., ]nx x xX

    Suppose, vector X is defined as:

    1 1 1

    1 2

    ,...,n

    F F FJ

    x x x

  • The Jacobian for a system of equations is:

    26

    1 1 2

    2 1 2

    1 2

    ( , ,..., ) 0

    ( , ,..., ) 0

    .

    .

    .

    ( , ,..., ) 0

    n

    n

    n n

    f x x x

    f x x x

    f x x x

    System Jacobian matrix

    1 1

    1

    2 2

    1

    1

    . . .

    . . .

    . .

    . .

    . .

    . . .

    n

    n

    n n

    n

    f f

    x x

    f f

    x x

    J

    f f

    x x

  • Newton-Raphson is extended to nonlinear

    systems by using the matrix notation*:

    27

    1 1

    1 1

    1 1

    1

    [ '( )] ( )

    [ ] ( )

    ( ) [ ] ( )

    ( ) ( )

    ( )

    k k k k

    k k k k

    k k k k

    k k k k

    k k k

    J

    J

    J

    J H

    X X F X F X

    X X F X

    X X F X

    X X F X

    F X

    Solving the Jacobian linear systems yields the value of the

    vector for the next time step

    *Derivation is based on _____________ expansion.

  • Example: Solve the following linear system using

    Newton-Raphson

    28

    2 2 2

    3

    5

    1x

    x y z

    x y z

    e xy xz

  • Step 1. Find the Jacobian (analytically)

    29

    ? ? ?

    ? ? ?

    ? ? ?

    J

  • Step 2. Implement Newton-Raphson for vectors

    30

    1. Assume an initial estimate of the root vector x=[xo, x1,, xn]

    2. While precision>required_precisionEstimate, F=f(x)Estimate, J=Jacobian(x)Solve: JH=-F X = X+Hprecision= norm(H);

    In the same manner, the secant method can be extended to a

    system of non-linear equations

  • 31

    Convergence of these methods generally depends on

    the required precision and initial guesses

    Interval identification

    Bisection

    False position

    Newton-Raphson

    Secant

    ---

    Method Convergence formula

    Incr

    eas

    ing

    com

    ple

    xity

    log( ) log(2 )

    log 2

    b an

    2

    1

    ( )1

    2 ( )

    nn n

    n

    fe e

    f x

    1 1

    1 ( )

    2 ( )n n n

    f re e e

    f r

    ---

    Linear

    Linear

    Quadratic

    Convergence type

    Super linear

    1

    1

    ( ) ( )

    2 ( ) ( )( )

    nn

    n n

    a r f re

    f r f r e a r