numerical methods in physics and astrophysics

42
Numerical Methods in Physics and Astrophysics Kostas Kokkotas 2 October 20, 2014 2 http://www.tat.physik.uni-tuebingen.de/kokkotas Kostas Kokkotas 3 Numerical Methods in Physics and Astrophysics

Upload: endless-love

Post on 25-Sep-2015

15 views

Category:

Documents


2 download

DESCRIPTION

Numerical Methods in Physics and Astrophysics

TRANSCRIPT

  • Numerical Methods in Physics and Astrophysics

    Kostas Kokkotas2

    October 20, 2014

    2http://www.tat.physik.uni-tuebingen.de/ kokkotasKostas Kokkotas3 Numerical Methods in Physics and Astrophysics

  • TOPICS

    1. Solving nonlinear equations

    2. Solving linear systems of equations

    3. Interpolation, approximation & curve fitting

    4. Numerical differentiation and numerical integration

    5. Numerical Solution of ODEs

    6. Boundary and Characteristic Value Problems

    7. Mathematical introduction to PDEs

    8. Numerical Solution of PDEs

    9. Finite Elements Methods

    TEXTBOOKS

    1. Applied Numerical Analysis C.F. Gerald & P.O.Wheatley,Addison-Wesley 7th Edition (2004)

    2. Numerical Recipes. The Art of Scientific Computing W.H. Press,S.A.Teukolsky, & W. T. Vetterling, Cambridge University Press(2007)

    Kostas Kokkotas4 Numerical Methods in Physics and Astrophysics

  • Outline II

    1. Solving nonlinear equationsI Bisection methodI Linear interpolationI xn+1 = g(xn)I Newtons method

    2. Solving systems of equationsI Gaussian eliminationI Iterative methodsI Matrix inverseI Eigenvalues & EigenvectorsI Nonlinear systems

    3. Interpolation, approximation & curve fittingI Interpolating polynomialsI Spline CurvesI Rational function approximations

    Kostas Kokkotas5 Numerical Methods in Physics and Astrophysics

  • Outline III

    1. Numerical differentiation and integrationI Numerical differentiationI Trapezoidal ruleI Simpson rulesI Gaussian quadratureI Multiple integrals

    2. Numerical Solution of ODEsI Eulers methodI Runge-Kutta methodsI Adams methodI Prediction-Correction methods

    3. Numerical Solution of PDEsI Elliptic equationsI Parabolic equationsI Hyperbolic equations

    Kostas Kokkotas6 Numerical Methods in Physics and Astrophysics

  • Solving nonlinear equations

    The classical problem is to find a value r such that for a function f (x)where x (a, b)

    f (r) = 0 (1)

    The typical procedure is to find a recurrence relation of the form:

    xn+1 = (xn) (2)

    which will provide a sequence of values x0, x1, . . . , x, . . . and in the limit to lead in a root of equation (1).For every method we need to answer the following questions:

    I Under what condition a method will converge

    I If it converges, then how fast

    I What is the best choice for the initial guess x0.

    Kostas Kokkotas7 Numerical Methods in Physics and Astrophysics

  • Bisection method I (Bolzano)

    Lets assume that we are looking for the roots of the following equation:

    f (x) = 2 sin(x) x2 ex = 0 (3)

    then x1 = 0 and x2 = 1 which give f (0) = 1 and f (1) = 0.31506

    I x3 = (x0 + x1)/2 = 0.5 f (0.5) = 0.1023I x4 = (x0 + x3)/2 = 0.25 f (0.25) = 0.1732I x5 = (x4 + x3)/2 = 0.375 f (0.375) = 0.0954I x6 = (x5 + x3)/2 = 0.4375 f (0.4375) = 0.0103I x7 = (x5 + x6)/2 = 0.40625

    f (0.40625) = 0.0408I ...

    I xn = r1 0.4310378790the other root is r2 = 1.279762546.

    Kostas Kokkotas8 Numerical Methods in Physics and Astrophysics

  • Bisection method II

    If there exists a root in the interval [a0, b0], then f (a0) f (b0) < 0. If0 = (a0 + b0)/2, then:

    I (I) either f (0) f (a0) < 0I (II) either f (0) f (b0) < 0I (III) either f (0) = 0 .

    If (III), then the root has been found orelse we set a new interval

    [a1, b1] =

    [0, b0] if (II )[a0, 0] if (I )

    (4)

    Kostas Kokkotas9 Numerical Methods in Physics and Astrophysics

  • Bisection method III

    REPEATSET x3 = (x1 + x2)/2IF f (x3) f (x1) < 0

    SET x2 = x3ELSE

    SET x1 = x3ENDIF

    UNTIL (|x1 x2| < E ) OR f (x3) = 0

    Table: Procedure to find the root of a nonlinear equations using bisectionmethod

    Kostas Kokkotas10 Numerical Methods in Physics and Astrophysics

  • Bisection method IV

    CRITISISM

    I Slow convergence

    I Problem with discontinuities

    ERROR : The error defined as: n = |r xn|. For this method

    n 12|an bn| (5)

    and in every step the error is half of the previous step

    n+1 =n2

    =n1

    22= = 0

    2n+1(6)

    and if we demand an error E we can calculate the number of stepsneeded:

    n = log20E

    (7)

    Kostas Kokkotas11 Numerical Methods in Physics and Astrophysics

  • Linear interpolation

    Assume that the function is linear in the interval (x1, x2) where f (x1) andf (x2) are of opposite sign. Then there will be a straight line connectingthe points (x1, f (x1)) and (x2, f (x2)) described by the equation:

    y (x) = f (x1) +f (x1) f (x2)

    x1 x2 (x x1) (8)

    which crosses the axis Ox let say in a point x3 which will be given by thefollowing relation

    x3 =x2f (x1) x1f (x2)f (x1) f (x2) = x2

    f (x2)

    f (x2) f (x1) (x2 x1) (9)

    That is we substitute the actual function with a straight line and weassume that the point where this lines crosses the axis Ox is a firstapproximation to the root of the equation.

    This new point x3 will be used to find a better approximation to the

    actual root r .

    Kostas Kokkotas12 Numerical Methods in Physics and Astrophysics

  • Linear interpolation

    A possible choice of the new points:

    I (I) If f (x1) f (x3) < 0 x2 = x3I (II) If f (x2) f (x3) < 0 x1 = x3I (III) If f (x3) = 0

    Recurrence relation:

    xn+2 = xn+1 f (xn+1)f (xn+1) f (xn) (xn+1 xn) .

    (10)

    Kostas Kokkotas13 Numerical Methods in Physics and Astrophysics

  • Linear interpolation : 1st algorithm

    Assume that the root is in the interval (x1, x2)REPEAT

    SET x3 = x2 f (x2) x2x1f (x2)f (x1)IF f (x3) f (x1) < 0

    SET x2 = x3ELSE

    SET x1 = x3ENDIF

    UNTIL |f (x3)| < E

    PROBLEM: Examine after how many iterations you will find the root of

    equation (3) with an error of the order of E 106.

    Kostas Kokkotas14 Numerical Methods in Physics and Astrophysics

  • Linear interpolation : 2nd algorithm

    The root is not included in the initial choice of the interval (x1, x2)REPEAT

    SET x3 = x2 f (x2) x2x1f (x2)f (x1)IF |f (x1)| < |f (x2) |

    SET x2 = x3ELSE

    SET x1 = x3ENDIF

    UNTIL |f (x3)| < E

    Kostas Kokkotas15 Numerical Methods in Physics and Astrophysics

  • Linear interpolation : Convergence

    If r is a root of the equation f (x) = 0 and n = |r xn| is the error forx = xn, the the convergence of the method of linear interpolation is

    n+1 = k 1.618n (11)

    PROOF : If we assume that xn = r + n and

    f (xn) = f (r + n) = f (r) + nf (r) +

    2n2f (r) (12)

    then the relation

    xn+2 = xn+1 f (xn+1)f (xn+1) f (xn) (xn+1 xn) (13)

    becomes

    r+n+2 = r+n+1n+1f

    (r) + 2n+1f (r)/2

    f (r) (n+1 n) + 12 f (r)(2n+1 2n

    ) (n+1 n)Kostas Kokkotas16 Numerical Methods in Physics and Astrophysics

  • which leads to:

    n+2 = n+1

    [1

    (1 n

    2

    f (r)f (r)

    )]= n+1n

    f (r)2f (r)

    but we are aiming for a relation of the form n+1 = k mnn+1 = k mnn+2 = k mn+1

    } k mn+1 = n+1n

    (f (r)2f (r)

    )

    n+1 =

    (1

    k

    ) 1m1

    1

    m1n A

    1m1 where A =

    f (r)2f (r)

    (14)

    k mn =(A

    k

    ) 1m1

    1

    m1n

    k =

    (Ak

    )1/(m1)m = 1m1 m2 m 1 = 0

    m =15

    2= 1.618 and km = A =

    f (r)2f (r)

    n+1 = k 1.618n (15)

    Kostas Kokkotas17 Numerical Methods in Physics and Astrophysics

  • Method xn+1 = g(xn)

    Write the nonlinear equation in a form xn+1 = g (xn) such aslimn xn = r (n = 1, 2, 3, . . . )

    Kostas Kokkotas18 Numerical Methods in Physics and Astrophysics

  • THEOREM: If g(x) and g (x) are continuous on an interval about aroot r of the equation x = g(x), and if |g (x)| < 1 for all x in theinterval, then the recurrence xn+1 = g(xn) (n = 1, 2, 3, . . . ) will convergeto the root x = r , provided that x1 is chosen in the interval.

    Note that this is a sufficient condition only, since for some equationsconvergence is secured even though not all the conditions hold. In a computer program it is worthwhile to determine whether|x3 x2| < |x2 x1|

    ERROR After n steps the error will be n = r xnn+1 = r xn+1 = g (r) g(xn) = g (r)(r xn) = g (r) n

    I.e. linear convergence.The rate of convergence is rapid if |g (x)| is small in the interval. If thederivative is negative the errors alternate in sign giving oscillatoryconvergence.

    Kostas Kokkotas19 Numerical Methods in Physics and Astrophysics

  • Method xn+1 = g(xn) : Example

    Find the root of equation f (x) = x + ln(x) in the interval [0.1, 1].

    We will try various forms of rewriting the equation:

    I xn+1 = ln(xn) but |g (x)| = 1x

    1 on [0.1, 1] : no convergence.I xn+1 = exn then |g (x)| = |ex | e0.1 0.9 < 1 : convergence.I another writing : xn+1 = (xn + exn)/2 then|g (x)| = 12 |1 ex | 12 |1 e1| = 0.316 : better convergence.

    I finally xn+1 = xn+2exn

    3 thus|g (x)| = 13 |1 2ex | 13 |1 2e1| = 0.03 : even betterconvergence.

    Thus the obvious choice is:

    xn+1 =xn + 2e

    xn

    3.

    Kostas Kokkotas20 Numerical Methods in Physics and Astrophysics

  • Aitkens improvement

    If a method is converging linearly (e.g. n+1 = g(r)n) then it can be

    improved to produce even more accurate results without extraiterations.The error the method xn+1 = g

    (xn) after n iterations is:

    r xn+1 g (r)(r xn)after n + 1 is:

    r xn+2 g (r)(r xn+1)and by division we get

    r xn+1r xn+2 =

    g (r)(r xn)g (r)(r xn+1)

    Then by solving for r we get:

    r = xn (xn xn1)2

    xn 2xn1 + xn2 (16)

    This relation improves considerably the accuracy of the final result.

    Kostas Kokkotas21 Numerical Methods in Physics and Astrophysics

  • Newtons method

    If near the root r of an equation f (x) = 0 the 1st and 2nd derivatives off (x) are continuous we can develop root finding techniques whichconverge faster than any method presented till now.

    Lets assume that after n iterations we reached avalue xn+1 which is the root of the equation and xn isa nearby value such as: xn+1 = xn + n. Then:

    f (xn+1) = f (xn + n)

    = f (xn) + nf (xn) +

    2n2f (xn) +

    but since f (xn+1) = 0 0 = f (xn) + nf (xn) i.e.

    n = f (xn)f (xn)

    xn+1 = xn f (xn)f (xn)

    (17)

    Kostas Kokkotas22 Numerical Methods in Physics and Astrophysics

  • Newtons method : Convergence

    If r is a root of f (x) = 0. Then xn = r + n and xn+1 = r + n+1, thus:

    r + n+1 = r + n f (r + n)f (r + n)

    = r + n f (r) + nf

    (r) + 122nf (r)

    f (r) + nf (r)

    but since f (r) = 0 and

    1

    1 + f (r)/f (r) 1 n f

    (r)f (r)

    we get the following relation:

    n+1 = f (r)

    2f (r) 2n (18)

    Notice that the convergence of the method is quadratic

    Kostas Kokkotas23 Numerical Methods in Physics and Astrophysics

  • Newtons method : Convergence II

    An alternative way for studying the convergence of Newtons method(17) is based on the method xn+1 = g(xn) i.e. successive iterations willconverge if |g (x)| < 1 . Here:

    g(x) = x f (x)f (x)

    g (x) = f (x)f(x)

    [f (x)]2(19)

    since n = xn r = g(xn) g(r) we get

    g(xn) = g(r + n) = g(r) + g(r)n +

    g ()2

    2n (20)

    = g(r) +g ()

    22n , [r , xn] (21)

    This leads to:

    g(xn) g(r) = g()2

    2n xn+1 r n+1 =g ()

    22n (22)

    Kostas Kokkotas24 Numerical Methods in Physics and Astrophysics

  • Newtons method : Algorithm

    COMPUTE f (x1), f(x1)

    SET x2 = x1IF (f (x1) 6= 0) END (f (x1) 6= 0)

    REPEATSET x2 = x1SET x1 = x1 f (x1)/f (x1)

    UNTIL (|x1 x2| < E ) OR (|f (x2)| < E )ENDIF

    EXAMPLE : Find the square root of a number a.

    f (x) = x2 a and f (x) = 2x

    Then

    xn+1 = xn x2n a2xn

    or in a better form xn+1 =1

    2

    (xn +

    a

    xn

    ). (23)

    Kostas Kokkotas25 Numerical Methods in Physics and Astrophysics

  • Newtons method : Halley

    Remember that n = xn+1 xn, then

    f (xn+1) = f (xn + n) = f (xn) + nf (xn) +

    2n2f (xn) + . . .

    f (xn) + n[f (xn) +

    n2f (xn)

    ]= 0

    n = f (xn)f (xn) + n2 f

    (xn)

    from the 1st order result we substitute

    n f (xn)f (xn)

    xn+1 = xn f (xn)f (xn) f (xn)f (xn)2f (xn)

    = xn 2f (xn) f (xn)

    2f 2 (xn) f (xn) f (xn) (24)

    obviously for f (xn) 0 we get the Newton-Raphson method.Kostas Kokkotas26 Numerical Methods in Physics and Astrophysics

  • Newtons method : Halley -Convergence

    Halleys methods achieves cubic convergence:

    n+1 = [

    1

    6

    f ()f ()

    14

    (f ()f ()

    )2] 3n (25)

    EXAMPLE: The square root of a number Q (here Q = 9) with Halleysmethod is given by (compare with eq. (23):

    xn+1 =x3n + 3xnQ

    3x2n + Q(26)

    Newton Error Halley Errorx0=15 0 = 12 x0=15 0 = 12x1=7.8 1 = 4.8 x1=5.526 1 = 2.5x2=4.477 2 = 1.477 x2=3.16024 2 = 0.16x3=3.2436 3 = 0.243 x3=3.00011 3 = 1.05 104x4=3.0092 4 = 9.15103 x4=3.0000000... 4 = 3.24 1014

    Kostas Kokkotas27 Numerical Methods in Physics and Astrophysics

  • Newtons method : Multipole roots

    If f (x) = (x r)mq(x) where m is the multiplicity of root r thenf (x) = (x r)m1 [mq(x) + (x r)q(x)]

    i.e. both f (r) = 0 and f (r) = 0. Thus the ratio [f (x)/f (x)]xr willdiverge.To avoid the problem we construct a new function

    (x) =f (x)

    f (x)=

    (x r)q(x)mq(x) + (x r)q(x)

    which obviously has r as root with multiplicity m = 1 and the recurrencerelation is:

    xn+1 = xn (xn)(xn)

    = xn f (xn)/f(xn)

    {[f (xn)]2 f (xn)f (xn)} /[f (xn)]2

    = xn f (xn) f(xn)

    [f (xn)]2 f (xn)f (xn) (27)

    The convergence is quadratic since we applied Newton-Raphson method

    for for finding the roots of (x) = 0 for which r is a simple root.

    Kostas Kokkotas28 Numerical Methods in Physics and Astrophysics

  • Newtons method : Multipole roots

    Find the multipole root of f (x) = x4 4x2 + 4 = 0(r =

    2 = 1.414213...).

    Standard Newton-Raphson

    xn+1 = xn x2n 24xn

    (A)

    Modified Newton-Raphson

    xn+1 = xn (x2n 2)xnx2n + 2

    (B).

    x (A) Error (A) (B) Error (B)x0 1.5 8.6102 1.5 8.6102x1 1.458333333 4.4102 1.411764706 -2.4103x2 1.436607143 2.2102 1.414211439 -2.1106x3 1.425497619 1.1102 1.414213562 -1.61012

    Kostas Kokkotas29 Numerical Methods in Physics and Astrophysics

  • Convergence tests

    We will compare the convergence rate of a method with linear and onewith quadratic convergence (Bisection and Newton)For linear convergence we have::

    limn

    |n+1||n| = a |n| a|n1| a

    2|n2| ... an|0|

    then by solving the above equation for n we come to a relation whichgives the number of iterations, n, needed to achieve a given accuracy |n|:

    n log10 |n| log10 |0|log10 |a|

    (28)

    In the same way for quadratic convergence we get:

    limn

    |n+1||n|2 = b |n| b|n1|

    2 b3|n2|4 ... b2n+11|0|2n+1

    Kostas Kokkotas30 Numerical Methods in Physics and Astrophysics

  • and by solving the above relation for n in order to achieve a givenaccuracy |n| we get:

    2n+1 log10 |n|+ log10 |b|log10 |0|+ log10 |b|

    (29)

    If for a given problem we ask that the error after n iterations to besmaller than 106 i.e. n 106 with an initial error 0 = 0.5 and fora = b = 0.7 the relation (28) gives:

    n log10 |106| log10 |0.5|

    log10 |0.7| 37 iterations

    The same assumptions for quadratic convergence will give:

    2n+1 log10 |106|+ log10 |0.7|

    log10 |0.5|+ log10 |0.7| 13.5

    i.e. the number of iterations is only 3!The difference becomes more pronounce if we demand even higheraccuracy e.g. n 1014 then bisection will need 89 iterations whileNewtons method will need only 4!

    Kostas Kokkotas31 Numerical Methods in Physics and Astrophysics

  • Non-linear systems of equations

    We will present two methods based on the techniques of the previoussection in solving systems of non-linear equations. The two methods arebased on Newtons method and in the xn+1 = g(xn) method.

    An example of two non-linear equations isthe following:

    f (x , y) = ex 3y 1(30)

    g(x , y) = x2 + y2 4

    it is obvious that f (x , y) = 0 andg(x , y) = 0 are two curves on the xy planeas in the Figure on the right.

    Kostas Kokkotas32 Numerical Methods in Physics and Astrophysics

  • Newtons method for 2 equations

    We will develop the method for a system of two non-linear equationswhile the extension to n nonlinear equations will become obvious.Lets assume:

    f (x , y) = 0 , g (x , y) = 0

    Lets assume that after n + 1 iteration the method converged to thesolution (xn+1, yn+1) i.e. f (xn+1, yn+1) 0 and g(xn+1, yn+1) 0. Thenby assuming that xn+1 = xn + n and yn+1 = yn + n we can Taylorexpand around the solution i.e.

    0 f (xn+1, yn+1) = f (xn+n, yn+n) f (xn, yn)+n(f

    x

    )n

    +n

    (f

    y

    )n

    0 g(xn+1, yn+1) = g(xn+n, yn+n) g(xn, yn)+n(g

    x

    )n

    +n

    (g

    y

    )n

    Kostas Kokkotas33 Numerical Methods in Physics and Astrophysics

  • And by solving the system with respect to n and n we get :

    n =f gy + g fyfx

    gy gx fy

    and n =g fx + f gxfx

    gy gx fy

    (31)

    Since xn+1 = xn + n and yn+1 = yn + n we come to the following pair ofrecurrence relations, which are generalizations of Newtons method:

    xn+1 = xn (

    f gy g fyfx gy gx fy

    )n

    (32)

    yn+1 = yn (

    g fx f gxfx gy gx fy

    )n

    (33)

    Kostas Kokkotas34 Numerical Methods in Physics and Astrophysics

  • Newtons method n non-linear equations

    If we assume the following system of N equations

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

    ......fn(x

    1, x2, ..., xN) = 0

    with N unknowns (x1, x2, ..., xN). Then by considering a solution of thesystem (x1n+1, x

    2n+1, ..., x

    Nn+1) for which we assume the following relations

    x1n+1 = x1n + x

    1n

    ......

    xNn+1 = xNn + x

    Nn

    Kostas Kokkotas35 Numerical Methods in Physics and Astrophysics

  • We can create expansion of the form:

    0 = f1(x1n+1, ..., xNn+1) = f1(x1n + x1n , ..., xNn + xNn ) f1 + f1

    x1x1n + ...+

    f1xN

    xNn

    ...... (34)

    0 = fN(x1n+1, ..., xNn+1) = fN(x1n + x1n , ..., xNn + xNn ) fN + fN

    x1x1n + ...+

    fNxN

    xNn

    Then the quantities x in will be found as solutions of the linear systemf1x1

    f1x2 f1xN

    ......

    fNx1

    fNx2 fNxN

    x1n

    ...

    xNn

    =

    f1

    ...

    fN

    (35)

    Kostas Kokkotas36 Numerical Methods in Physics and Astrophysics

  • Thus if we start with N initial values (x10 , x20 , ..., x

    N0 ) then from the

    solution of the above system we will calculate the quantities x in whichlead to the new values (x11 , x

    21 , ..., x

    N1 ) via the relations:

    x11 = x10 + x

    10

    ...... (36)

    xN1 = xN0 + x

    N0

    This procedure will be repeated till the a given accuracy is reached i.e.

    max |x in| < E .

    Kostas Kokkotas37 Numerical Methods in Physics and Astrophysics

  • Methods of type x = g(x)

    Lets assume the system on N nonlinear equations:

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

    ...... (37)

    fN (x1, x2, . . . , xN) = 0

    The system can be rewritten in the form:

    x1 = F1 (x1, x2, . . . , xN)

    ...... (38)

    xN = FN (x1, x2, . . . , xN)

    A SIMPLE CHOICE: Give some N initial values (x1, . . . , xN)0 in theright hand side of the equations and find a set on N new values(x1, . . . , xN)1. Repeat the procedure till you reach a solution with a givenaccuracy.

    Kostas Kokkotas38 Numerical Methods in Physics and Astrophysics

  • AN IMPROVED APPROACH: Give some N initial values(x1, . . . , xN)0 in the right hand side of the 1st of the equations (38) andfind a new value (x1)1.Then in the right hand side of the 2nd equations apply the following setof guess values (x1)1, (x2, . . . , xN)0 and estimate (x2)1. Continue in thethird equation by applying the improved set of values : (x1, x2)1,(x3, . . . , xN)0 and so on.

    CONVERGENCE: The system xi = Fi (x1, x2, . . . , xN) with i = 1, . . . ,Nwill converge to a solution, if near this solution the following criterion issatisfied: F1x1

    + F1x2+ + F1xN

    < 1...... (39)FNx1

    + FNx2+ + FNxN

    < 1

    Kostas Kokkotas39 Numerical Methods in Physics and Astrophysics

  • Methods of type x = g(x) : EXAMPLE

    The non-linear system of equations

    x2 + y2 = 4 and ex 3y = 1

    with exact solutions (1.5595,1.2522) and (-1.9793,-0.2873) can bewritten in the form:

    xn+1 =

    4 y2n and yn+1 =1

    3(exn 1)

    for an initial choice (1, 0), we create the following sequence of solutionsn 0 1 2 3 4 5x -1 -2 -1.9884 -1.9791 -1.9792 -1.9793y 0 -0.2107 -0.2882 -0.2877 -0.2873 -0.2873

    which after 5 iterations approaches the exact solution.

    Kostas Kokkotas40 Numerical Methods in Physics and Astrophysics

  • If we use the 2nd method then the results are:

    n 0 1 2 3x -1 -2 -1.9791 -1.9793y 0 -0.2882 -0.2873 -0.2873

    i.e. the same accuracy has been achieved with only 3 iterations.In order to find the 2nd solution of the system we modify the recurrencerelations as follows:

    xn+1 =

    4 y2n and yn+1 =1

    3(exn 1)

    If we start with values close to the exact solution e.g. x0 = 1.5 andy0 = 1 the results are :

    n 0 1 2 3 4 5x 1.5 1.7321 1.2630 1.8126 1.0394 1.9050y 1 1.5507 0.8453 1.7087 0.6092 1.9064

    we notice that we diverge from the solution and the reason is that the

    criteria for convergence set earlier are not satisfied.

    Kostas Kokkotas41 Numerical Methods in Physics and Astrophysics

  • While if we write the recurrence relation in the form

    yn+1 =

    4 x2nxn+1 = ln(1 + 3yn)

    after some iterations we will find the 2nd solution.

    Kostas Kokkotas42 Numerical Methods in Physics and Astrophysics

  • Selected problems I

    1. Find the eigenvalues of the differential equation y + 2y = 0with the following boundary conditions y(0) = 0 and y(1) = y (1).

    2. Find the inverse of a number without using division

    3. If a is a given number find the value of 1/a.

    4. Find the root of equation ex sin(x) = 0 (r = 3.183063012). Ifthe initial interval is [4,3] estimate the number of iterationneeded to reach an accuracy of 4 digits i.e. |xn r | < 0.00005.

    5. Repeat the previous estimation for using the methods of linearinterpolation and Newton.

    6. Solve the following system of equations using both methods andestimate the rate of convergence:

    ex y = 0 and xy ex = 0

    Kostas Kokkotas43 Numerical Methods in Physics and Astrophysics

  • 1. Consider the nonlinear system of equations

    f1(x , y) = x2 + y2 2 = 0, and f2(x , y) = xy 1 = 0 .

    It is obvious that the solutions are (1, 1) and (1,1), examine thedifficulties that might arise if we try to use Newtons method to findthe solution.

    Kostas Kokkotas44 Numerical Methods in Physics and Astrophysics