This document discusses various numerical methods for finding the roots of functions, including graphical methods, Newton's method, secant method, and bisection method. It provides examples of applying these methods to find the roots of example functions. Newton's and secant methods are shown to converge rapidly, finding roots within 6 iterations for one example problem. The bisection method is also demonstrated on the function x^2 - 4x + 3, finding roots that agree with the analytical solutions. The document provides information on roots, functions, and iterative algorithms for root-finding.
ICT Role in 21st Century Education & its Challenges.pptx
03 finding roots
1. 0101011
0000000
1110100
0110001
1
0
Finding Roots
Sparisoma Viridi
Nuclear Physics and Biophysics Research Division
Institut Teknologi Bandung, Bandung 40132, Indonesia
dudung@fi.itb.ac.id
v2011.09.20 FI3102 Computational Physics 1
2. 0101011
0000000
1110100
0110001 Outline
1
• Function and roots
0
• A simple physical problem and its solution
• Several methods in finding roots
• Graphical method
• Newton’s method, secant method
• Bisection method
• References
v2011.09.20 FI3102 Computational Physics 2
3. 0101011
0000000
1110100
0110001 Function
1
• Function:
0
– Output: f(x)
– Input: x (the argument)
• The argument can be
a real number or
elements of a given
set (matrix, vector, etc)
• See reference [1]
v2011.09.20 FI3102 Computational Physics 3
4. 0101011
0000000
1110100
0110001 Roots
1
• Argument that makes a function to
0
produce zero output [2, 3]
• Argument that make two functions to
produce same output [4]
• Question 1. Is the second definition
actually the same as the first one?
v2011.09.20 FI3102 Computational Physics 4
5. 0101011
0000000
1110100
0110001 Roots (cont.)
1
• Example
0
of roots for
f(x) = cos (x)
in interval
[-2π,2π],
see [5]
v2011.09.20 FI3102 Computational Physics 5
6. 0101011
0000000
1110100
0110001 Roots (cont.)
1
• Say that there are two functions:
0
– First function is f(x)
– Second function is g(x)
• The second definition of roots is argument
that makes two functions produce same
output
• If x is a root than f(x) = g(x)
v2011.09.20 FI3102 Computational Physics 6
7. 0101011
0000000
1110100
0110001 Roots (cont.)
1
• Or, we can introduce a new function
0
– The new function is h(x) = f(x) – g(x)
• If x is a root, it makes f(x) = g(x)
• If x is a root, it also makes h(x) = 0
• So, both definitions are actually the same
(Answer 1)
v2011.09.20 FI3102 Computational Physics 7
8. 0101011
0000000
1110100
0110001 A simple physical problem
1
• A ball is launched from bottom of a incline
0
plane as illustrated below, find where and
when does it hit
the plane!
v0 H (xH, yH)
α
β
O (0, 0)
v2011.09.20 FI3102 Computational Physics 8
9. 0101011
0000000
1110100
0110001Solving the problem analytically
1
• The ball motions in x and y direction as
0
function of time t are
x(t) = v0 [cos (α + β)] t
y(t) = v0 [sin (α + β)] t – ½ gt2
then y(t) = y[t(x)] = y(x) will give
y = f(x) = [tan (α + β)] x – [g / 2v02 cos2(α + β)] x2
• The equation of incline plane is
y = g(x) = [tan β] x
v2011.09.20 FI3102 Computational Physics 9
10. 0101011
0000000
1110100
0110001 The roots of the problem
1
• In this case we can use second definition
0
of roots, so
f(x) = g(x) → x is a root
• Or we construct a new function h(x)
h(x) = f(x) – g(x)
= [tan (α + β) – tan β] x – [g/2v02 cos2(α + β)] x2
• The view of both definition in finding roots
will be shown in the next slide
v2011.09.20 FI3102 Computational Physics 10
12. 0101011
0000000
1110100
0110001 Graphics of .. (cont.)
1
• Even both graphics show different curve,
0
but they give the same value of x (the root
we want to find)
• Parameters are:
α = π/6, β = π/6, v0 = 5, g = 10,
x0 = 0, y0 = 0, ∆x = 0.025
• The root should be around x = 1.4
• And vertical position around y = 0.85
•
v2011.09.20 FI3102 Computational Physics 12
13. 0101011
0000000
1110100
0110001 Analytical solution
1
• Using quadratic formula we can find the
0
roots
• But this case is simpler since other root
are 0
• Then it can found that
x = [tan (α + β) – tan β] [2v02 cos2(α + β)] / g
= 1.443376
f(x) = f(1.443376) = 0.833333
v2011.09.20 FI3102 Computational Physics 13
14. 0101011
0000000
1110100
0110001 Analytical solution (cont.)
1
• Question 2. If we already know the
0
analytical solution, then for what is it the
numerical solution?
v2011.09.20 FI3102 Computational Physics 14
15. 0101011
0000000
1110100
0110001 Analytical solution (cont.)
1
• Answer 2. It is for testing whether the
0
numerical solution has the same value as
the analytical one
• You can not (or should not) use your
method or algorithm or code to some
problem, before you test it
• Test it for the problem that you have
already known its solution
v2011.09.20 FI3102 Computational Physics 15
17. 0101011
0000000
1110100
0110001 Graphical method
1
• It uses graphics to find the root
0
• It can accommodate the first and second
definition of the root
• It is rather not accurate since it depends
on our judgment to determine whether
f(x) = g(x) or h(x) = 0
• Some software, i.e. gnuplot, has feature to
return the position of mouse pointer
v2011.09.20 FI3102 Computational Physics 17
18. 0101011
0000000
1110100
0110001 Graphical method (cont.)
1
• We (actually) already used this method
0
root
analytical
solution
x = 1.443376
graphical
y = 0.833333 solution
x = 1.4
y = 0.85
v2011.09.20 FI3102 Computational Physics 18
19. 0101011
0000000
1110100
0110001 Newton’s method
1
• Taylor’s expansion around x = a will give
0
f (x) ≈ f (a) + (x – a)f '(a)
with assumption that (x – a) small enough
to terminate next term in the series
• By setting x = 0 (the target) we can find
that x = a – f (a) / f ' (a)
• Or, the iterative expression is
xi+1 = xi – f (xi) / f '(xi)
v2011.09.20 FI3102 Computational Physics 19
20. 0101011
0000000
1110100
0110001 Newton method (cont.)
1
• Question 3. Write the iterative expression
0
for previous problem using Newton’s
method [use h(x) instead of f(x) and g(x)]
and show also the result
• From previous problem:
h(x) = [tan (α + β) – tan β] x – [g/2v02 cos2(α + β)] x2
h'(x) = ?
xi+1 = xi + ?
v2011.09.20 FI3102 Computational Physics 20
21. 0101011
0000000
1110100
0110001 Newton method (cont.)
1
• Answer 3. It can be found that
0
g 2
[tan (α + β ) − tan β ]x i − xi
2 v o cos (α + β )
2 2
xi +1 = xi −
[tan (α + β ) − tan β ] − g 2
2 xi
v o cos (α + β )
2
v2011.09.20 FI3102 Computational Physics 21
22. 0101011
0000000
1110100
0110001 Newton method (cont.)
1
• And the result is
0
• Only need about
6 iterations
• x = 1.443376
(analytical solu-
tion is 1.443376)
• In a good agree-
ment wtih a.s.
v2011.09.20 FI3102 Computational Physics 22
23. 0101011
0000000
1110100
0110001 Secant method
1
• In Newton’s method we must know or
0
calculate the derivative of f(x)
• In secant method it is calculated using
f '(xi) ≈ [f(xi) – f(xi-1)] / (xi – xi-1)
• And this gives the iterative expression
xi+1 = xi – (xi – xi-1) f (xi) / [f(xi) – f(xi-1)]
with xi and xi-1 as starting values
v2011.09.20 FI3102 Computational Physics 23
24. 0101011
0000000
1110100
0110001 Secant method (cont.)
1
• Secant method (right) is more efficient
0
than Newton’s method (left) as illustrated
in [3]
v2011.09.20 FI3102 Computational Physics 24
25. 0101011
0000000
1110100
0110001 Secant method (cont.)
1
• The result is
0
• Only (also) need
~ 6 iterations
• x = 1.443376
(analytical solu-
tion is 1.443376)
• In a good agree-
ment wtih a.s.
v2011.09.20 FI3102 Computational Physics 25
27. 0101011
0000000
1110100
0110001 Newton’s vs secant ... (cont.)
1
• For Newton’s method x0 = 1
0
• For secant method x0 = 1 and x1 = 1.1
• Both methods gives similar result at about
10 iterations (difference less than 10–16)
v2011.09.20 FI3102 Computational Physics 27
28. 0101011
0000000
1110100
0110001 Bisection method
1
• Suppose that we have a function as in [6]
0
v2011.09.20 FI3102 Computational Physics 28
32. 0101011
0000000
1110100
0110001 Example: x2 – 4x + 3 (cont.)
1
• The roots have been found
0
x1 ≈ 2.999 (analytical solution is 3)
x2 ≈ 1.001 (analytical solution is 1)
• Further iteration (more than 10) can be
performed to get nearer results
• What about muliple roots? Any idea?
v2011.09.20 FI3102 Computational Physics 32
33. 0101011
0000000
1110100
0110001 Multiple roots
1
• After finding one root the original equation
0
must be modified
• Question 4. Do you know how to modify
the original equation in order to obtain
other root?
v2011.09.20 FI3102 Computational Physics 33
34. 0101011
0000000
1110100
0110001 Multiple roots (cont.)
1
• Answer 4. Divide the original equation
0
with all previous found root(s) in order to
avoid the previous root(s) to be found
again
• Could you write the algorithm together with
the finding roots algorithm?
v2011.09.20 FI3102 Computational Physics 34
36. 0101011
0000000
1110100
0110001 Summary
1
• Three different methods for finding roots
0
have been presented
• A simple physical problem is used to
illustrate the first two method
• Other problems which need to find roots
can also be solved using given methods
• Algorithm to solve multiple roots problem
has not yet been discussed (only the idea)
v2011.09.20 FI3102 Computational Physics 36
37. 0101011
0000000
1110100
0110001 References
1
1. Wikipedia contributors, “Function (mathe-
0
matics)”, Wikipedia, The Free
Encyclopedia, 18 September 2011, 10:26
UTC, oldid:451121927> [2011.09.19
07.31+07]
2. Paul L. DeVries, “A First Course in
Computational Physics”, John Wiley &
Sons, New York, First Edition, 1994, pp.
41-85
v2011.09.20 FI3102 Computational Physics 37
38. 0101011
0000000
1110100
0110001 References (cont.)
1
3. Steven E. Koonin and Dawn C. Meredith,
0
“Computational Physics Fortran Version”,
Westview, Canada, First Edition, 1990,
pp. 11-14
4. Gisela Engeln-Müllges, Klaus
Niederdrenk, and Reinhard Wodicka,
“Numerik-Algorithmen”, Springer, Berlin,
10. Auflage, 2011, pp.25-90
v2011.09.20 FI3102 Computational Physics 38
39. 0101011
0000000
1110100
0110001 References (cont.)
1
5. Wikipedia contributors, “Zero of a
0
function”, Wikipedia, The Free
Encyclopedia, 12 September 2011, 02:23
UTC, oldid:449926806 [2011.09.19
07.48+07]
6. Sparisoma Viridi, “Computational
Physics”, Version 3, 2011, pp. 49-53
v2011.09.20 FI3102 Computational Physics 39