Professional Documents
Culture Documents
i2HjTU Lecture3 PDF
i2HjTU Lecture3 PDF
MECE 390-A1
Numerical Methods of Mechanical Engineering
Objective
1. Roots of functions
2. Iterative root finding schemes
3. Bisection methods
4. Condition for root bracketing
Many engineering and design problems involve finding roots (or zeros) of equations.
• 𝑦 = 𝑓 𝑥 satisfies 𝑓 𝑥𝑟𝑜𝑜𝑡 = 0 then 𝑥𝑟𝑜𝑜𝑡 is the solution of the equation 𝑓 𝑥 = 0.
𝑦2 − 𝑦1
(𝑥2 , 𝑦2 ) 𝑦= 𝑥 − 𝑥1 + 𝑦1
𝑥2 − 𝑥1
𝒙 𝑦 −𝑦
(𝑥1 , 𝑦1 ) where 𝑚 = 𝑥2−𝑥1 is the slope of 𝑦.
2 1
𝑦 = 2𝑥 2 + 3𝑥 − 7
• Unfortunately, the associated equation for cubic polynomials is a real mass and no such
equation exists for polynomials of order > 3.
• Similar ambiguities arise when trying to find the roots of e.g. 𝑦 = tan(ln(𝑥 2 )).
Q. What to do ?
Use data cursor… OR more elegant solution Use an iterative root finding schemes.
NOTE: In this course, we confine our analysis only to the cases with real roots.
Classification
1. Bracketing method
2. Open method
Bracketing methods
• In general, two initial points are used which bracket
𝑓 𝑥𝑈 root.
f(x) f(x)
• The function need to change the sign within this
interval.
xL root • Then the bracketing interval is reduced while
xu x continuing to bracket the root until the interval is
small enough.
𝑓 𝑥𝐿
𝑥𝐿 : lower bound, 𝑥𝑢 : upper bound
For Bracketing method, we will study two types of methods: 1) Bisection Method
2) False position method
MEC E 390 -A1
Bisection method 6
Bisection Pseudocode
Input: 𝑥𝐿 , 𝑥𝑈 , 𝑚𝑎𝑥𝑖𝑡, 𝜀 𝜀= tolerance, 𝑚𝑎𝑥𝑖𝑡: # of iteration
Check condition: [𝑥𝐿 , 𝑥𝑈 ] bracket a root
𝑓𝐿 = 𝑓(𝑥𝐿 ); 𝑓𝑈 = 𝑓(𝑥𝑈 )
f(x)
𝑓𝑈
Count = 0 ; always initialized counter before loop 𝑓𝑟
𝑎 = 𝑥𝐿
While (not converged) and count < 𝑚𝑎𝑥𝑖𝑡 𝑓𝑟
𝑓𝑟 𝑥𝑟 b = 𝑥𝐿
Count = count + 1
𝑓𝑟 x
𝑥𝑟 = 𝑥𝐿 + 𝑥𝑈 /2
𝑓𝑟 = 𝑓(𝑥𝑟 )
If 𝑓𝑟 𝑓𝑈 < 0 ,alternatively use 𝑠𝑖𝑔𝑛(𝑓𝑟 ) ≠ 𝑠𝑖𝑔𝑛(𝑓𝑈 )
𝑓𝐿 X
𝑥𝑟
𝑥𝐿 = 𝑥𝑟 ; 𝑓𝐿 = 𝑓𝑟 𝑥𝐿 X 𝑥𝑈
else
𝑥𝑈 = 𝑥𝑟 ; 𝑓𝑈 = 𝑓𝑟
𝑥𝐿
𝑥
X 𝑥𝑈
𝑟
end 𝑥𝐿 𝑥𝑈
estimated error 𝑥𝑟
End; print 𝑥𝑟 , 𝑓𝑟 , count; STOP
MEC E 390 -A1
Matlab code 8
Define function
Convergence criteria:
Either equal to zero or smaller than the
tolerance
MEC E 390 -A1
Example 9
In case that the initial guess is not enclose a root, for example, Note: Code is available (see,
𝑥𝑈 = −3, 𝑥𝐿 = −2 (Root1 is not bracketed. i.e. 𝑓 −3 and 𝑓(−2) are Lecture3_Bisection.m &
the same sign) Lecture3_Bisection_Graph.m).
Bisection method fail to find the solution. ‘a’ and ‘b’ are initial guesses
Note
1. In order to find a root using Bisection method, a root must be enclosed by
initial guessing points.
2. Convergence is not guaranteed.
3. Finding different root are not always straight forward especially when we do
not know the shape of the graph. The method entirely rely on trial error.
MEC E 390 -A1
Imposition of iterative conditions 11
Convergence criteria
f(x)
1. Convergence criteria in 𝑥 (required) 𝑥𝑎 𝑥𝑟 𝑥𝑏 𝛿𝑓
a)
𝑥𝑏 −𝑥𝑎
< 𝛿𝑥1 or 𝑥𝑏 − 𝑥𝑎 < 𝛿𝑥2 , x
𝑥𝑏𝑜 −𝑥𝑎𝑜
where 𝑥𝑏𝑜 − 𝑥𝑎𝑜 is the initial interval. This version of the relative error means an order of magnitude
𝑥 −𝑥
check: 𝑥 𝑏 −𝑥𝑎 < 10−5 (we require that the final interval be smaller than 5 orders of magnitude)
𝑏𝑜 𝑎𝑜
𝑥𝑏 −𝑥𝑎 𝑥𝑏 −𝑥𝑎 2 𝑥𝑏 −𝑥𝑎
b) Alternatively, we may also consider = = as a relative error
2𝑥𝑟 2 𝑥𝑏 +𝑥𝑎 𝑥𝑏 +𝑥𝑎
𝑥𝑏 −𝑥𝑎
< 𝛿𝑥1 or 𝑥𝑏 − 𝑥𝑎 < 𝛿𝑥2 ,
𝑥𝑏 +𝑥𝑎
Note: The above test are “stopping criteria” used with For-loops. While-loops requires
“continuation criteria”:
Continuation While ( relative error > tol1 AND Ture error > tol2) OR (relative 𝑓 > tol3)
Stopping Stop if ( relative error < tol1 OR Ture error < tol2) AND (relative 𝑓 < tol3)