Numerical Analysis 4 Class Environmental Department College of Engineering 2016-2017
Numerical Analysis 4 Class Environmental Department College of Engineering 2016-2017
Numerical Analysis 4 Class Environmental Department College of Engineering 2016-2017
4th Class
Environmental
Department
College Of Engineering
2016-2017
1/12/2017 1
Content: Numerical Analysis
3
Nonlinear Equation
Solvers
All Iterative
Part 2 3
Locating the Position of Roots
There exist a roots between these interval (-4, 0) and (4, 8).
Then there exist a roots between these interval (-2, 0), (0, 2), (2, 4) and
(4, 6).
Find the root of an equation
What Goes
Wrong?
1/12/2017 8
Bisection Method
f(b) is positive
xc= (a+b)/2
f(c) negative
xc = (0 + 1) /2 = 0.5,
f(0.5) = 0.125. Now f(a) and f(xc) has opposite signs
So, the next interval is [0, 0.5]
12
Bisection Method: Class Work
Ex.1 Find the approximate value of the following:
1 x3 4 x 1 0 where 0.001
2 e x 3x 0
3 x cos(x) 0
4 x tan( x) 1
5 f ( x) log( x) x 5
Ex.2 Find the real root of the equation f(x)=x3 – x – 1=
0 correct to 2 decimal places.(=0.01). Ans.: 1.325683
f(xi)
x f x Newton’s Method
i, i
f(xi )
xi 1 = xi - (1)
f (xi )
f(xi-1) Approximate the derivative
f ( xi ) f ( xi 1 )
X f ( xi ) (2)
xi xi 1
xi+2 xi+1 xi
16
Secant Method – Derivation
The secant method can also be derived from geometry:
f(x)
17
Algorithm for Secant Method
Step 1
Calculate the next estimate of the root from two initial guesses
f ( xi )( xi xi 1 )
xi 1 xi
f ( xi ) f ( xi 1 ) xi 1- xi
Find the absolute relative approximate error a = 100
xi 1
Step 2
Find if the absolute relative approximate error is greater
than the prespecified relative error tolerance.
If so, go back to step 1, else stop the algorithm.
Also check if the number of iterations has exceeded the
maximum number of iterations.
18
Algorithm
• Given two guesses x0, x1 near the root,
• If f x0 f x1 then
• Swap x0 and x1.
• Repeat
x0 x1
• Set 2 1 x x f x *
f x0 f x1
1
• Set x0 = x1
• Set x1 = x2
• Until f x2 < tolerance value.
Discussion of Secant Method
• The secant method has better convergence
than the bisection method .
• Because the root is not bracketed there are
pathological cases where the algorithm
diverges from the root.
• May fail if the function is not continuous.
Example :1
As an example of the secant method, suppose we wish to find a root of the function
f(x) = cos(x) + 2 sin(x) + x2. A closed form solution for x does not exist so we must use
a numerical technique. We will use x0 = 0 andx1 = -0.1 as our initial approximations.
We will let the two values εstep = 0.001 and εabs = 0.001 and we will halt after a
maximum of N = 100 iterations.
We will use four decimal digit arithmetic to find a solution and the resulting iteration is
shown in Table 1.
Table 1. The secant method applied to f(x) = cos(x) + 2 sin(x) + x2.
xn 1 xn f xn
xn 1 xn
f xn 1 f xn
Thus, with the last step, both halting
conditions are met, and therefore, after
six iterations, our approximation to the
root is -0.6595
x0 x1
x2 x1 f x1 *
f x0 f x1
Example: Use secant method of finding roots of the following
equations
1 x 3 0.1654 x 2 3.993 10 4 0 where 0.001
2 e x 3x 0
3 x 2 10 cos(x) 0
4 x tan( x) 1
5 f ( x) x 3 3 x 2
• Solution 1:
First we can find the interval which a roots contain it as:
[ 0.02, 0.05] when x0=0.02 and x1=0.05
Step:1 Let n=1
x0 f ( x1 ) x1 f ( x0 ) 0.02 f (0.05) 0.05 f (0.02)
x2 0.06461
f ( x1 ) f ( x0 ) f (0.05) f (0.02)
Regula-Falsi Method Or False Position
Type of Algorithm (Equation Solver)
The Regula-Falsi Method (sometimes called the False Position Method) is a
method used to find a numerical estimate of an equation.
This method attempts to solve an equation of the form f(x)=0. (This is very
common in most numerical analysis applications.) Any equation can be written in
this form.
Algorithm Requirements
This algorithm requires a function f(x) and two points a and b for which f(x) is
positive for one of the values and negative for the other. We can write this
condition as f(a)f(b)<0.
If the function f(x) is continuous on the interval [a,b] with f(a)f(b)<0, the algorithm
will eventually converge to a solution.
This algorithm can not be implemented to find a tangential root. That is a root that
is tangent to the x-axis and either positive or negative on both side of the root.
For example f(x)=(x-3)2, has a tangential root at x=3.
False Position
• The method of false position is seen as an improvement on the
secant method.
• The method of false position avoids the problems of the secant
method by ensuring that the root is bracketed between the two
starting points and remains bracketing between successive
pairs.
• Set x1 = x2
• Else Set x0 = x1
• End If
• Until f x2 < tolerance value.
This method achieves better convergence but a more complicated algorithm.
May fail if the function is not continuous.
Example
Lets look for a solution to the equation x3-2x-3=0.
We consider the function f(x)=x3-2x-3
On the interval [0,2] the function is negative at 0 and positive at 2. This means
that a=0 and b=2 (i.e. f(0)f(2)=(-3)(1)=-3<0, this means we can apply the
f (0)2 0
algorithm).
3(2) 6 3
xrfp 0
f (2) f (0) 1 3 4 2
3 21 This is negative and we will make the a =3/2
f ( xrfp ) f and b is the same and apply the same thing
2 8 to the interval [3/2,2].
3 f 32 2 32 3 821 12 3 21 54
xrfp
2 f (2) f 2 2 1 8
3 21
2 58 29
54 This is negative and we will make the a =54/29
f ( xrfp ) f 0.267785 and b is the same and apply the same thing to
29 the interval [54/29,2].
Example 1
Consider finding the root of f( x) = x2 - 3. Let εstep = 0.01, εabs = 0.01 and start with the
interval [1, 2].
Table 1. False-position method applied to f( x) = x2 - 3.
Thus, with the third iteration, we note that the last step 1.7273 → 1.7317 is less
than 0.01 and |f(1.7317)| < 0.01, and therefore we chose b = 1.7317 to be our
approximation of the root.
Note that after three iterations of the false-position method, we have an acceptable
answer (1.7317 where f(1.7317) = -0.0044) whereas with the bisection method, it
took seven iterations to find a (notable less accurate) acceptable answer (1.71344
where f(1.73144) = 0.0082)
Example 2
Consider finding the root of f(x) = e-x(3.2 sin(x) - 0.5 cos(x)) on the interval [3, 4], this
time with εstep = 0.001, εabs = 0.001.
Table 2. False-position method applied to f(x) = e-x(3.2 sin(x) - 0.5 cos(x)).
Thus, after the sixth iteration, we note that the final step, 3.2978 → 3.2969 has a size
less than 0.001 and |f(3.2969)| < 0.001 and therefore we chose b = 3.2969 to be our
approximation of the root.
In this case, the solution we found was not as good as the solution we found using the
bisection method (f(3.2963) = 0.000034799) however, we only used six instead of
eleven iterations.
END Lecture
5- Newton-Raphson Method
Given an approximate value of a root of an equation, a better and closer
approximation to the root can be found by using an iterative process called
Newton’s method or Newton-Raphson method.
Let x=x0 be an approximate value of one root of the equation f(x)=0. If x=x1 is
the exact value then
f(x1)=0 ……………. (1)
Where the difference between x0 and x1 is very small called h then
x1=x0+h
f(x1)=f(x0+h)=0
Expanding by Taylor’s theorem we get
h2 h3 …….. (2)
f ( x0 ) h f ( x0 )
f ( x0 )
f ( x 0 ) ... 0
2 6
Since h is small, neglecting all the powers of h above the first form (2), we get
f ( x0 ) h f ( x0 ) 0 approximately
f ( x0 ) f ( x0 )
h x1 x0 h x0
f ( x0 ) f ( x0 )
Similarly x2 denotes a better approximation, starting with x1 , we get
f ( x1 )
x 2 x1
f ( x1 )
Proceeding in this way we get
f ( xn )
xn 1 xn
f ( xn )
The above is a general formula, known as Newton-Raphson formula,
Geometrically, Newton’s method is equivalent to replacing a small arc of
the curve y=f(x) by a tangent line drawn to a point of the curve.
1
ii. k
where k are constant.
Theorem:- If g( [a, b]) [a, b] and /g’(x)/ ≤ L<1 for all x [a, b], then there
exist exactly one λ in [a, b] such that
λ=g(λ)
Proof: Exercise
Geometrically:
A solution of f(x)=0 is an intersection point of the graph f with the x-axis,
and the convergence test which are :-
1- If /g’(x0)/ is near 1 then the converge is slow “ monotonically ”.
2- If -1 < g’(x0) < 0 then we have an oscillatory convergence.
3- If g’(x0) is positive the convergence will be increasing or decreasing.
4- If g’(x0) >1 , then we will have diverges.
For example: Use iterative method to find the approximate roots, and determine
the convergence types of f(x) = x2 -2 x -3=0
Solution:
Numerical Solution of Non-Linear Simultaneous Equations
Consider the system involving two non-linear equations:
f(x, y)=0
g(x, y)=0 …………. (1)
With the initial approximate solution (x0 , y0), we will study three numerical
methods to solve this type of equations.
1- Iterative method:
Let f(x, y)=0
g(x, y)=0 …………. (1)
First can be written as the form
x=F(x , y)
y=G(x , y)
Starting by initial value (x0 , y0), can be extended to approximate solution
(xi , yi) of the iterative formula
xi+1=F(xi , yi)
yi+1=G(xi , yi) where i=1,2,3,…
Stop the iteration when xi 1 xi and yi 1 yi
What is a sufficient conditions for convergence of iteration method for solving
non-linear equations:
F G
1
x ( x0 , y 0 ) x ( x0 , y 0 )
and
F G
1
y ( x0 , y 0 )
y ( x0 , y 0 )
2- x2 – y2 -7=0
x2 + y2 - 25=0 where (x0 , y0)= (3 , 4)
Solution:
Let f(x , y) =2x2 – xy - 5x +1 =0
g(x, y) = x +3 Log(x)- y2 =0 …………… (1)
From equation (1) we have
x ( y 5) 1
x F ( x , y)
2
y x Log ( x) G ( x , y )
and
F G
0.246 1
y ( x0 , y 0 )
y ( x0 , y 0 )
2- Newton-Raphson Method
1- f(x, y) = 2x2 – xy - 5x +1 =0
g(x, y) = x +3 Log(x)- y2 =0 where (x0 , y0)= (3.5 , 2.5)
2- x2 – y2 -7=0
x2 + y2 - 25=0 where (x0 , y0)= (3 , 4)
3- x2 – 2x- y + 0.5=0
x2 + 4y2-4=0 at (2 , 0.25)
4- x2 + y2-2=0
xy-1=0 at (1 , 1)
Summary
Method Pros Cons
Bisection - Easy, Reliable, Convergent - Slow
- One function evaluation per - Needs an interval [a,b]
iteration containing the root, i.e.,
- No knowledge of derivative is f(a)f(b)<0
needed
Newton - Fast (if near the root) - May diverge
- Two function evaluations per - Needs derivative and an
iteration initial guess x0 such that
f’(x0) is nonzero
46