
Numerical Techniques:
Root Searching
Dr. Cem Özdo
˘
gan
LOGIK
Solving Nonlinear
Equations
Blackbody Radiation
Interval Halving (Bisection)
Linear Interpolation
Methods-The Secant
Method
Newton’s Method
4.11
Bisection II
•
A plot of f (x) is useful to know where to start.
•
Example: The function; f (x) = 3x + sin(x) − e
x
•
Look at to the plot of the function to learn where the
function crosses the x-axis.
1 imp ort numpy as np
2 from math i mpo rt
*
3 def f ( x ) :
4 r et ur n 3
*
x+s in ( x )−exp ( x )
5 x va l = [ ]
6 fu n va l = [ ]
7 k f i r s t =0. 0; k las t =2 .0; kincrem ent =0.01
8 f o r j i n np . arange ( k f i r s t , k l a s t +
kincr ement , kinc rement ) :
9 xv al . append ( j )
10 f un va l . append( f ( j ) )
11 i mport m at p lo t li b . p y pl ot as p l t
12 p l t . t i t l e ( ’ $ f ( x ) =3x+ sin ( x )−e^ x$ ’ )
13 p l t . x la be l ( ’X Value ’ )
14 p l t . y la be l ( ’ Func tion Value ’ )
15 p l t . p l o t ( x val , f un val , ’− ’ )
16 p l t . g ri d ( )
17 p l t . s ave fig ( ’ f u nc t io n_ plo t . eps ’ )
18 p l t . show( )
Figure: Code and plot of the
function:
f (x) = 3x + sin(x) − e
x
•
We see from the figure that indicates there ar e zeros at
about x = 0.35 and 1.9.