Beruflich Dokumente
Kultur Dokumente
FA 16
Lecture 11
17/10/2016
Lecture 11
Newton-Raphson method
We assume that the function `f ' is dierentiable.
Computational Physics
Dr. M. Kamran
3 / 18
17/10/2016
Lecture 11
Newton-Raphson method
We assume that the function `f ' is dierentiable.
At a certain point
(x0 , f (x0 ))
Computational Physics
Dr. M. Kamran
3 / 18
17/10/2016
Lecture 11
Newton-Raphson method
We assume that the function `f ' is dierentiable.
At a certain point
(x0 , f (x0 ))
= f (x0 ) (x x0 ) + f (x0 ) ,
(1)
Computational Physics
Dr. M. Kamran
3 / 18
17/10/2016
Lecture 11
Newton-Raphson method
We assume that the function `f ' is dierentiable.
At a certain point
(x0 , f (x0 ))
= f (x0 ) (x x0 ) + f (x0 ) ,
(1)
`f'.
Computational Physics
Dr. M. Kamran
3 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The root of g (x) can be easily found from Eq. 1.
x1
Computational Physics
= x0
(x0 )
.
0)
f (x
Dr. M. Kamran
(2)
4 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The root of g (x) can be easily found from Eq. 1.
x1
= x0
(x0 )
.
0)
f (x
(2)
Computational Physics
Dr. M. Kamran
4 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The root of g (x) can be easily found from Eq. 1.
x1
= x0
(x0 )
.
0)
(2)
f (x
= x1
(x1 )
,
1)
f (x
Computational Physics
x3
= x2
(x2 )
.
2)
f (x
Dr. M. Kamran
(3)
4 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The root of g (x) can be easily found from Eq. 1.
x1
= x0
(x0 )
.
0)
(2)
f (x
= x1
(x1 )
,
1)
f (x
x3
= x2
(x2 )
.
2)
f (x
(3)
Dr. M. Kamran
4 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Computational Physics
Dr. M. Kamran
5 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Describing the Newton's method in terms of a sequence
x0 , x1 , . . ., we can write
xn+1
Computational Physics
= xn
(xn )
.
n)
f (x
Dr. M. Kamran
(4)
6 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Describing the Newton's method in terms of a sequence
x0 , x1 , . . ., we can write
xn+1
= xn
(xn )
.
n)
f (x
(4)
Computational Physics
Dr. M. Kamran
6 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Describing the Newton's method in terms of a sequence
x0 , x1 , . . ., we can write
xn+1
= xn
(xn )
.
n)
f (x
(4)
Computational Physics
Dr. M. Kamran
6 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Describing the Newton's method in terms of a sequence
x0 , x1 , . . ., we can write
xn+1
= xn
(xn )
.
n)
f (x
(4)
Computational Physics
(x0 + h) = 0.
Dr. M. Kamran
(5)
6 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Describing the Newton's method in terms of a sequence
x0 , x1 , . . ., we can write
xn+1
= xn
(xn )
.
n)
f (x
(4)
(x0 + h) = 0.
(5)
(x0 ) + hf (x0 ) +
Computational Physics
(x0 ) + . . . = 0.
Dr. M. Kamran
(6)
6 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Determining `h' from this equation is, of course, not easy.
Therefore, we give up the expectation of arriving at the
true root in one step and seek only an approximation to h.
Computational Physics
Dr. M. Kamran
7 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Determining `h' from this equation is, of course, not easy.
Therefore, we give up the expectation of arriving at the
true root in one step and seek only an approximation to h.
We retain the rst two terms in the series, and ignore
higher terms.
f
Computational Physics
(x0 ) + hf (x0 ) = 0
Dr. M. Kamran
(7)
7 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Determining `h' from this equation is, of course, not easy.
Therefore, we give up the expectation of arriving at the
true root in one step and seek only an approximation to h.
We retain the rst two terms in the series, and ignore
higher terms.
f
(x0 ) + hf (x0 ) = 0
(7)
Note: The h that solves Eq. 7 is not the one that solves Eq.
6.
Computational Physics
Dr. M. Kamran
7 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Determining `h' from this equation is, of course, not easy.
Therefore, we give up the expectation of arriving at the
true root in one step and seek only an approximation to h.
We retain the rst two terms in the series, and ignore
higher terms.
f
(x0 ) + hf (x0 ) = 0
(7)
Note: The h that solves Eq. 7 is not the one that solves Eq.
6.
From Eq. 7, we obtain
h
Computational Physics
(x0 )
.
0)
f (x
Dr. M. Kamran
(8)
7 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Determining `h' from this equation is, of course, not easy.
Therefore, we give up the expectation of arriving at the
true root in one step and seek only an approximation to h.
We retain the rst two terms in the series, and ignore
higher terms.
f
(x0 ) + hf (x0 ) = 0
(7)
Note: The h that solves Eq. 7 is not the one that solves Eq.
6.
From Eq. 7, we obtain
h
(x0 )
.
0)
f (x
(8)
Dr. M. Kamran
7 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x1
= x0 + h = x0
Computational Physics
(x0 )
.
0)
f (x
Dr. M. Kamran
(9)
8 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x1
= x0 + h = x0
(x0 )
.
0)
f (x
(9)
Computational Physics
Dr. M. Kamran
8 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x1
= x0 + h = x0
(x0 )
.
0)
(9)
f (x
Problem: If f
(x) = x3 x + 1
and x0
= 1,
calculate x1 and x2
Computational Physics
Dr. M. Kamran
8 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x1
= x0 + h = x0
(x0 )
.
0)
(9)
f (x
Problem: If f
(x) = x3 x + 1
and x0
= 1,
calculate x1 and x2
(x0 ) = 1;
Computational Physics
(x0 ) = 2.
Dr. M. Kamran
8 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x1
= x0 + h = x0
(x0 )
.
0)
(9)
f (x
Problem: If f
(x) = x3 x + 1
and x0
= 1,
calculate x1 and x2
(x0 ) = 1;
x1
Computational Physics
(x0 ) = 2.
= .
2
Dr. M. Kamran
8 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x1
= x0 + h = x0
(x0 )
.
0)
(9)
f (x
Problem: If f
(x) = x3 x + 1
and x0
= 1,
calculate x1 and x2
(x0 ) = 1;
x1
(x1 ) = ;
Computational Physics
(x0 ) = 2.
= .
2
f
(x1 ) = .
4
Dr. M. Kamran
8 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x1
= x0 + h = x0
(x0 )
.
0)
(9)
f (x
Problem: If f
(x) = x3 x + 1
and x0
= 1,
calculate x1 and x2
(x0 ) = 1;
x1
(x1 ) = ;
8
(x0 ) = 2.
= .
2
f
x2
Computational Physics
(x1 ) = .
4
= 3.
Dr. M. Kamran
8 / 18
17/10/2016
Lecture 11
Newton-Raphson method
In the use of Newton's method, consideration must be given
to the proper choice of a starting point.
Its convergence depends upon hypotheses that are dicult
to verify a priori.
Computational Physics
Dr. M. Kamran
9 / 18
17/10/2016
Lecture 11
Newton-Raphson method
In the use of Newton's method, consideration must be given
to the proper choice of a starting point.
Its convergence depends upon hypotheses that are dicult
to verify a priori.
Sometimes, due to a poor choice of the initial point, it may
happen that the tangent to the graph of the function f at
x0 intersects the x-axis at a point remote from the root r.
Computational Physics
Dr. M. Kamran
9 / 18
17/10/2016
Lecture 11
Newton-Raphson method
In the use of Newton's method, consideration must be given
to the proper choice of a starting point.
Its convergence depends upon hypotheses that are dicult
to verify a priori.
Sometimes, due to a poor choice of the initial point, it may
happen that the tangent to the graph of the function f at
x0 intersects the x-axis at a point remote from the root r.
Figure: Runaway
Computational Physics
Dr. M. Kamran
9 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Successive points in Newton's iteration will recede from the
root instead of converging to it.
Computational Physics
Dr. M. Kamran
10 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Successive points in Newton's iteration will recede from the
root instead of converging to it.
It may happen that the tangent to the curve is parallel to
the x-axis and x1
= ,
Computational Physics
Dr. M. Kamran
10 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Successive points in Newton's iteration will recede from the
root instead of converging to it.
It may happen that the tangent to the curve is parallel to
the x-axis and x1
= ,
= x0 .
Computational Physics
Dr. M. Kamran
10 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Successive points in Newton's iteration will recede from the
root instead of converging to it.
It may happen that the tangent to the curve is parallel to
the x-axis and x1
= ,
= x0 .
Dr. M. Kamran
10 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Successive points in Newton's iteration will recede from the
root instead of converging to it.
It may happen that the tangent to the curve is parallel to
the x-axis and x1
= ,
= x0 .
Figure: Cycle
Dr. M. Kamran
10 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Roundo errors or limited precision may eventually cause
this situation to become unbalanced.
Computational Physics
Dr. M. Kamran
11 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Roundo errors or limited precision may eventually cause
this situation to become unbalanced.
Computational Physics
Dr. M. Kamran
11 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Roundo errors or limited precision may eventually cause
this situation to become unbalanced.
Computational Physics
= xn m
f
f
(xn )
.
(xn )
Dr. M. Kamran
(10)
11 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Problem: Carry out two iterations of Newton's method using
x0
=1
and f
(x) = x2 + 10x 3.
Computational Physics
Dr. M. Kamran
12 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Problem: Carry out two iterations of Newton's method using
x0
=1
and f
(x) = x2 + 10x 3.
f
(x) = x2 + 10x 3;
Computational Physics
(x) = 2x + 10.
Dr. M. Kamran
12 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Problem: Carry out two iterations of Newton's method using
x0
=1
and f
(x) = x2 + 10x 3.
f
(x) = x2 + 10x 3;
f
(x0 ) = 8;
Computational Physics
(x) = 2x + 10.
(x0 ) = 12.
Dr. M. Kamran
12 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Problem: Carry out two iterations of Newton's method using
x0
=1
and f
(x) = x2 + 10x 3.
f
(x) = x2 + 10x 3;
f
(x0 ) = 8;
x1
Computational Physics
(x) = 2x + 10.
(x0 ) = 12.
= 1/3.
Dr. M. Kamran
12 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Problem: Carry out two iterations of Newton's method using
x0
=1
and f
(x) = x2 + 10x 3.
f
(x) = x2 + 10x 3;
f
(x0 ) = 8;
x1
(x1 ) = 4/9;
Computational Physics
(x) = 2x + 10.
(x0 ) = 12.
= 1/3.
f
(x1 ) = 32/3.
Dr. M. Kamran
12 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Problem: Carry out two iterations of Newton's method using
x0
=1
and f
(x) = x2 + 10x 3.
f
(x) = x2 + 10x 3;
f
(x0 ) = 8;
x1
(x1 ) = 4/9;
x2
Computational Physics
(x) = 2x + 10.
(x0 ) = 12.
= 1/3.
f
(x1 ) = 32/3.
= 7/24.
Dr. M. Kamran
12 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Dening the function (using symbolic toolbox)
syms x
f
Computational Physics
Dr. M. Kamran
13 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Dening the function (using symbolic toolbox)
syms x
f
Computational Physics
Dr. M. Kamran
13 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Dening the function (using symbolic toolbox)
syms x
f
')
grid on
xlabel(`$$x$$',`Interpreter',`Latex')
ylabel(`$$f
(x)$$',`Interpreter',`Latex')
3
x 1$$'],
`Interpreter',`Latex')
Computational Physics
Dr. M. Kamran
13 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The initial guess
x0
= 1.0;
Computational Physics
Dr. M. Kamran
14 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The initial guess
x0
= 1.0;
Tolerance allowed
min_err = 10
Computational Physics
Dr. M. Kamran
14 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The initial guess
x0
= 1.0;
Tolerance allowed
min_err = 10
Computational Physics
Dr. M. Kamran
14 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The initial guess
x0
= 1.0;
Tolerance allowed
min_err = 10
Computational Physics
Dr. M. Kamran
14 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The initial guess
x0
= 1.0;
Tolerance allowed
min_err = 10
Dr. M. Kamran
14 / 18
17/10/2016
Lecture 11
Newton-Raphson method
The function le
function [x_root,iterations_vec,rel_err_vec] =
new_raph_fun(f,f_der,x_0,min_err)
x_old = x_0;
rel_err = 1;
iterations = 0;
counter = 1;
while rel_err > min_err
f_x_old = double(subs(f,x_old));
f_der_x_old = double(subs(f_der,x_old));
x_new = x_old
f_x_old / f_der_x_old;
Computational Physics
x_old) / x_old );
Dr. M. Kamran
15 / 18
17/10/2016
Lecture 11
Newton-Raphson method
x_old = x_new;
iterations_vec (counter) = iterations;
rel_err_vec(counter) = rel_err;
counter = counter + 1;
iterations = iterations + 1;
end
x_root = x_new;
Computational Physics
Dr. M. Kamran
16 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Dr. M. Kamran
17 / 18
17/10/2016
Lecture 11
Newton-Raphson method
Dr. M. Kamran
18 / 18