You are on page 1of 21

Numerical analysis

Numerical Analysis
Prepared by Eng. Maged Kamel
Prepared By Eng Maged kamel
Objective of lecture.

• Difference between Numerical and Analytical


methods.

• Methods used to get root of function , comparing


between Analytical and Numerical.

• Bisecting method for root finding.

• Method of False position for root finding.


Numerical Analysis

Numerical analysis involves the study of all the methods of computing numerical
data.

Difference between Numerical and Analytical


method.

• Numerical methods provide approximation to the problem in question,


while analytical method give exact solutions ,with more time
consuming.

• Numerical method give solution at certain point only, like finite


difference ,finite element ,these methods are considered Numerical
since they give results at certain points.
Finding the +ve root of function
What is the root of a function?

The roots of function ,or zeros, are the


points where the function crosses the x axis
,where the value of f(x)=0

We let f(x)=y=0
(x+2)*(x-2)=0
So x=-2 or x=+2 are the zeros
To check substitute in the value of x
Y=(2)^2-4= 4-4=0
Y=(-2)^2-4=4-4=0
Synthetic Division
To get the zero for a function ,some times we are guessing the values for x ,so
called rational roots test
Rational roots test is a handy way of obtaining a list of useful first guesses when
you are trying to find the zeroes (roots) of a polynomial.
Example: solve the function y=𝑥 2 − 5𝑥 + 6

Solution : we examine the leading coefficient (X^2) we have +1


constant +6 what will be the possible values of x
1,6 2,3
+1,-1,+2,-2,+3,-3,+6,-6. for constants , ± , ±
1,1 1,1
Next step we let x+3=0 as first trial x=-3
1-We write coefficients only without x^2 or x
-3 1 -5 +6

+24 2- Coefficient of x^2 carrying down


-3
3-multiply -3*+1.
-8 4- add (-3)+(-5)=-8
1 +30
5-multiply (-8)*(-3)=24
6-add +24 to +6=+30.
Continue for roots finding.
Example: solve the function y=x2 – 5x +6

2nd trial :
Next step we let X-2=0 i.e x=2
+2 1 -5 +6

+2 -6
(x-2)*(x-3)=0 the result shows that we
-3
1 0 have two roots x1=2,x2=3
Our example is :f(x) =𝑥 3 − 6𝑥 2 + 11 ∗ x − 6, find the zeros for the function
by analytical method and further by Numerical method.
Solution:
Leading coefficient ±1
1,6,2,3
Constant coefficient ±1,6,2,3 Our choices: ± as zeros
1

If x=2 our first choice i,e


2 1 -6 11 -6
X-2=0
2 -8 +6 (x-2)*(x^2-4x+3)=0
1 -4 3 0
This formula can be again simplified as
(x-2)*(x-3)*(x-1)=0

We have three solutions X1=2 &X2=3 & X3=1


Bracketing method
Bisecting method.
1-This method depends on two values for F(x) of opposite signs.
a with –ve sign& b with +ve sign, for –ve value ,approaching from –ve
to +ve ,assign left bracket {
And ending with +ve value, assign right hand bracket }

2- Our zero value must be in between, so we take an


intermediate point between (𝑎1 & 𝑏1 ).
3- Our (𝑥1 ,first trial=0.50*((𝑎1 +(𝑏1 ))

4- check f((𝑥1 ) .

5- if f((𝑎1 )*f(𝑥1 ) <0 ,then they are opposite to each other , (𝑥1 will have right hand bracket }
if not then (𝑥1 ) then x1 will be having left bracket ,get new point
Take intermediate point with (𝑥2 , as 2nd trial= 0.50*((𝑎1 +(𝑏1 ) get f(x2)
Bracketing method
Bisecting method.
5- if f((𝑎1 )*f(𝑥1 ) < 0 ,then they are opposite to each other , (𝑥1 will have right hand
bracket }
We will bisect the distance between 𝑎1 & 𝑥1 and get a new point 𝑥2

if f((𝑎1 )*f(𝑥1 ) >0 X1 will be having left bracket ,get new point
Take intermediate point ,between 𝑥1 and 𝐵1 with (𝑥2 ,

as 2nd trial= 0.50*((𝑥1 +(𝑏1 ) ,then estimate 𝑓(𝑥2 )

6- check if f((𝑥2 )*f(𝑏1 ) ) < 0,then these points will be opposite to each other .

7- Continue the process by bisecting the distance between point having opposite f(x) value till you
approach to the zero point.
Example if :f(x)=X^3-6X^2+11x-6 ,find the zeros for the function by bisecting
method.
Solution:
1- Try several values of x that give different values of f(x)
for X =4 f(4) = 4^3-6*4^2+11*(4)-6=64-96+44-6=+6
for x=2.50 then f(2.50)= 2.5^3 - 6*2.5^2+11*(2.5)-6=15.625-37.50+27.50-6=-0.375

(3.25,0.7031) (4,+6)
a0=2.50 X3=0.50*(2.875+3.25)=3.0625
X1=3.25 f(3.0625)=+0.1369
(2.50,-0.375) b=4
}
{ { X2=2.875
(2.875,-0.2050)
X4=0.50*(2.875+3.0625)=2.96875
X2=2.875 { } X1=3.25 f(2.96875=-0.0596

X2=2.875 { } X3=3.0625
Zero point at x=3
X4=2.968 { } X3=3.0625 X5=0.50*(2.968+3.0625)=3.015
} X5=3.015 f(3.015)=0.032
1st iteration.
Take X1=0.50*(4+2.50)=3.25
f(3.25)=+0.7031
f(2.50)*f(3.25)=- 0.375*(+0.7031)=- 0.26367
they are opposite to each other
2nd iteration.
Take X2=0.50*(2.50+3.25)=2.875
f(2.875)=-0.20508
f(2.875)*f(4)=-0.20508*6 =-1.23047

Take X3=0.50*(4+2.875)=3.0625 3rd iteration.


f(3.0625)=+0.1369
f(2.875)*f(3.0625)=-0.20508*(+0.1369)=-0.03
4rth iteration.

Take X4=0.50*(2.875+3.0625)=2.968

f(2.968) =-0.06

f(3.0625)*f(2.968)=+0.1369*(-0.06)=-0.01

5th iteration
Take X5=0.50*(2.968+3.0625)=3.015

f(3.015) =+0.032

f(3.015)*f(2.968)=+0.032*(-0.06)=-0.002

Solution is converging to x=3.00


Error estimation

Number of iteration n ≥ log10 (𝑏0 −𝑎0 ) −log10 ( 𝜀) / log10 2


In our example 𝑎0 =2.50 & 𝑏0 =4 for error tolerance of € =0.001
n≥ log10 (4 −2.5*1/ log10 2

−0.166091 − (−3 *1Τ0.301029 =10.55

Relative error =(x new-x old)/x new for x is value


estimated for zero f(x) value
Method of false position.(Regula falsi)

This method creates a false position ,


by joining the f(𝑏0 ) & f(𝑎0 ) by a chord
thus creating a new position of x root,
that is shifted from the original 𝑥𝑟 .
Instead of bisecting a new point will
be selected based on the next
relation.

𝑥𝑟 = (𝑏0 ∗ f(𝑎0 ) − 𝑎0 ∗ f(𝑏0 ))


f(𝑎0 ) − f(𝑏0 )
Note that 𝑥𝑟 is measured from left
When 𝑎0 at the left and 𝑏0 at the
right side

Check if f((𝑎0 )*f(𝑏1 ) <0 Check if f((𝑎0 )*f(𝑏1 ) >0


Example - If :f(x)=𝑥 3 − 6𝑥 2 + 11 ∗ x − 6, find the zeros for the function by
False position method, consider 𝑎0 = 2.5, 𝑏0 = 4 ,as before in the previous
method .
y

Solution (4,+6)
For 𝑎0 =2.5 put x=2.5
then f(4)= 2.53 − 6 ∗ 2.52 +11 ∗ 2.5 X1
= -0.375
𝑎0 =2.5 x
(2.588,-0.3847) 𝑏0 =4
(2.50,-0.375)
For 𝑏0 =4 put x=4 then f(4)= 43 − 6 ∗ 42 +11 ∗ 4
First iteration. = 64- 96+ 44 – 6 = +6

(4 ∗ (−0.375) − (2.50 ∗ 6)
= (4 ∗ −0.375) − (2.50 ∗ 6)
(−0.375 − 6)
= 2.588
(−0.375 − 6)

then f(2.588)= 2.5883 − 6 ∗ 2.5882 +11 ∗ 2.588 = -0.3847


f(2.588)*f(4)=-0.3847*+6=-2.3082 Our (𝑥1 ) will be our
new left bracket point
(4,+6)
X2=2.673

𝑥1 =(2.588)
𝑎0 =2.50
(2.50,-0.375) b=4
X1=2.588 { }
f(2.588)= -0.38469
X2 =2.673 {
}

Again put 𝑎0 =2.588 & 𝑏0 =4 }


Check if f((𝑥2 )*f(𝑏0 ) < 0 (4 ∗ (−0.38469) − (2.588 ∗ 6)
2nd iteration. 𝑥2 = 2.673 (−0.38469 − 6)

f(2.6732)= -0.36801 Check if f((𝑥2 )*f(𝑏0 ) > 0


f(2.6732)*f(4)=-0.36801*+6=-2.2084
f(2.6732)*f(4)=-(0.36801)*+6=-2.2084 Will be our new left
bracket point –proceed
to X3 (4,+6)
X2=2.673

𝑥1 =(2.588)
𝑎0 =2.50
(2.50,-0.375) b=4
X1=2.588 { }
3rd iteration.
X2 =2.673 {
}
(4 ∗ (−0.36801) − (2.6732 ∗ 6) X3 = 2.749 { }
(−0.36801 − 6) X4=2.8147 { }
X3= 2.7499
f(2.7499)*f(4)=-0.328*+6 = -1.9688
f(2.7499) )= 2.74993 − 6 ∗ 2.74992 +11 ∗ 2.7499 = = -0.328 Left bracket
f(2.7499)*f(4)=-0.328*+6 = -1.9688 Proceed to X4
Left bracket

X2=2.673 (4,+6)

𝑥1 =(2.588)
𝑎0 =2.50
(2.50,-0.375) b=4
X1=2.588 { }
4rth iteration.
X2 =2.673 {
}
(4 ∗ (−0.328) − (2.749 ∗ 6) X3 = 2.749 { }
(−0.328 − 6) X4=2.8147 { }
X4 = 2.8417
f(2.8417)*f(4)=-0.274*(+6 )= -1.643
f(2.8417) )= 2.84173 − 6 ∗ 2.84172 +11 ∗ 2.8417 = = -0.274 Left bracket
f(2.8417)*f(4)=-0.274*(+6 )= -1.643 Proceed to X5
Left bracket

X2=2.673 (4,+6)

𝑥1 =(2.588)
𝑎0 =2.50
(2.50,-0.375) b=4
X1=2.588 { }
5th iteration.
X2 =2.673 {
}
(4 ∗ (−0.274) − (2.8417 ∗ 6) X3 = 2.749 { }
(−0.274 − 6) X4=2.8147 { }
X5 = 2.866 X5=2.866 {
f(2.866) )= 2.88663 − 6 ∗ 2.8662 +11 ∗ 2.866 = = -0.216 f(2.866)*f(4)=-0.216*(+6 )= -1.9255
Left bracket
f(2.866)*f(4)=-0.216*(+6 )= -1.9255 Proceed to X6
Left bracket

X2=2.673 (4,+6)

𝑥1 =(2.588)
𝑎0 =2.50
(2.50,-0.375) b=4
X1=2.588 { }

X2 =2.673 {
}
X3 = 2.749 { }

X4=2.8147 { }
Iteration will continue till x =3.00 after 20 iteration
X5=2.866
{
Spread sheet data used for approximation

You might also like