Chapter2 Nonlinear Eqs Version2021
Chapter2 Nonlinear Eqs Version2021
Introduction
Solving one equation
Graph method
Course of Computational Physics 1 Bisection method
Fixed-point Iteration
Lecturer: dr Hưng / Sonnet Nguyen Newton-Raphson method
improved Newton-Raphson methods
Hanoi Univ. of Science Secant method
E-mail: [email protected] Brent method
Regula-Falsi method
Copyright 2007-2022
Solving a system of nonlinear equations
https://classroom.google.com/u/0/c/NTUwNTg1 Minimization and Maximization
MDk1MjI2 Steepest descent method
1 Computational Physics 1, Hanoi Univ of Science 2/73
Introduction Example
Much of the problems of science lead to the problem of solving A geometric representation of a nonlinear system when n 2,
simultaneous equations and inequalities. In this lecture we shall
f1 ( x1 , x2 ) 0 f 2 ( x1 , x2 ) 0, is given in the Figure below
focus into numerical algorithms for solving one equation or a
system of nonlinear equations. At the beginning we consider the
root-finding problem, i.e. finding a root or solution of an equation
f ( x ) 0, which is one of the most basic problems of numerical
approximation. Later, we consider the more difficult problem:
Finding a solution of a system of m equations with n unknowns:
f1 ( x1 ,....., xn ) 0 Given F : R n R m .
⋮ OR
f ( x ,....., x ) 0 Find x R such F ( x ) 0 .
n
m 1 n
Computational Physics 1, Hanoi Univ of Science 3/73 Computational Physics 1, Hanoi Univ of Science 4/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Determine an interval [ a, b] (or open ( a, b)) in which one and Suppose that f is continuous on the interval [a, b] and
only one root exists. The interval can be found by use of the
that f (a) and f (b) are of opposite sign. We want to
graphing method or well-known theorem.
find a solution to f ( x) 0 on an interval (a, b).
Theorem:
Although the method will work for the case when more
If f ( x) is continuous, monotonic and f (a )* f (b) 0, then
the interval ( a, b) contains exactly one root.
than one root is contained in the interval [a, b], we
assume for simplicity of our discussion that the root in
In the theorem above we can replace the "monotonicity" of the this interval is unique.
function f by the condition "unchanging sign of its derivative".
Computational Physics 1, Hanoi Univ of Science 7/73 Computational Physics 1, Hanoi Univ of Science 8/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
There are three stopping criteria commonly incorporated in Start: Given a,b and ε
the Bisection method.
u = f(a) ; v = f(b)
First, the method stops if one of the midpoints happens to
coincide with the root. c = (a+b) /2 ; w = f(c) no
Secondly, it also stops when the length of the search interval yes
yes is no is
is less than some prescribed tolerance we call TOL. Stop
(b-a)/2 <ε
u w <0
Thirdly, the procedure also stops if the number of iterations
exceeds a preset bound N0 . b=c; v= w a=c; u= w
Computational Physics 1, Hanoi Univ of Science 11/73 Computational Physics 1, Hanoi Univ of Science 12/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Computational Physics 1, Hanoi Univ of Science 17/73 Computational Physics 1, Hanoi Univ of Science 18/73
Theorem
Suppose that g ( x) is continuous in [ a, b] and for all x in [a, b]
the value g ( x) in [a, b] too.
Suppose, in addition, that g ' exists on (a, b) and exists a
constant q such that 0 q 1, and | g '( x) | q for all x in (a, b).
Then for any number x0 in [a, b] the sequence defined by
x1 g ( x0 ), x2 g ( x1 ), … , xk g ( xk 1 ), …
converges to the unique fixed-point in [ a, b].
Computational Physics 1, Hanoi Univ of Science 21/73 Computational Physics 1, Hanoi Univ of Science 22/73
Computational Physics 1, Hanoi Univ of Science 27/73 Computational Physics 1, Hanoi Univ of Science 28/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Computational Physics 1, Hanoi Univ of Science 31/73 Computational Physics 1, Hanoi Univ of Science 32/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
if(Cond == 2) printf("The root was found with the desired tolerance !\n");
printf("----------------------------------------------\n");
Computational Physics 1, Hanoi Univ of Science 33/73 Computational Physics 1, Hanoi Univ of Science 34/73
Computational Physics 1, Hanoi Univ of Science 35/73 Computational Physics 1, Hanoi Univ of Science 36/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
CISE301_Topic2 Computational Physics 1, Hanoi Univ of Science 37/73 Computational Physics 1, Hanoi Univ of Science 38/73
Computational Physics 1, Hanoi Univ of Science 39/73 Computational Physics 1, Hanoi Univ of Science 40/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Suppose that f in C 3 ([ a , b ]), the interval [ a , b] contains a root p , The Newton-Raphson method requires to compute values
(thus exists p in [ a , b] such f ( p ) 0), and suppose f '( p ) 0. f ( xk ) and f '( xk ) at each step of the iteration.
Then there exists >0 such a sequence { xn } defined by For a simple function f , it is not a big problem, but for a
1
f ( x) f ( x ) f ''( x ) complicated function, the computation of f '( xk ) at each step
g ( x) x 1 ; xk 1 g ( xk );
f '( x ) 2( f '( x )) 2 is too costly.
converges to p for every initial point in the -neighborhood So it is natural to ask for other fast convergent methods, that
of p , i.e. x0 [ p , p ]. require to compute only the value of the function f .
Furthermore if p is a simple root, the order of convergence These methods do exist as we will see below.
of the sequence { xk } is equal 3.
Computational Physics 1, Hanoi Univ of Science 41/73 Computational Physics 1, Hanoi Univ of Science 42/73
The secant method is a root-finding algorithm that uses a The secant method is defined by the recurrence relation
succession of roots of secant lines to better approximate a
xn xn1 f xn1
xn 1 xn 2
root of a function f . f xn1 f xn 2
The secant method can be thought of as a finite difference Note that the secant method requires two initial values,
approximation of Newton-Raphson method.
x0 and x1 , which should ideally be chosen to lie close to
However, it was developed independently of the Newton-Raphson
the root.
method.
Computational Physics 1, Hanoi Univ of Science 43/73 Computational Physics 1, Hanoi Univ of Science 44/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
We use two stopping conditions in the Secant method. The iteration equation should not be simplified algebraically to
First, we assume that xn is sufficiently accurate when |xn xn 1|
xn xn 1 f xn 1
xn1 xn2 =
f ( xn 1 ) xn 2 f ( xn 2 ) xn 1
is within a given tolerance. f xn 1 f xn 2 f ( xn 1 ) f ( xn 2 )
Second, a safeguard exit based upon a maximum number of Although this is algebraically equivalent to the iteration equation,
iterations is given in case the method fails to converge as it could increase the significance of rounding error if the nearly
expected. equal numbers f ( xn 1 ) xn 2 and f ( xn 2 ) xn 1 are subtracted.
The Secant method does not have the root-bracketing property of
the Bisection method. As a consequence, the method does not always
converge, but when it does converge, it generally does so much faster
than the Bisection method.
Computational Physics 1, Hanoi Univ of Science 45/73 Computational Physics 1, Hanoi Univ of Science 46/73
Theorem Suppose that f in C 2 ([a, b]), the interval [a, b] contains a root p,
Suppose that f in C 2 ( a , b ), the interval a , b contains a and suppose f '( p) 0. Then there exists >0 such a sequence {xn }
root p (thus exists p in a , b such f p 0), and suppose defined by
xk 1 g ( xk 2 , xk 1 , xk ) xk 1
f ’ p 0. Then there exists 0 such a sequence {xn }
f ( xk 2 ) f ( xk 1 ) f ( xk 2 ) ( xk 1 xk ) f ( xk ) f ( xk 1 ) f ( xk ) ( xk 2 xk 1 )
defined by
f ( xk )( xk xk 1 ) f ( xk ) f ( xk 1) f ( xk ) f ( xk 2 ) f ( xk 1 ) f ( xk 2 )
xk 1 g ( xk 1 , xk ) xk
f ( xk ) f ( xk 1 )
converges to p for every initial points in the neighborhood of p,
converges to p for every initial points in the – neighborhood
i.e. for all x0 , x1 , x2 [p , p ].
of p , i.e. for all x0 , x1 [p , p ].
Computational Physics 1, Hanoi Univ of Science 47/73 Computational Physics 1, Hanoi Univ of Science 48/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Computational Physics 1, Hanoi Univ of Science 49/73 Computational Physics 1, Hanoi Univ of Science 50/73
#include <stdio.h>
Theorem. Assume that f C[a0 , b0 ] and p [a0 , b0 ] #include <math.h>
double f(double x)
is a root. If f (an ) and f (bn ) have opposite signs, and {
return x*x*x-3*cos(x)+2.8;
an f (bn ) bn f (an )
cn }
f (bn ) f (an ) int main(void)
{
represents the sequence of points generated by the printf(“One root computed by the Regula Falsi method
Regula Falsi method, then the sequence cn p= %0.10f\n", falsi(-2, -1, 5E-10, 100));
return 0;
converges to the root p. }
Computational Physics 1, Hanoi Univ of Science 51/73 Computational Physics 1, Hanoi Univ of Science 52/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Computational Physics 1, Hanoi Univ of Science 53/73 Computational Physics 1, Hanoi Univ of Science 54/73
The Newton’s method for a system of non- The Newton’s method for a system of non-
linear equations linear equations
Use the Taylor expansion: So, the Newton-Raphson algorithm consists of the following
steps:
0 F ( X ) F ( X 0 ) DF ( X 0 ) * ( X X 0 ) • Step 0: initialize the iteration counter (k=0) and provide
an initial value for vector x, i.e., x(0).
where X 0 ( x01 ,....x0n ), DF ( X 0 ) is Jacobian matrix at X 0 • Step 1: compute the Jacobian JF(x(0)).
f1 f1 • Step 2: compute x(k+1).
x1 ,...., x n • Step 3: check every element of the absolute value of the
difference between the values of vector x in two consecutive
J F ( X 0 ) DF ( X 0 ) ................... , iterations is lower than a tolerance , i.e., check if || x(k+1) -
f f x(k) ||< tol. If so, the algorithm has converged and the
n ,...., nn solution is x(k+1) If not, continue at Step 4.
x1 x x X 0 • Step 4: update the iteration counter k=k+1 and continue
at Step 1.
1
Thus, X 1 X 0 J X 0 F X0 .
Computational Physics 1, Hanoi Univ of Science 55/73 Computational Physics 1, Hanoi Univ of Science 56/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
The Newton’s method for a system of non- The fixed-point iteration for system of non-
linear equations – An example linear equations
Solve approximately the system of non-linear equations:
Fixed-point method
x3 y 1, y 3 x 2,
near (1,1) by the Newton method. 0 F ( X ) X G ( X ).
Sol. Here Choose: X 0 .
f ( x, y ) x 3 y 1 0,
Recursion: X k 1 G ( X k ).
g ( x, y ) y 3 x 2 0.
The Jacobi matrix: Newton's method
J [3 x ,1; 1,3 y ].
2 2
0 F ( X ).
We will use the matrix J for each iteration.
Choose: X 0 ,
For the first iteration,we need to solve the following system
J [ x, y ] [ f (1,1), g (1,1)]; X k 1 g ( X k ) X k [J ( X k )]1 * F ( X k ).
Computational Physics 1, Hanoi Univ of Science 57/73 Computational Physics 1, Hanoi Univ of Science 58/73
Computational Physics 1, Hanoi Univ of Science 59/73 Computational Physics 1, Hanoi Univ of Science 60/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Computational Physics 1, Hanoi Univ of Science 61/73 Computational Physics 1, Hanoi Univ of Science 62/73
Computational Physics 1, Hanoi Univ of Science 69/73 Computational Physics 1, Hanoi Univ of Science 70/73
Exercises Exercises
The function f(x)=tanh(x) has a root at x = 0. Using one of the methods to find solutions for
the following system of non-linear equations:
Write a program to show that the Newton-
Raphson method does not converge for an a) x4+sin(x2+y2)=5,
initial guess of x>1. y4+cos(x2-y2)=1.
Can you understand what's going wrong by
considering a graph of tanh(x) ? b) 3x1 − cos(x2x3) −1/2=0,
Derive the critical value of the initial guess x12− 81(x2 + 0.1)2 + sin x3 + 1.06 = 0,
above which convergence will not occur.
exp(-x1x2) + 20 x3 + (10 pi/3 − 1) = 0.
Try to solve the problem using the secant
method.
Computational Physics 1, Hanoi Univ of Science 71/73 Computational Physics 1, Hanoi Univ of Science 72/73
Prof. Dr Sonnet Nguyen HUS, VNU
[email protected] Computational Physics 1
Thank you!