You are on page 1of 42

Numerical Methods in Physics and Astrophysics

Kostas Kokkotas2

October 20, 2014

http://www.tat.physik.uni-tuebingen.de/ kokkotas
Kostas 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 equations
I
I
I
I

Bisection method
Linear interpolation
xn+1 = g (xn )
Newtons method

2. Solving systems of equations


I
I
I
I
I

Gaussian elimination
Iterative methods
Matrix inverse
Eigenvalues & Eigenvectors
Nonlinear systems

3. Interpolation, approximation & curve fitting


I
I
I

Interpolating polynomials
Spline Curves
Rational function approximations
Kostas Kokkotas5

Numerical Methods in Physics and Astrophysics

Outline III
1. Numerical differentiation and integration
I
I
I
I
I

Numerical differentiation
Trapezoidal rule
Simpson rules
Gaussian quadrature
Multiple integrals

2. Numerical Solution of ODEs


I
I
I
I

Eulers method
Runge-Kutta methods
Adams method
Prediction-Correction methods

3. Numerical Solution of PDEs


I
I
I

Elliptic equations
Parabolic equations
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

If it converges, then how fast

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) x 2 e x = 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.1023

x4 = (x0 + x3 )/2 = 0.25 f (0.25) = 0.1732

x5 = (x4 + x3 )/2 = 0.375 f (0.375) = 0.0954

x6 = (x5 + x3 )/2 = 0.4375 f (0.4375) = 0.0103

x7 = (x5 + x6 )/2 = 0.40625


f (0.40625) = 0.0408

...

xn = r1 0.4310378790

the 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. If
0 = (a0 + b0 )/2, then:
I

(I) either f (0 ) f (a0 ) < 0

(II) either f (0 ) f (b0 ) < 0

(III) either f (0 ) = 0 .

If (III), then the root has been found or


else we set a new interval

[0 , b0 ] if (II )
[a1 , b1 ] =
(4)

[a0 , 0 ] if (I )

Kostas Kokkotas9

Numerical Methods in Physics and Astrophysics

Bisection method III

REPEAT
SET x3 = (x1 + x2 )/2
IF f (x3 ) f (x1 ) < 0
SET x2 = x3
ELSE
SET x1 = x3
ENDIF
UNTIL (|x1 x2 | < E ) OR f (x3 ) = 0
Table: Procedure to find the root of a nonlinear equations using bisection
method

Kostas Kokkotas10

Numerical Methods in Physics and Astrophysics

Bisection method IV
CRITISISM
I

Slow convergence

Problem with discontinuities

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


n

1
|an bn |
2

(5)

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


n+1 =

n
n1
0
= 2 = = n+1
2
2
2

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


needed:
0
n = log2
E
Kostas Kokkotas11

Numerical Methods in Physics and Astrophysics

(6)

(7)

Linear interpolation
Assume that the function is linear in the interval (x1 , x2 ) where f (x1 ) and
f (x2 ) are of opposite sign. Then there will be a straight line connecting
the points (x1 , f (x1 )) and (x2 , f (x2 )) described by the equation:
y (x) = f (x1 ) +

f (x1 ) f (x2 )
(x x1 )
x1 x2

(8)

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

x2 f (x1 ) x1 f (x2 )
f (x2 )
= x2
(x2 x1 )
f (x1 ) f (x2 )
f (x2 ) f (x1 )

That is we substitute the actual function with a straight line and we


assume that the point where this lines crosses the axis Ox is a first
approximation 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

(9)

Linear interpolation
A possible choice of the new points:
I

(I) If f (x1 ) f (x3 ) < 0 x2 = x3

(II) If f (x2 ) f (x3 ) < 0 x1 = x3

(III) If f (x3 ) = 0

Recurrence relation:
xn+2 = xn+1

f (xn+1 )
(xn+1 xn ) .
f (xn+1 ) f (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
x1
SET x3 = x2 f (x2 ) f (xx22)f
(x1 )
IF f (x3 ) f (x1 ) < 0
SET x2 = x3
ELSE
SET x1 = x3
ENDIF
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
x1
SET x3 = x2 f (x2 ) f (xx22)f
(x1 )
IF |f (x1 )| < |f (x2 ) |
SET x2 = x3
ELSE
SET x1 = x3
ENDIF
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 for
x = xn , the the convergence of the method of linear interpolation is
n+1 = k 1.618
n

(11)

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


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

2n 00
f (r )
2

(12)

then the relation


xn+2 = xn+1

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

(13)

becomes
r +n+2 = r +n+1

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


 (n+1 n )
f 0 (r ) (n+1 n ) + 12 f 00 (r ) 2n+1 2n
Kostas Kokkotas16

Numerical Methods in Physics and Astrophysics

which leads to:





f 00 (r )
n f 00 (r )
= n+1 n 0
n+2 = n+1 1 1
0
2 f (r )
2f (r )
but we are aiming for a relation of the form n+1 = k m
n

 00

m
f (r )
n+1 = k n
m
k n+1 = n+1 n
n+2 = k m
2f 0 (r )
n+1
1
  m1
1
1
1
f 00 (r )
n+1 =
nm1 A m1 where A = 0
k
2f (r )

1/(m1)

1
  m1

k = Ak
1
A

m1
m
n
k n =


k
1

m = m1
m2 m 1 = 0

f 00 (r )
1 5
= 1.618 and k m = A = 0
m=
2
2f (r )

n+1 = k 1.618
n
Kostas Kokkotas17

(14)

(15)

Numerical Methods in Physics and Astrophysics

Method xn+1 = g (xn )


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

Kostas Kokkotas18

Numerical Methods in Physics and Astrophysics

THEOREM: If g (x) and g 0 (x) are continuous on an interval about a


root r of the equation x = g (x), and if |g 0 (x)| < 1 for all x in the
interval, then the recurrence xn+1 = g (xn ) (n = 1, 2, 3, . . . ) will converge
to the root x = r , provided that x1 is chosen in the interval.
Note that this is a sufficient condition only, since for some equations
convergence 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 xn
n+1 = r xn+1 = g (r ) g (xn ) = g 0 (r )(r xn ) = g 0 (r ) n
I.e. linear convergence.
The rate of convergence is rapid if |g 0 (x)| is small in the interval. If the
derivative is negative the errors alternate in sign giving oscillatory
convergence.

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 0 (x)| = 1 1 on [0.1, 1] : no convergence.
x
I

xn+1 = e xn then |g 0 (x)| = |e x | e 0.1 0.9 < 1 : convergence.

another writing : xn+1 = (xn + e xn )/2 then


|g 0 (x)| = 21 |1 e x | 12 |1 e 1 | = 0.316 : better convergence.

finally xn+1 = xn +2e


thus
3
|g 0 (x)| = 13 |1 2e x | 13 |1 2e 1 | = 0.03 : even better
convergence.

xn

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 0 (r )n ) then it can be
improved to produce even more accurate results without extra
iterations.
The error the method xn+1 = g 0 (xn ) after n iterations is:
r xn+1 g 0 (r )(r xn )
after n + 1 is:
r xn+2 g 0 (r )(r xn+1 )
and by division we get
r xn+1
g 0 (r )(r xn )
= 0
r xn+2
g (r )(r xn+1 )
Then by solving for r we get:
2

r = xn

(xn xn1 )
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 of
f (x) are continuous we can develop root finding techniques which
converge faster than any method presented till now.
Lets assume that after n iterations we reached a
value xn+1 which is the root of the equation and xn is
a nearby value such as: xn+1 = xn + n . Then:
f (xn+1 )

= f (xn + n )
= f (xn ) + n f 0 (xn ) +

2n 00
f (xn ) +
2

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


n =

f (xn )
f 0 (xn )

xn+1 = xn

f (xn )
f 0 (xn )

Kostas Kokkotas22

(17)

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 0 (r ) + 12 2n f 00 (r )
f (r + n )
=
r
+

n
f 0 (r + n )
f 0 (r ) + n f 00 (r )

but since f (r ) = 0 and


1
f 00 (r )

n
1 + f 00 (r )/f 0 (r )
f 0 (r )
we get the following relation:
n+1 =

f 00 (r ) 2

2f 0 (r ) n

(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 will
converge if |g 0 (x)| < 1 . Here:
g (x) = x

f (x)f 00 (x)
f (x)
0

g
(x)
=
f 0 (x)
[f 0 (x)]2

(19)

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


g (xn )

g (r + n ) = g (r ) + g 0 (r )n +

g 00 () 2

2 n

(20)

00

g (r ) +

g () 2
 ,
2 n

[r , xn ]

(21)

This leads to:


g (xn ) g (r ) =

g 00 () 2

2 n

Kostas Kokkotas24

xn+1 r n+1 =

g 00 () 2

2 n

(22)

Numerical Methods in Physics and Astrophysics

Newtons method : Algorithm


COMPUTE f (x1 ), f 0 (x1 )
SET x2 = x1
IF (f (x1 ) 6= 0) END (f 0 (x1 ) 6= 0)
REPEAT
SET x2 = x1
SET x1 = x1 f (x1 )/f 0 (x1 )
UNTIL (|x1 x2 | < E ) OR (|f (x2 )| < E 0 )
ENDIF
EXAMPLE : Find the square root of a number a.
f (x) = x 2 a

and f 0 (x) = 2x

Then
xn+1

x2 a
= xn n
2xn

or in a better form

Kostas Kokkotas25

xn+1

1
=
2



a
xn +
. (23)
xn

Numerical Methods in Physics and Astrophysics

Newtons method : Halley


Remember that n = xn+1 xn , then
f (xn+1 ) = f (xn + n ) = f (xn ) + n f 0 (xn ) +

2n 00
f (xn ) + . . .
2

h
i
n
f (xn ) + n f 0 (xn ) + f 00 (xn ) = 0
2
f (xn )
n = 0
f (xn ) + 2n f 00 (xn )
from the 1st order result we substitute
n

xn+1 = xn

f (xn )
f 0 (xn )

f 00 (xn )f (xn )
2f 0 (xn )

f (xn )
f 0 (xn )

= xn

2f

02

2f (xn ) f 0 (xn )
(24)
(xn ) f 00 (xn ) f (xn )

obviously for f 00 (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:
"

2 #
1 f 000 () 1 f 00 ()

3n
n+1 =
6 f 0 ()
4 f 0 ()

(25)

EXAMPLE: The square root of a number Q (here Q = 9) with Halleys


method is given by (compare with eq. (23):
xn+1 =
Newton
x0 =15
x1 =7.8
x2 =4.477
x3 =3.2436
x4 =3.0092

Error
0 = 12
1 = 4.8
2 = 1.477
3 = 0.243
4 = 9.15103
Kostas Kokkotas27

xn3 + 3xn Q
3xn2 + Q
Halley
x0 =15
x1 =5.526
x2 =3.16024
x3 =3.00011
x4 =3.0000000...

(26)
Error
0 = 12
1 = 2.5
2 = 0.16
3 = 1.05 104
4 = 3.24 1014

Numerical Methods in Physics and Astrophysics

Newtons method : Multipole roots


If f (x) = (x r )m q(x) where m is the multiplicity of root r then
f 0 (x) = (x r )m1 [mq(x) + (x r )q 0 (x)]
i.e. both f (r ) = 0 and f 0 (r ) = 0. Thus the ratio [f (x)/f 0 (x)]xr will
diverge.
To avoid the problem we construct a new function
(x) =

(x r )q(x)
f (x)
=
0
f (x)
mq(x) + (x r )q 0 (x)

which obviously has r as root with multiplicity m = 1 and the recurrence


relation is:
xn+1

f (xn )/f 0 (xn )


(xn )
=
x

n
0 (xn )
{[f 0 (xn )]2 f (xn )f 00 (xn )} /[f 0 (xn )]2
0
f (xn ) f (xn )
= xn 0
(27)
[f (xn )]2 f (xn )f 00 (xn )

= xn

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) = x 4 4x 2 + 4 = 0
(r = 2 = 1.414213...).
Standard Newton-Raphson
xn+1 = xn

xn2 2
4xn

(A)

Modified Newton-Raphson
xn+1 = xn
x
x0
x1
x2
x3

(A)
1.5
1.458333333
1.436607143
1.425497619

(xn2 2)xn
xn2 + 2

Error (A)
8.6102
4.4102
2.2102
1.1102

Kostas Kokkotas29

(B).

(B)
1.5
1.411764706
1.414211439
1.414213562

Error (B)
8.6102
-2.4103
-2.1106
-1.61012

Numerical Methods in Physics and Astrophysics

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

|n+1 |
= a |n | a|n1 | a2 |n2 | ... an |0 |
|n |

then by solving the above equation for n we come to a relation which


gives 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:


lim

n+1
n+1
|
n+1 |
= b |
n | b|
n1 |2 b 3 |
n2 |4 ... b 2 1 |
0 |2
|
n |2

Kostas Kokkotas30

Numerical Methods in Physics and Astrophysics

and by solving the above relation for n in order to achieve a given


accuracy |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 be


smaller than 106 i.e. n 106 with an initial error 0 = 0.5 and for
a = b = 0.7 the relation (28) gives:
n

log10 |106 | log10 |0.5|


37
log10 |0.7|

iterations

The same assumptions for quadratic convergence will give:


2n+1

log10 |106 | + log10 |0.7|


13.5
log10 |0.5| + log10 |0.7|

i.e. the number of iterations is only 3!


The difference becomes more pronounce if we demand even higher
accuracy e.g. n 1014 then bisection will need 89 iterations while
Newtons 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 previous
section in solving systems of non-linear equations. The two methods are
based on Newtons method and in the xn+1 = g (xn ) method.
An example of two non-linear equations is
the following:
f (x, y )

= e x 3y 1
(30)

g (x, y )

= x +y 4

it is obvious that f (x, y ) = 0 and


g (x, y ) = 0 are two curves on the xy plane
as 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 equations
while 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 the
solution (xn+1 , yn+1 ) i.e. f (xn+1 , yn+1 ) 0 and g (xn+1 , yn+1 ) 0. Then
by assuming that xn+1 = xn + n and yn+1 = yn + n we can Taylor
expand around the solution i.e.
 
 
f
f
+n
0 f (xn+1 , yn+1 ) = f (xn +n , yn +n ) f (xn , yn )+n
x n
y n
 
 
g
g
0 g (xn+1 , yn+1 ) = g (xn +n , yn +n ) g (xn , yn )+n
+n
x n
y n

Kostas Kokkotas33

Numerical Methods in Physics and Astrophysics

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


n =

g
f
y + g y
g f
f g
x y x y

and n =

g
x
g f
x y

f
g x
+f
f g
x y

(31)

Since xn+1 = xn + n and yn+1 = yn + n we come to the following pair of


recurrence relations, which are generalizations of Newtons method:

xn+1

= xn


yn+1

= yn

Kostas Kokkotas34

f gy g fy
fx gy gx fy

g fx f gx
fx gy gx fy

(32)
n

(33)
n

Numerical Methods in Physics and Astrophysics

Newtons method n non-linear equations

If we assume the following system of N equations


f1 (x 1 , x 2 , ..., x N ) = 0
.. ..
..
fn (x 1 , x 2 , ..., x N ) = 0
with N unknowns (x 1 , x 2 , ..., x N ). Then by considering a solution of the
1
2
N
system (xn+1
, xn+1
, ..., xn+1
) for which we assume the following relations
1
xn+1
= xn1 + xn1
.. ..
..
N
xn+1
= xnN + xnN

Kostas Kokkotas35

Numerical Methods in Physics and Astrophysics

We can create expansion of the form:


1
N
0
, ..., xn+1
)
= f1 (xn+1

1
N
0
, ..., xn+1
)
= fN (xn+1

= f1 (xn1 + xn1 , ..., xnN + xnN )


f1
f1
f1 + 1 xn1 + ... + N xnN
x
x
.. ..
..
=

fN (xn1

xn1 , ..., xnN

(34)

xnN )

+
+
fN
fN
fN + 1 xn1 + ... + N xnN
x
x

Then the quantities xni will be found as solutions of the linear system

f1 f1

f1
1

f1
x
n
x 1
x 2
x N

..

..
..

..
.
.
(35)
.

= .

fN
fN
fN
fN
xnN
x
N
x 1
x 2

Kostas Kokkotas36

Numerical Methods in Physics and Astrophysics

Thus if we start with N initial values (x01 , x02 , ..., x0N ) then from the
solution of the above system we will calculate the quantities xni which
lead to the new values (x11 , x12 , ..., x1N ) via the relations:
x11

= x01 + x01
.. ..
..

x1N

= x0N + x0N

(36)

This procedure will be repeated till the a given accuracy is reached i.e.
max |xni | < 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 ) =
.. ..
. .

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

(37)

The system can be rewritten in the form:


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

(38)

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

A SIMPLE CHOICE: Give some N initial values (x1 , . . . , xN )0 in the


right 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 given
accuracy.
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) and
find a new value (x1 )1 .
Then in the right hand side of the 2nd equations apply the following set
of guess values (x1 )1 , (x2 , . . . , xN )0 and estimate (x2 )1 . Continue in the
third 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, . . . , N
will converge to a solution, if near this solution the following criterion is
satisfied:







F1 F1

+
+ + F1 < 1
xN
x1 x2
.. ..
..
(39)





FN FN
FN





x1 + x2 + + xN < 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 e x 3y = 1

with exact solutions (1.5595,1.2522) and (-1.9793,-0.2873) can be


written in the form:
p
xn+1 = 4 yn2

and yn+1 =

1 xn
(e 1)
3

for an initial choice (1, 0), we create the following sequence of solutions
n
x
y

0
-1
0

1
-2
-0.2107

2
-1.9884
-0.2882

3
-1.9791
-0.2877

4
-1.9792
-0.2873

5
-1.9793
-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
x
y

0
-1
0

1
-2
-0.2882

2
-1.9791
-0.2873

3
-1.9793
-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 recurrence
relations as follows:
xn+1 =

4 yn2

and yn+1 =

1 xn
(e 1)
3

If we start with values close to the exact solution e.g. x0 = 1.5 and
y0 = 1 the results are :
n
x
y

0
1.5
1

1
1.7321
1.5507

2
1.2630
0.8453

3
1.8126
1.7087

4
1.0394
0.6092

5
1.9050
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


p
yn+1 =
4 xn2
xn+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 00 + 2 y = 0
with the following boundary conditions y (0) = 0 and y (1) = y 0 (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 e x sin(x) = 0 (r = 3.183063012). If
the initial interval is [4, 3] estimate the number of iteration
needed to reach an accuracy of 4 digits i.e. |xn r | < 0.00005.
5. Repeat the previous estimation for using the methods of linear
interpolation and Newton.
6. Solve the following system of equations using both methods and
estimate the rate of convergence:
ex y = 0

Kostas Kokkotas43

and xy e x = 0

Numerical Methods in Physics and Astrophysics

1. Consider the nonlinear system of equations


f1 (x, y ) = x 2 + y 2 2 = 0,

and f2 (x, y ) = xy 1 = 0 .

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

Kostas Kokkotas44

Numerical Methods in Physics and Astrophysics

You might also like