5.4.25 · D3 · Coding › Scientific Computing (Python) › Implementing root-finding from scratch — Newton-Raphson, bis
Intuition Yeh page kya hai
Parent note ne tumhe do engines diye — bisection (ek sign-change squeeze) aur Newton-Raphson (ek tangent chase). Engines tabhi trustworthy hote hain jab tum unhe har tarah ki road pe drive kar chuke ho. Yeh page un sabhi cases ko enumerate karta hai jo ek root-finder ko hit kar sakti hain, phir har case ke liye ek example work karta hai. Jab tum finish karo, koi bhi scenario tumhe surprise nahi karna chahiye.
Yeh page self-contained hai: iske liye jo bhi chahiye — guard tests, tangent formula, error argument — sab kuch yahan full mein restate kiya gaya hai pehle use karne se. Jab koi word naya ho, hum use zero se rebuild karte hain.
Definition "Bracket" kya hota hai?
Bracket simply ek interval [ a , b ] hai jiske baare mein hum believe karte hain ki yeh ek root ko enclose karta hai — yeh crossing ko "bracket" karta hai jaise do haath ek coin ko cup karte hain taaki woh nikal na sake. Woh technical condition jo ek interval ko valid bracket banati hai woh hai sign change : f ( a ) aur f ( b ) opposite ± signs carry karte hain. Agar f continuous hai aur uski value [ a , b ] ke across negative se positive flip karti hai, toh curve ko zaroor kahi unke beech mein se zero pass karna hoga (Intermediate Value Theorem ). Naam usi trapping picture se aata hai: root bracketed hai — dono taraf se hold kiya gaya hai.
Definition "Ek bit of precision" — yahan
bit ka matlab
Ek bit ek binary yes/no answer hai: yeh batata hai ki tumhara unknown ek range ke kis half mein hai. Agar tum jaante ho ki ek number width w ke interval mein hai, aur tumhe pata chala ki woh actually width w /2 ke ek specific half mein hai, toh tumne abhi ek bit gain kiya — apni uncertainty ki ek halving. Bisection har step mein exactly yahi karta hai, isliye "ek bit of precision per step" literally matlab hai "har step us interval ko half karta hai jo abhi bhi root ko hide kar sakta hai". Das bits ⇒ interval 2 10 ≈ 1000 × shrink hua; isliye log 2 ( range / tolerance ) steps count karta hai.
Root-finding mein kuch situations hain jo alag behave karti hain . Yahan poori list hai. Har row ka "Example" column us section ka naam hai jo usse work karta hai (labels C1…C10 neeche headings se exactly match karte hain).
#
Case class
Kya special hai
Kaun sa method
Example
C1
Clean bracket, opposite signs
textbook bisection
bisection
C1
C2
Sign convention: kaun sa half survive karta hai
quadrant/sign bookkeeping
bisection
C2
C3
Endpoint exactly ek root hai
degenerate: f ( a ) = 0
bisection
C3
C4
Newton, good start, f ′ = 0
quadratic bliss
Newton
C4
C5
Newton ek flat spot ke paas (f ′ → 0 )
huge/undefined step
Newton
C5
C6
Newton jo diverge / cycle karta hai
limiting bad behaviour
Newton
C6
C7
Double root (f = f ′ = 0 saath mein)
convergence slow hokar linear
Newton
C7
C8
Real-world word problem
units, modelling
either
C8
C9
Exam twist: derivative nahi diya
robust engine choose karo
bisection
C9
C10
Invalid bracket (f ( a ) f ( b ) > 0 ), aur midpoint root hit kare
error case + early exit
bisection
C10
Definition Woh teen cheezein jo ek root-finder meet kar sakta hai
Ek sign change matlab hai f ( a ) aur f ( b ) ke opposite ± signs hain, toh curve unke beech zero cross karta hai. Ek flat spot woh hai jahan slope f ′ ( x ) (near) zero ho — tangent horizontal hai aur kahin useful point nahi karta. Ek multiple root woh hai jahan f axis ko bina cross kiye touch karta hai, toh f aur uski slope f ′ saath vanish karte hain; multiplicity m ke root ke liye, actually pehle m − 1 derivatives sab wahan vanish karte hain (f = f ′ = ⋯ = f ( m − 1 ) = 0 , lekin f ( m ) = 0 ). Hamara C7 example simplest case m = 2 hai.
Hum teeno se milenge, plus pure error cases bhi.
f ( x ) = x 2 − 5 ke root ke roop mein 5 nikalo [ 2 , 3 ] par.
Forecast: andaaza lagao ki 5 kahan baitha hai, aur guess karo kitni halvings tumhe 3 decimals ke liye chahiye. (Answer 2.236 ke paas; roughly log 2 ( 1/0.001 ) ≈ 10 steps.)
Step 1 — Bracket check karo. f ( 2 ) = 4 − 5 = − 1 , f ( 3 ) = 9 − 5 = 4 . Yeh step kyun? Bisection tabhi legal hai jab f ( a ) f ( b ) < 0 ; yahan ( − 1 ) ( 4 ) = − 4 < 0 ✓ — ek sign change, toh Intermediate Value Theorem se ek root andar trapped hai.
Step 2 — Midpoint. m = 2 2 + 3 = 2.5 , f ( 2.5 ) = 6.25 − 5 = 1.25 > 0 . Kyun? Midpoint uncertainty ko exactly half mein split karta hai — yahi ek move hai jo guarantee karta hai ki har step ek bit buy kare (uncertainty ki ek halving, jaise upar define kiya).
Step 3 — Woh half rakhho jo abhi bhi sign change kare. f ( 2 ) = − 1 < 0 aur f ( 2.5 ) = + 1.25 > 0 : sign flip left half mein hai. [ 2 , 2.5 ] rakhho. Kyun? Root wahan rehta hai jahan endpoints abhi bhi sign mein disagree karte hain.
Step 4 — Repeat karo. m = 2.25 , f = 0.0625 > 0 → [ 2 , 2.25 ] rakhho. m = 2.125 , f = − 0.484 < 0 → [ 2.125 , 2.25 ] rakhho. Kyun har repeat help karta hai? Har step ek endpoint ko midpoint se replace karta hai, toh interval width 1 → 0.5 → 0.25 → 0.125 = 2 n 1 jaati hai — har baar exactly half, har step ek bit of precision add karke (linear convergence with ratio 2 1 ). Figure ise coloured bars ki stack ke roop mein dikhata hai: top bar [ 2 , 3 ] hai; neeche har bar ek sub-interval hai jo uske upar wale ke andar baitha hai aur half length ka hai ([ 2 , 2.5 ] , phir [ 2 , 2.25 ] , phir [ 2.125 , 2.25 ] ), aur har bar x = 5 ≈ 2.236 par red dashed vertical line ko straddle karta hai — toh tum dekh sakte ho ki root trapped rehta hai jabki bars usp par close in karte hain.
Verify karo: true root 5 = 2.2360679 … hai; 4 steps ke baad hamara bracket [ 2.125 , 2.25 ] indeed ise contain karta hai, width 0.125 = 2 3 1 . ✓
f ( x ) = x 3 − x − 2 on [ 1 , 2 ] : stored sign ko carefully track karo.
Forecast: cubics wiggle kar sakte hain. Kya yeh bracket usi root ki taraf point karta rehega? (Haan — yahan sirf ek real root hai, 1.52 ke paas.)
Step 1 — Bracket. f ( 1 ) = 1 − 1 − 2 = − 2 , f ( 2 ) = 8 − 2 − 2 = 4 . Product − 8 < 0 ✓. f a = − 2 store karo (negative).
Step 2 — Midpoint. m = 1.5 , f ( 1.5 ) = 3.375 − 1.5 − 2 = − 0.125 . f a store karke f m se compare kyun karte hain? Stored f a = − 2 ko f m = − 0.125 ke against compare karo: same sign (dono negative), toh crossing left half mein nahi hai. f a store karna (har loop mein f ( a ) recompute karne ki bajaye) function calls bhi bachata hai.
"Mixing conventions" concretely kya hota hai. Do consistent tarike hain decide karne ke liye ki kaun sa half rakhen: (A) "woh half rakho jinke endpoints mein sign change ho" — yaani left half [ a , m ] rakho jab f a ⋅ f m < 0 ; ya (B) mirror test "right half [ m , b ] rakho jab f m ⋅ f b < 0 ". Har ek apne aap mein correct hai. Bug yeh hai ki decide karne ke liye test (A) use karo lekin endpoint update karo jaise test (B) use kiya ho — e.g. conclude karo "sign change left mein hai" phir bhi a ko m tak upar move karo b ko m tak neeche move karne ki bajaye. Woh single mismatch us half ko rakhta hai jo root contain nahi karta, aur agla iteration silently galat jagah converge karta hai (ya raise hit karta hai jab false bracket apna sign change kho deta hai). Safe rule: ek stored value (f a ) choose karo, use f m se compare karo, aur matching-sign endpoint update karo — ek convention, start to finish.
Step 3 — Left endpoint upar move karo. Kyunki f a ⋅ f m > 0 , root [ 1.5 , 2 ] mein hai. a = 1.5 , f a = − 0.125 set karo. Kyun? Hum us endpoint ko update karte hain jiska sign match kiya (a , kyunki f a aur f m agree karte hain), ek valid bracket preserve karte hue.
Step 4 — Continue karo. m = 1.75 , f = 5.359 − 1.75 − 2 = 1.609 > 0 → ab f a = − 0.125 aur f m = + 1.609 disagree karte hain → [ 1.5 , 1.75 ] rakhho.
Verify karo: x 3 − x − 2 ka real root 1.52137 … hai, jo [ 1.5 , 1.75 ] mein hai ✓. Stored-sign convention ne kabhi use nahi khoya.
f ( x ) = x 2 − 4 on [ 2 , 5 ] — kisine tumhe ek lucky endpoint diya.
Forecast: f ( 2 ) = 0 . Kya standard bracket test chalega bhi? (Nahi! f ( 2 ) f ( 5 ) = 0 , < 0 nahi.)
Step 1 — Guard tests (yahan full mein state kiye gaye hain). Koi bhi correct bisection teen guards se open hota hai, is order mein:
fa, fb = f(a), f(b)
if fa == 0 : return a # endpoint already an exact root
if fb == 0 : return b # other endpoint already an exact root
if fa * fb > 0 : # STRICTLY > 0, not >= 0
raise ValueError ( "f(a) and f(b) must have opposite signs" )
Reject test > 0 kyun hai na ki >= 0? Zero ke barabar product ka matlab hai ki ek endpoint ek root hai — yeh koi error nahi, yeh ek jeet hai. Toh > 0 sirf truly no-sign-change case ko reject karta hai, jabki uske upar ke do == 0 checks pehle exact-root endpoints ko pakad lete hain. Yeh exact order kyun? == 0 checks product test se pehle aane chahiye, taaki zero endpoint return ho sake na ki fall through kare.
Step 2 — Humari inputs trace karo. f ( 2 ) = 0 , toh pehla guard if fa == 0 fire karta hai aur a return karta hai. Order kyun matter karta hai: agar hum fa*fb tak pahunchte, toh 0 ⋅ 21 = 0 milta, jo > 0 nahi hai, toh koi error raise nahi hota — lekin loop phir run karta aur exact zero discard kar sakta tha. fa == 0 pehle check karna hi humein bachata hai.
Step 3 — Return karo. Hum x ∗ = 2 immediately return karte hain, zero iterations.
Verify karo: f ( 2 ) = 2 2 − 4 = 0 ✓ exact. [ 2 , 5 ] par endpoint check skip karna evaluations waste karta ya root kho deta.
Common mistake "Sign change matlab endpoints roots nahi ho sakte, toh check skip karo."
WHY yeh sahi lagta hai: f ( a ) f ( b ) < 0 zero endpoints rule out karta hai. Fix: caller ek aisa interval pass kar sakta hai jiska endpoint exactly ek root hai, giving f ( a ) f ( b ) = 0 . Loop trust karne se pehle hamesha endpoints check karo.
f ( x ) = x 2 − 2 , f ′ ( x ) = 2 x , x 0 = 1.5 se.
Forecast: har step ke baad correct digits count karo — kya woh roughly double hote hain? (Haan: yahi quadratic convergence ki pehchaan hai.)
Step 1 — Update (yahan derive kiya gaya, borrowed nahi). x n par f ki tangent line y = f ( x n ) + f ′ ( x n ) ( x − x n ) hai. y = 0 set karke x ke liye solve karne par Newton step milta hai x n + 1 = x n − f ′ ( x n ) f ( x n ) — us tangent ka x-intercept. Is f ke liye yeh Babylonian rule x n + 1 = 2 x n + x n 1 mein simplify hota hai. Yeh simplification kyun? x − 2 x x 2 − 2 = x − 2 x + x 1 .
Step 2 — Iterate karo. Figure blue parabola f ( x ) = x 2 − 2 dikhata hai, aur har guess par ek yellow straight tangent line; agla guess padhne ke liye har tangent ko neeche follow karo jahan woh horizontal axis cross karta hai (ek red dot).
x 1 = 2 1.5 + 1.5 1 = 0.75 + 0.6667 = 1.41667 (3 good digits).
x 2 = 2 1.41667 + 1.41667 1 = 0.708333 + 0.705882 = 1.414216 (6 digits).
Step 3 — Itni tezi kyun (second derivative explicitly ke saath). Error e n = x n − x ∗ likho jahan x ∗ = 2 . Convergence rate second derivative f ′′ par depend karta hai, jo measure karta hai ki slope khud kaise change hoti hai — curve ka bending. Yahan f ( x ) = x 2 − 2 , toh f ′ ( x ) = 2 x aur f ′′ ( x ) = 2 (ek constant: parabola har jagah same tarah bend karta hai). Standard error bound hai
e n + 1 ≈ 2 f ′ ( x ∗ ) f ′′ ( x ∗ ) e n 2 .
f ′′ ( x ∗ ) = 2 aur f ′ ( x ∗ ) = 2 2 plug in karo: constant hai 2 ⋅ 2 2 2 = 2 2 1 ≈ 0.354 . Kyunki f ′ ( x ∗ ) = 2 2 = 0 , yeh bound hold karta hai aur error e n 2 ke proportional hai — har step mein square hota hai, toh correct digits ki sankhya roughly double hoti hai.
Verify karo: 2 = 1.41421356 … ; x 2 = 1.414216 5 places tak match karta hai ✓. Digit count 3 → 6 gaya: doubling confirmed. Constant check: e 1 = 1.5 − 2 ≈ 0.0858 , e 2 = x 2 − 2 ≈ 0.0000024 , aur e 2 / e 1 2 ≈ 0.33 — predicted 0.354 ke paas. ✓
f ( x ) = x 2 − 2 lekin x 0 = 0.001 se start (slope ki almost flat bottom-ish region).
Forecast: slope f ′ ( 0.001 ) = 0.002 tiny hai. Kya pehla step chhota hoga ya gigantic? (Gigantic — near-zero slope se divide karna tumhe dur faar le jaata hai.)
Step 1 — Step compute karo. f ( 0.001 ) = 0.00 1 2 − 2 = − 1.999999 , f ′ ( 0.001 ) = 2 ( 0.001 ) = 0.002 . Step = 0.002 − 1.999999 = − 999.9995 . Itna bada kyun? Tangent almost horizontal hai, toh uska x-intercept bahut dur hai — ek horizontal line axis ko infinity par milti hai.
Step 2 — Jump karo. x 1 = 0.001 − ( − 999.9995 ) = 1000.0005 . Dekho : blue curve near-zero-slope point par ek shallow yellow tangent carry karta hai, aur ek red arrow agla guess axis ke kaafi right mein flung dikhata hai.
Step 3 — Recovery. x 1 = 1000 se slope ab huge aur honest hai, toh Newton eventually wapas aata hai — lekin usne iterations waste kiye. Agar x 0 exactly 0 hota, toh f ′ ( 0 ) = 0 aur code ZeroDivisionError raise karta — ek flat tangent kahin nahi point karta.
Verify karo: step magnitude ∣ − 999.9995 ∣ = 999.9995 ✓, aur x 1 = 1000.0005 ✓. Lesson: ek flat spot ke paas step size blow up hoti hai, C4 mein tiny confident steps ke bilkul opposite.
f ( x ) = x 1/3 (cube root), root x ∗ = 0 ke alawa kahin se bhi start karo.
Forecast: ek hi root 0 hai. Kya Newton uski taraf chalega ya door? (Door — yeh geometrically diverge karta hai.)
Step 1 — Derivative. f ( x ) = x 1/3 , toh f ′ ( x ) = 3 1 x − 2/3 . f ′ kyun check karein? Newton isse divide karta hai; yahan yeh galat direction mein grow karta hai.
Step 2 — Update simplify hota hai. x n + 1 = x n − 3 1 x n − 2/3 x n 1/3 = x n − 3 x n 1/3 x n 2/3 = x n − 3 x n = − 2 x n . Yeh catastrophic kyun hai? Har step x ko − 2 se multiply karta hai: sign flip karta hai aur root se distance double karta hai.
Step 3 — x 0 = 1 se iterate karo. x 1 = − 2 , x 2 = 4 , x 3 = − 8 , … Dekho : guess dots (red) axis par baithte hain aur yellow curved arrows har guess ko next tak hop karte hain — 1 → − 2 → 4 → − 8 — outward left, right, farther left, kabhi 0 par green root ki taraf nahi.
Verify karo: x n + 1 = − 2 x n se ∣ x n ∣ = 2 n milta hai, jo → ∞ ✓. [ − 1 , 1 ] par bisection (f ( − 1 ) = − 1 < 0 , f ( 1 ) = 1 > 0 ke saath) safely 0 ko trap karta — eternal robustness-vs-speed trade-off.
Common mistake "Newton hamesha converge karta hai — woh simply better method hai."
WHY yeh sahi lagta hai: jab kaam karta hai toh digits double karta hai. Fix: bura start, near-zero slope, ya x 1/3 jaisa odd-power cusp ise diverge ya cycle kara deta hai. Robustness bisection ki hai.
f ( x ) = ( x − 3 ) 2 , multiplicity two ka root, x 0 = 5 se.
Forecast: x ∗ = 3 par, f ( 3 ) = 0 aur f ′ ( 3 ) = 0 dono. Kya Newton abhi bhi digits double karta hai? (Nahi — double root ise linear tak demote karta hai, sirf error half karte hue.)
Step 1 — Update. f ( x ) = ( x − 3 ) 2 , f ′ ( x ) = 2 ( x − 3 ) . Toh x n + 1 = x n − 2 ( x n − 3 ) ( x n − 3 ) 2 = x n − 2 x n − 3 = 2 x n + 3 . Yeh kyun matter karta hai? Error obey karta hai e n + 1 = 2 1 e n — linear , quadratic nahi.
Step 2 — Iterate karo. x 0 = 5 (error 2) → x 1 = 4 (error 1) → x 2 = 3.5 (error 0.5) → x 3 = 3.25 (error 0.25). Har step error ko exactly half karta hai, bisection ki tarah.
Step 3 — Slowdown kyun? C4 se quadratic bound e n + 1 ≈ 2 f ′ ( x ∗ ) f ′′ ( x ∗ ) e n 2 assume karta hai ki f ′ ( x ∗ ) = 0 . Double root par f ′ ( x ∗ ) = 0 , woh formula zero se divide karta hai aur invalid hai; true rate linear tak collapse ho jaati hai. (Multiplicity m ke liye, f aur uske pehle m − 1 derivatives wahan vanish karte hain, aur linear rate 1 − m 1 ban jaati hai.)
Verify karo: x 1 = 2 5 + 3 = 4 ✓, x 2 = 2 4 + 3 = 3.5 ✓, x 3 = 3.25 ✓. Errors 2 , 1 , 0.5 , 0.25 — ratio 2 1 , linear ✓.
Worked example Ek projectile ki height
h ( t ) = 20 t − 4.9 t 2 metres hai, t seconds mein. Yeh ground se kab takkaraata hai (h = 0 , launch ke alawa)?
Forecast: launch t = 0 hai; landing kuch seconds baad honi chahiye (guess near 4 s).
Step 1 — Root problem set up karo. Hum h ( t ) = 0 chahte hain, yaani t ( 20 − 4.9 t ) = 0 . Factor kyun? Ek root trivial t = 0 hai; physical landing doosre factor ka root hai.
Step 2 — Landing bracket karo. h ( 3 ) = 60 − 44.1 = 15.9 > 0 , h ( 5 ) = 100 − 122.5 = − 22.5 < 0 : sign change on [ 3 , 5 ] ✓. Yahan bisection kyun? Ek clean bracket exist karta hai aur hum correct units ke saath guaranteed answer chahte hain.
Step 3 — Squeeze karo.
m = 4 : h ( 4 ) = 80 − 78.4 = 1.6 > 0 . [ 4 , 5 ] kyun rakhte hain? h ( 4 ) > 0 aur h ( 5 ) < 0 sign mein abhi bhi disagree karte hain, toh crossing right half mein hai.
m = 4.5 : h ( 4.5 ) = 90 − 99.225 = − 9.225 < 0 . [ 4 , 4.5 ] kyun rakhte hain? Ab h ( 4 ) > 0 aur h ( 4.5 ) < 0 disagree karte hain, toh root left half mein hai. t ∗ = 20/4.9 ki taraf converge ho raha hai.
Verify karo (algebra + units): 20 − 4.9 t = 0 solve karne par t ∗ = 20/4.9 = 4.0816 … seconds milta hai, jo [ 4 , 4.5 ] mein hai ✓. Units: [ m⋅s − 1 ] / [ m⋅s − 2 ] = [ s ] ✓ — answer ek time hai, jaisa hona chahiye.
f ( x ) = e x + x ka root [ − 1 , 0 ] par nikalo. Tumhe f ′ nahi diya gaya." Kaun sa engine, aur kyun?
Forecast: Newton ko f ′ chahiye; kya tum differentiate kiye bina kaam kar sakte ho? (Haan — bisection use karo, ya derivative-free Secant method .)
Step 1 — Constraint padho. No f ′ ⇒ Newton off the table hai jab tak tum haath se differentiate nahi karte. Kyun? Newton update f ′ ( x n ) se divide karta hai; iske bina divide karne ke liye kuch nahi hai.
Step 2 — Bracket karo. f ( − 1 ) = e − 1 − 1 = 0.3679 − 1 = − 0.6321 < 0 , f ( 0 ) = 1 + 0 = 1 > 0 : sign change ✓. Yeh kaafi kyun hai? Bisection ko sirf f values aur ek sign flip chahiye — koi calculus nahi.
Step 3 — Squeeze karo. m = − 0.5 : f = e − 0.5 − 0.5 = 0.6065 − 0.5 = 0.1065 > 0 → [ − 1 , − 0.5 ] rakhho. m = − 0.75 : f = 0.4724 − 0.75 = − 0.2776 < 0 → [ − 0.75 , − 0.5 ] rakhho. − 0.567 ke paas converge ho raha hai.
Verify karo: e x + x = 0 ka true root x ∗ = − 0.567143 … hai (negative Omega constant), jo [ − 0.75 , − 0.5 ] mein hai ✓. Exam-safe choice: bisection , kyunki isme zero derivatives chahiye.
Worked example Bisection loop ke do edge behaviours: (a)
f ( a ) f ( b ) > 0 "bracket" ke roop mein pass in kiya gaya, aur (b) ek midpoint jo exactly ek root hai, jiske liye early exit if fm == 0: return m chahiye.
Forecast: har case mein code ko kya karna chahiye? (a) error ke saath refuse karo; (b) instantly stop karo aur midpoint return karo.
Step 1 — Invalid bracket (a). f ( x ) = x 2 − 2 on [ 2 , 3 ] lo. f ( 2 ) = 2 > 0 , f ( 3 ) = 7 > 0 : product 14 > 0 . Refuse kyun? Sign change nahi hona matlab Intermediate Value Theorem andar root ki koi guarantee nahi deta — guard if fa*fb > 0: raise ValueError (C3 mein full mein stated) fire karta hai. Continue karna meaningless hoga: bisection ek aisi crossing invent nahi kar sakta jo bracketed nahi hai.
Step 2 — Midpoint root hit kare (b). f ( x ) = x 2 − 4 on [ 1 , 3 ] lo. f ( 1 ) = − 3 < 0 , f ( 3 ) = 5 > 0 : valid bracket. Midpoint hai m = 2 1 + 3 = 2 , aur f ( 2 ) = 0 exactly . Early exit kyun? Loop body guard carry karta hai if fm == 0 or (b - a)/2 < tol: return m. fm == 0 test ke bina, code fa*fm compare karta — lekin f a ⋅ 0 = 0 na <0 hai na handled hai, toh woh else branch mein fall karta aur exact root se door walk karta . Early exit is lucky bullseye ko catch karta hai.
Step 3 — Contrast karo. Case (a) koi jawab nahi deta (ek error — input illegal tha); case (b) ek step mein exact answer deta hai. Dono ko do tiny guards handle karte hain; yeh example precisely dikhata hai ki har ek kab fire karta hai.
Verify karo: (a) f ( 2 ) f ( 3 ) = 2 ⋅ 7 = 14 > 0 ✓ toh raise trigger hota hai. (b) f ( 2 ) = 2 2 − 4 = 0 ✓ exact, toh if fm == 0: return 2 fire karta hai — aur [ 1 , 3 ] par x 2 − 4 ka true root indeed 2 hai. ✓
Recall Matrix par quick self-test
Kaun sa cell Newton ki quadratic convergence ko perfect start ke bawajood break karta hai? ::: C7 — ek double root, kyunki f ′ ( x ∗ ) = 0 ise linear tak demote karta hai.
x 0 = 0.001 (C5) se start karna Newton ko itna dur kyun bhejta hai? ::: Slope f ′ near zero hai, toh tangent almost flat hai aur uska x-intercept enormous hai — ek giant step.
f ( x ) = x 1/3 (C6) par, Newton update kya reduce hota hai? ::: x n + 1 = − 2 x n , har step mein distance double karke aur sign flip karke — pure divergence.
Koi derivative na ho (C9), do safe options batao. ::: Bisection ya secant method — dono ko sirf f values chahiye.
C10 mein bisection edge cases ko kaun se do guards handle karte hain? ::: if fa*fb > 0: raise (valid bracket nahi) aur if fm == 0: return m (midpoint exactly root hai).
Bisection ke liye "ek bit of precision" ka matlab kya hai? ::: Uncertainty interval ki ek halving — ek single yes/no answer ki bare mein kaun sa half root hide karta hai.
Multiplicity m ke root ke liye, wahan kaun se derivatives vanish karte hain? ::: f = f ′ = ⋯ = f ( m − 1 ) = 0 lekin f ( m ) = 0 .
Mnemonic Char Newton dangers, "SLoW-D"
S tart bahut door · Lo w (flat) slope f ′ ≈ 0 · W iggly/odd cusp (cycles/diverges) · D ouble root (slows to linear). Jab bhi koi appear kare, bisection par fall back karo.
Yeh bhi dekho parent note , Fixed-point iteration iteration ka ek aur view ke liye, scipy.optimize production tooling ke liye, aur Floating point arithmetic is liye ki f(m)==0 almost kabhi exactly kyun nahi hota.