Week 2 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Roots of Equations

Dr. Meead Saberi


Research Centre for Integrated Transport
Innovation (rCITI)
School of Civil and Environmental Engineering
Remember?
Solving the following

! " = $" % + '" + ( = 0

−' ± '% − 4$(


"=
2$
How about this one?
Solving the following

! " = $ %& − " = 0

No analytical solution!
Graphical solution
! " = $ %& − " = 0

Some where around here


Can we do better?
Yes, with “numerical method”.

There are various numerical methods such as “bracketing


methods” or “open methods” that help us find real or complex
roots of any equation with different degree of precision.
Graphical methods
Simplest possible method to estimate the root of the equation
f(x)=0

Remember the parachutist example again and the speed equation.

#$ +
!= (1 − ) * -
, )
%

Suppose we had to determine the drag coefficient c for a


parachutist of a given mass to attain a prescribed velocity.
Example
Let’s re-express the equation as

$% )
*
,
! " = 1−( + −-
"

We now use the graphical approach to determine c needed for a


parachutist of mass m = 68.1 kg to have a velocity of 40 m/s after
free-falling for time t = 10 sec. Acceleration due to gravity is 9.81
m/s2.
Example
9.81(68.1) .
- /0.1 12
! " = 1−, − 40
"

668.06
! " = 1 − , -2.15/056. − 40
"

c f(c)
4 34.190
8 17.712
12 6.114
16 -2.230
20 -8.368
Bisection Method
When applying the graphical technique, we saw that f(x) changes
sign on opposite sides of the root.

So, if f(x) is real and continuous in


the interval from xl and xu and f(xl)
and f(xu) have opposite signs that,

! "# ! "$ < 0

Then, there is at least one real root


between xl and xu.
"# "$
Bisection Method
It’s also known as “binary chopping”, “interval halving”, or
“Bolzano’s method”.

Bisection method uses an incremental search to find the root.

We start with an interval and always divide it into half. If the


function changes sign over the new interval, the value at midpoint
is evaluated. We keep doing this until we obtain the root to a
precision we’d like.
Bisection Method
Bisection Method
Example
Use bisection method to find the root of the following equation.
Similar to previous example.

668.06
! " = 1 − * +,.-./0.12 − 40
"
Example
First step is to guess an initial xl and xu.
We can use the graphical method.

So, let’s start with 12 and 16 that


!" = 12
!& = 16

We then divide it by half to get the first


guess root
12 + 16
!( = = 14
2
Iteration 1
We now check the conditions and
compute the function value at the lower
bound and the midpoint.

! 12 ! 14 = 9.850 > 0

Since this is greater than zero, it means


the true root does not lie between 12
and 14. Instead, it should be between 14
and 16. So, we now consider 14 and 16
as new lower and upper bounds.
Iteration 2
So, let’s start again with 14 and 16 that

!" = 14
!& = 16

We then divide it by half to get the


second guess of the root

14 + 16
!( = = 15
2
Iteration 2
We again check the conditions and
compute the function value at the lower
bound and the midpoint.

! 14 ! 15 = −0.619 < 0

This is now smaller than zero, it means


the true root really lies between 14 and
15. So, we now consider 14 and 15 as
new lower and upper bounds. We repeat
the process.
Iteration 3
So, let’s start again with 14 and 15 that

!" = 14
!& = 15

We then divide it by half to get the


second guess of the root

14 + 15
!( = = 14.5
2
Iteration 3
Doing this for 3 iterations, we can stop
here and consider 14.5 as an
approximation of the real root.

!" = 14.5

If not happy with accuracy, you can


continue a one or more iterations.

The real root is 14.8011, anyways.


When should we really stop?
Let’s estimate an error and set an objective as termination
criteria

&'()$ *+,
$% %
!" = &'(
$%
100%

We can now say, for example, we are happy if !" is smaller


than 1%.
Checking the termination criteria
iteration xl xu xr !"
1 12 16 14 -
2 14 16 15 6.667
3 14 15 14.5 3.448
4 14.5 15 14.75 1.695
5 14.75 15 14.875 0.840
But what if we didn’t really have
the lower and upper bound guess?
Bisection method was a type of “bracketing method” which
requires lower and upper bound guesses to start.

In contrast, we have “open methods” which only requires


one single starting point or two points that do no necessarily
bracket the root.
Bracketing vs. Open Methods

Diverging

Converging
Newton-Raphson Method
If the initial guess at the root is xi, a tangent can be extended from
the point [xi,f(xi)]. The point where this tangent crosses the x axis
usually represents an improved estimate of the root.
Newton-Raphson Method
Newton-Raphson Formula
Estimating the slope

"(#$ ) − 0
"! #$ =
#$ − #$*+

Re-arranging the formula


"(#$ )
#$*+ = #$ −
"! #$
Example
Use the Newton-Raphson method to estimate the root of the
following function, employing an initial guess of !" = 0.

% ! = & '( − !
Let’s apply NR formula
! " = $ %& − "

!( ") = −$ %& − 1

/(+, )
+,-. = +, −
/( +,
$ %&3 − ")
")-2 = ") − %&
−$ 3 − 1
Iterative process
Starting with an initial guess of !" = 0

iteration !% &' (%)


0 0 -
1 0.5 100
2 0.566311003 11.71
3 0.567143165 0.15
4 0.567143290 0.00
Did you notice the convergence rate?
From iteration 1 to 2, the error reduced from 100% to 11.71%.
From iteration 2 to 3, the error further reduced to 0.15%.

The Taylor series derivation of the Newton-Raphson formula


provides theoretical insight regarding the rate of convergence
as expressed as !"#$ = & !"' . The error is roughly
proportional to the square of the previous error.

)(+" )
)(+"#$) ≅ )(+" ) + )′(+" )(+"#$−+" ) +"#$ = +" −
)1 +"
Another example
Use the Newton-Raphson method to estimate the root of the
following function, employing an initial guess of !" = 0.5.

' ! = !(" − 1
Let’s apply NR formula
! " = "$% − 1

!( ") = 10" +

0(,- )
,-./ = ,- −
0( ,-
") $% − 1
").$ = ") −
10") +
Iterative process
iteration !" #$ (%)
0 0.5 -
1 51.65 99.03
2 46.485 -11.11
3 41.8365 -11.11
4 37.652 -11.11
5 33.887565 -11.11
… … …
infinity 1.0000
Was the convergence normal?
From iteration 1 to 2, the error reduced from 99% to 11%.
However, since iteration 2, the convergence has been super slow.

But why?

Newton-Raphson method may perform poorly in some


situations such as “multiple roots”.
Newton-Raphson pitfalls
Secant method
A problem with Newton-Raphson method is the need to take the
derivation. For certain functions, taking derivatives may be
extremely difficult or inconvenient.

Backward finite divided difference

" #$&' − "(#$ )


"! #$ ≅
#$&' − #$
Secant formula
Let’s now replace the “backward finite divided difference” in the
Newton-Raphson formula.

"(#$ ) 0(-. )(-.&/ − -. )


#$+' = #$ − -.+/ = -. −
"! #$ 0 -.&/ − 0(-. )

Backward finite divided difference


" #$&' − "(#$)
"! #$ ≅
#$&' − #$
Example
Use the Secant method to estimate the root of the following
function, employing an initial estimates of !"# = 0 !& = 1.

( ! = ) "* − !
First iteration
"#$ = 0 ! "#$ = 1.0000

") = 1 ! ") = −0.63212

! ". ".#$ − ".


"./$ = ". − = 0.61270
! ".#$ − ! ".

12 = 8.0%
Second iteration
"- = 1 ! "#$ = −0.63212

"$ = 0.61270 ! "- = −0.07081

! "0 "0#$ − "0


"01$ = "0 − = 0.56384
! "0#$ − ! "0

45 = 0.58%
Comparison of
convergence rates

! " = $ %& − "

You might also like