You are on page 1of 13

Introduction to Numerical

Analysis
Riham K. Ahmed
Lecture 2 – Part 1
‫إيجاد الجذور – ‪Roots Finding‬‬
‫‪𝑓 𝑥 = 𝑥 2 − 2𝑥 + 3 = 0‬‬
‫‪= 𝑥−3 𝑥+1 =0‬‬
‫‪∴ 𝑥 = 3, −1‬‬

‫الهدف؟؟؟‬
‫دراسة طرق متعددة إليجاد جذور)‪ (roots‬معادلة ما بإستحدام التقريب العددي في حالة‬
‫صعوبة الحصول على ‪ roots‬عن طريق الحلول التحليلية )‪(Analytic Solutions‬‬
Root Finding
:‫ = 𝑥 𝑓 حيث 𝑓 دالة حقيقية مستمرة قابلة لإلشتقاق‬0, 𝑥 ∈ 𝑎, 𝑏 ‫إذا كان‬

• Bisection Method

• Fixed Point Iteration


• Steps in each method
• Convergence rate of root
• Newton’s Method • Algorithm

• Secant Method
Bisection Method
Intermediate Value Theorem )‫(مبرهنة القيمة المتوسطة‬
‫𝑎[ و𝑝 عدد يقع بين)𝑎(𝑓 و)𝑏(𝑓 عندئذ توجد نقطة‬, 𝑏] ‫• إذا كانت𝑓دالة مستمرة في الفترة‬
.𝑓)𝑝( = 0 ‫𝑎[ ∊ 𝑝 بحيث ان‬, 𝑏]

• Suppose 𝑓 is a continuous function defined on the interval [𝑎, 𝑏], with


𝑓(𝑎) and 𝑓(𝑏) of opposite sign. Then there exists a point 𝑝 ∊ [𝑎, 𝑏]
such that 𝑓(𝑝) = 0
Bisection Method Steps
• 𝑓(𝑎) ∙ 𝑓(𝑏) < 0.
• Bisect the interval [𝑎, 𝑏] [𝑎, 𝑝] & [𝑝, 𝑏] by letting:
𝑎+𝑏
𝑝=
2
• If 𝑓(𝑝) = 0, then 𝑝 is a root.
• If 𝑓(𝑝) ∙ 𝑓(𝑎) < 0, then a root lies in the interval [𝑎, 𝑝], set 𝑏 = 𝑝.
• If 𝑓(𝑝) ∙ 𝑓(𝑏) < 0, then a root lies in the interval [𝑏, 𝑝], set 𝑎 = 𝑝.
• Then reapply the process to the new interval [𝑎, 𝑏] until 𝑓(𝑝) = 0 or interval
length < ε (tolerance ε > 0).
Bisection Method Steps
➢ set 𝑎1 = a and 𝑏1 = b, and let:
𝑎1 + 𝑏1
𝑝1 =
2
➢ If 𝑓(𝑝1 ) = 0, then p = 𝑝1 , and we are done.

➢ If 𝑓(𝑝1 ) ≠ 0, then 𝑓(𝑝1 ) has the same sign as either


𝑓(𝑎1 ) or 𝑓(𝑏1 ):

o If 𝑓(𝑝1 ) and 𝑓(𝑎1 ) have the same sign, 𝑝 ∈ (𝑝1 , 𝑏1 ). Set


𝑎2 = 𝑝1 and 𝑏2 = 𝑏1 .

o If 𝑓(𝑝1 ) and 𝑓(𝑎1 ) have opposite signs, 𝑝 ∈ (𝑎1 , 𝑝1 ). Set


𝑎2 = 𝑎1 and 𝑏2 = 𝑝1 .

Then reapply the process to the interval [𝑎2 , 𝑏2 ].


‫‪Example‬‬
‫• بإستخدام ‪ Bisection method‬أوجد جذرتقريبي للدالة ‪ 𝑓 𝑥 = 𝑥 4 − 𝑥 − 10 = 0‬في‬
‫الفترة ]‪ [1.5, 2‬بخطأ ‪10−2‬‬
‫‪Solution:‬‬
‫‪𝑓 𝑎 = 1.54 − 1.5 − 10 = −6.4375‬‬
‫‪𝑓 𝑏 = 24 − 2 − 10 = 4‬‬
‫‪𝑓 1.5 ∙ 𝑓 2 < 0‬‬
‫𝑏‪𝑎+‬‬
‫= 𝑖𝑝‬
‫‪2‬‬
‫‪𝑝1 = 1.75‬‬
‫‪𝑓 𝑝1 = 1.754 − 1.75 − 10 = −2.37109375‬‬
‫‪𝑎, 𝑏 = 1.75, 2‬‬
‫‪𝑝2 = 1.875‬‬
‫‪𝑓 𝑝2 = 1.8754 − 1.875 − 10 = 0.484619140625‬‬
‫]‪𝑎, 𝑏 = [1.75, 1.875‬‬
‫‪Example‬‬
‫• بإستخدام ‪ Bisection method‬أوجد جذر تقريبي للدالة ‪ 𝑓 𝑥 = 𝑥 4 − 𝑥 − 10 = 0‬في الفترة ]‪[1.5, 2‬‬
‫بخطأ ‪10−2‬‬
‫‪Solution:‬‬
‫‪𝑓 1.5 = −6.4375,‬‬ ‫‪𝑓 2 =4‬‬
‫‪𝑓 1.5 ∙ 𝑓 2 < 0‬‬
‫𝑏‪𝑎+‬‬
‫= 𝑖𝑝‬
‫‪2‬‬
‫𝒊‬ ‫𝒂‬ ‫𝒃‬ ‫𝒊𝒑‬ ‫)𝑎(𝑓‬ ‫) 𝒊𝒑(𝑓‬ ‫) 𝒊𝒑(𝑓∙)𝑎(𝑓‬ ‫𝟏‪𝒑𝒊 − 𝒑𝒊−‬‬
‫‪1‬‬ ‫‪1.5‬‬ ‫‪2‬‬ ‫‪1.75‬‬ ‫‪-6.438‬‬ ‫‪-2.371‬‬ ‫‪15.264‬‬ ‫‪-‬‬
‫‪2‬‬ ‫‪1.75‬‬ ‫‪2‬‬ ‫‪1.875‬‬ ‫‪-2.371‬‬ ‫‪0.485‬‬ ‫‪-1.149‬‬ ‫‪0.125‬‬
‫‪3‬‬ ‫‪1.75‬‬ ‫‪1.875‬‬ ‫‪1.812‬‬ ‫‪-2.371‬‬ ‫‪-1.032‬‬ ‫‪2.447‬‬ ‫‪0.063‬‬
‫‪4‬‬ ‫‪1.812‬‬ ‫‪1.875‬‬ ‫‪1.844‬‬ ‫‪-1.032‬‬ ‫‪-0.282‬‬ ‫‪0.291‬‬ ‫‪0.032‬‬
‫‪5‬‬ ‫‪1.844‬‬ ‫‪1.875‬‬ ‫‪1.86‬‬ ‫‪-0.282‬‬ ‫‪0.108‬‬ ‫‪-0.030‬‬ ‫‪0.016‬‬
‫‪6‬‬ ‫‪1.844‬‬ ‫‪1.86‬‬ ‫‪1.852‬‬ ‫‪-0.282‬‬ ‫‪-0.088‬‬ ‫‪0.0248‬‬ ‫‪0.008‬‬

‫‪𝑓(𝑝) = 1.852‬‬
‫?‪Question‬‬
‫كم عدد التكرارات الممكنة ليصبح طول الفتره أقل من ‪ε‬؟‬
‫‪Solution:‬‬
‫• ضع 𝑎 – 𝑏 = ‪ L‬من ‪ Bisection method‬سيصبح طول الفترة بعد𝑘 تكرار‪:‬‬
‫‪[1.5,2]=0.5‬‬ ‫‪L‬‬
‫‪[1.75,2]= 0.25‬‬ ‫𝑘 = 𝑘‪L‬‬
‫‪[1.75,1.875]=0.125‬‬ ‫‪2‬‬
‫• نحتاج أن يكون‪:‬‬
‫‪L‬‬ ‫‪L‬‬
‫‪L𝑘 ≤ ε ⟹ 𝑘 ≤ ε ⟹ 𝑘 ≥ log 2‬‬
‫‪2‬‬ ‫‪ε‬‬
‫‪L‬‬
‫‪ 𝑘 = log 2‬حيث ‪ .‬هي دالة السقف‪.‬‬ ‫• سنختار‬
‫‪ε‬‬
Theorem

‫𝑛𝑝 تتقارب إلى 𝑝 جذر‬ 𝑛=1 ‫ تولد متتابعة‬Bisection method ‫ < )𝑏(𝑓∙)𝑎(𝑓 فإن‬0‫𝑎[𝐶𝜖𝑓 و‬,𝑏] ‫• إذا كان‬
:‫ = 𝑥 𝑓 ب‬0 ‫المعادلة‬
𝑏−𝑎
𝑝𝑛 − 𝑝 ≤ 𝑛 when 𝑛 ≥ 1
2
Proof:
1
For each 𝑛 ≥ 1: 𝑏𝑛 − 𝑎𝑛 = (𝑏 − 𝑎) and 𝑝 ∈ (𝑎𝑛 + 𝑏𝑛 )
2𝑛−1
1
∵ 𝑝𝑛 = (𝑏𝑛 + 𝑎𝑛 ), ∀𝑛 ≥ 1
2
1 𝑏−𝑎
∴ 𝑝𝑛 − 𝑝 ≤ 𝑏𝑛 − 𝑎𝑛 = 𝑛
2 2
1 1 1
𝑝𝑛 − 𝑝 = (𝑏𝑛 + 𝑎𝑛 ) − (𝑏𝑛 − 𝑎𝑛 ) = 𝑏𝑛 − 3𝑎𝑛 ≤ 𝑏𝑛 − 𝑎𝑛
2 2 2
∞ 1 1
The sequence 𝑝𝑛 𝑛=1 converges to 𝑝 with rate of convergence 𝑂 ; that is 𝑝𝑛 = 𝑝 + 𝑂
2𝑛 2𝑛
Bisection Method Algorithm
• INPUT: endpoints a, b; tolerance TOL; maximum number of iterations 𝑁0 .
• OUTPUT: approximate solution 𝑝 or message of failure.
• Step 1 Set 𝑖 = 1;
FA = 𝑓(𝑎).
• Step 2 While 𝑖 ≤ 𝑁0 do Steps 3 – 6.
Step 3 Set 𝑝 = 𝑎 + (𝑏 – 𝑎)/2 ; (Compute 𝑝𝑖 )
FP = 𝑓(𝑝).
Step 4 If FP = 0 or (𝑏 – 𝑎)/2 < TOL then
OUTPUT (𝑝); (Procedure completed successfully.)
STOP.
Step 5 Set 𝑖 = 𝑖 + 1.
Step 6 If FA・FP > 0 then set a = 𝑝; (Compute 𝑎𝑖 , 𝑏𝑖 .)
FA = FP
else set b = p. (FA is unchanged.)
• Step 7 OUTPUT (‘Method failed after 𝑁0 iterations, 𝑁0 =`, 𝑁0 );
(The procedure was unsuccessful.)
STOP.
‫‪Exercise‬‬
‫‪ .1‬مستخدما ‪ Bisection method‬أوجد ‪ 𝑝3‬للدالة 𝑥 ‪ 𝑓 𝑥 = 𝑥 − cos‬في الفترة ]‪.[0, 1‬‬

‫‪ .2‬لتكن ‪ 𝑓 𝑥 = 0‬معادلة غير خطية ولدينا فترة طولها ‪ 1.5‬أوجد أقل عدد من مرات التكرار تكفي ليكون‬
‫الخطأ أقل من أويساوي ‪.10−10‬‬

‫‪3. Determine the number of iterations necessary to solve 𝑓 𝑥 = 𝑥 3 + 4𝑥 2 − 10 = 0‬‬


‫‪with accuracy 10−3 using 𝑎1 = 1 and 𝑏1 = 2.‬‬

‫‪ .4‬أكتب برنامج بإستخدام ‪ Python‬اليجاد جذر المعادله ‪ 𝑓 𝑥 = 0‬في فتره معينه مستخدما ‪Bisection‬‬
‫‪.method‬‬

You might also like