Uploaded by EE19B030 NANDIRAJU ABHAY KUMARA SRI KRISHNA

CS3109_Lec-2

advertisement
Computational Engineering Numerical Methods
Dr. Kalidas Yeturu
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Roots of functions
• Motivation
– Very generic, applicable in different engineering
contexts
– Solving gradient function equals 0
– Plotting of contours
• Some of the popular examples
– Matlab – roots() and fzero() functions
– Python – scipy.optimize.root()
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Definition and examples
•
•
Given 𝑓 π‘₯
Roots are a set of values of x, ∃π‘₯ ∢ π‘₯: 𝑓 π‘₯ = 0
•
Simple equations
–
–
𝑓 π‘₯ = π‘šπ‘₯ + 𝑐
𝑓 π‘₯ = π‘Žπ‘₯ 2 + 𝑏π‘₯ + 𝑐 →
π‘₯=
−𝑏 − 𝑏 2 − 4π‘Žπ‘ −𝑏 + 𝑏 2 − 4π‘Žπ‘
,
2π‘Ž
2π‘Ž
Need sophisticated methods for finding roots of higher order and transcendental functions
•
Higher order polynomials
–
•
Transcendental equations
–
–
•
𝑓 π‘₯ = 5x 2 − x 3 + 7x 6
𝑓 π‘₯ = ln (x 2 ) − 1
𝑓 π‘₯ = e−0.2π‘₯ sin(3x − 0.5)
Types of methods
–
–
Single real root detection
Determining all roots both real and complex
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Root detection by visual inspection of
plots
• 𝑓 𝑐 =
π‘”π‘š
𝑐
1−𝑒
−𝑐
∗𝑑
π‘š
−𝑣
• 𝑑 = 10, 𝑔 = 9.8, 𝑣 = 40, π‘š = 68.1
• Plot and examine where it intersects X axis
• Root ~ 14.75
Issues
•
•
•
•
Error prone
Subjective
Not scalable (imagine,
we need it as a routine
invoked 1 million times)
Difficult for multivariate
scenarios
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Algorithms for root finding
• Bracketing methods
– Where root exists in an interval
– Bisection
– Regula Falsi
• Open methods
– Where starting from a single point, a sequence of steps will lead
to root
– Simple Fixed Point
– Newton-Raphson
– Secant Method
• Iterative in nature
– New value at time step t+1 depends of value at time step t
• Special cases and convergence aspects
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Root finding – Bracketing methods
• Given an interval of coordinates on X
axis
• Determine a point in the closed
interval as root
• Case (a) – Root does not exist in the
interval
• Case (b) – Single root exists
• Case (c) – Two roots exist
• Case (d) – Multiple roots exist
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Bracketing methods…
Same sign
0 roots
Same sign
Even number
of roots
Opposite sign
1 roots
Same sign
Opposite sign
2 roots
Odd number
of roots
Opposite sign
3 roots
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Bracketing methods…
• Opposite signs
– Case (e): Function is
tangential to X axis
:Two roots
– Case (f): Function is
discontinuous: Two
roots
(e)
• Same sign, function
touches X axis
– Case (g) : One root
• These are special
cases, need to handled
separately
(f)
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
(g)
Bracketing methods – Bisection/Bolzano method
1.
2.
3.
Choose xl and xu such that function
changes sign f xl ∗ f xu < 0
π‘₯ +π‘₯
Determine mid point xr = 𝑙 𝑒
2
Evaluate cases
– If f xl ∗ f xr < 0
Root lies between [xl and xr]
Set xu = xr
Goto Step 2
f(xu)
f(xl)
– If f xl ∗ f xr > 0
xl
Root lies between [xr and xu]
Set xl = xr
Goto Step 2
π‘₯π‘Ÿ =
– If f xl ∗ f xr = 0
xr is the root
Break from loop
• Report xr
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
xu
π‘₯𝑙 + π‘₯𝑒
2
Bisection method…
Input initial xr
Avoid divide by 0
π‘₯π‘Ÿπ‘›π‘’π‘€ − π‘₯π‘Ÿπ‘œπ‘™π‘‘
πœ€π‘Ž =
∗ 100%
π‘₯π‘Ÿπ‘›π‘’π‘€
π‘‘π‘Ÿπ‘’π‘’ − π‘₯π‘Ÿπ‘›π‘’π‘€
πœ€π‘‘ =
∗ 100%
π‘‘π‘Ÿπ‘’π‘’
Set error to 0
Error is small
Number of iterations is over
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Bisection method…!
Improved Bisection method
n+1 evaluations of f(x)
2n evaluations of f(x)
One time evaluation
before the loop
Single invocation
of f(x) inside the loop
Two times f(x) evaluations
Remember the value
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Bracketing methods – Regula Falsi Method
•
Consider triangles βˆ†π΄π΅πΆ and
βˆ†πΆπ·πΈ
E
•
Vertical angles are same ‫= 𝐡𝐢𝐴ۦ‬
‫𝐷𝐢𝐸ۦ‬
•
Ratio of opposite side by adjacent
𝐸𝐷
𝐴𝐡
sides are same οƒ  𝐢𝐷 = 𝐴𝐢
•
Translating the above ratio to
function values and X coordinates
𝑓(π‘₯𝑒 )
−𝑓 π‘₯𝑙
=
(π‘₯𝑒 − π‘₯π‘Ÿ ) (π‘₯π‘Ÿ − π‘₯𝑙 )
•
After rearranging terms, we have
𝑓 π‘₯𝑒 (π‘₯𝑙 − π‘₯𝑒 )
π‘₯π‘Ÿ = π‘₯𝑒 −
𝑓 π‘₯𝑙 − 𝑓 π‘₯𝑒
C
A
D
B
Idea – As the bracket is close to the root,
curve segment is nearly a straight line…
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Regula Falsi method…
1.
2.
1.
Choose xl and xu such that function
changes sign f xl ∗ f xu < 0
Determine mid point
𝑓 π‘₯𝑒 (π‘₯𝑙 − π‘₯𝑒 )
π‘₯π‘Ÿ = π‘₯𝑒 −
𝑓 π‘₯𝑙 − 𝑓 π‘₯𝑒
Evaluate cases
– If f xl ∗ f xr < 0
Root lies between [xl and xr]
Set xu = xr
Goto Step 2
– If f xl ∗ f xr > 0
Root lies between [xr and xu]
Set xl = xr
Goto Step 2
– If f xl ∗ f xr = 0
xr is the root
Break from loop
•
Report xr
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Regula Falsi method…
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Regula Falsi method…
Different curves
have different convergence
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Regula Falsi method…
Enhanced approach
Naïve approach
1.
2.
1.
Choose xl and xu such that function
changes sign f xl ∗ f xu < 0
Determine mid point
𝑓 π‘₯𝑒 (π‘₯𝑙 − π‘₯𝑒 )
π‘₯π‘Ÿ = π‘₯𝑒 −
𝑓 π‘₯𝑙 − 𝑓 π‘₯𝑒
Evaluate cases
–
If f xl ∗ f xr < 0
Root lies between [xl and xr]
Set xu = xr
Goto Step 2
–
If f xl ∗ f xr > 0
Root lies between [xr and xu]
Set xl = xr
Goto Step 2
–
If f xl ∗ f xr = 0
xr is the root
Break from loop
•
Report xr
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Regula Falsi method…
𝒙𝒖 is not moving
…
…
…
…
𝑓 π‘₯𝑙 < 0
𝑓 π‘₯𝑒 (π‘₯𝑙 − π‘₯𝑒 )
𝑓 π‘₯𝑙 − 𝑓 π‘₯𝑒
𝑓(π‘₯𝑒 )
(π‘₯𝑙 − π‘₯𝑒 )
π‘₯′π‘Ÿ = π‘₯𝑒 − 2
𝑓 π‘₯
𝑓 π‘₯𝑙 − 2𝑒
Let π‘₯π‘Ÿ − π‘₯π‘Ÿ′ > 0 → 𝑓 π‘₯𝑙 > 0 Ends up in a contradiction!
⇒ π‘₯π‘Ÿ < π‘₯π‘Ÿ′
π‘₯π‘Ÿ = π‘₯𝑒 −
xr
xl
xu
i.e. root estimate moves right after 𝑓 π‘₯𝑒 ←
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
𝑓(π‘₯𝑒 )
2
Bracketing interval detection
Upper bound
Lower bound
Computation Engineering course, IIT
Tirupati - Dr. Kalidas Yeturu
Download