5.4.25 · D3 · HinglishScientific Computing (Python)

Worked examplesImplementing root-finding from scratch — Newton-Raphson, bisection

3,726 words17 min read↑ Read in English

5.4.25 · D3 · Coding › Scientific Computing (Python) › Implementing root-finding from scratch — Newton-Raphson, bis

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.


Scenario matrix

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: bisection C3
C4 Newton, good start, quadratic bliss Newton C4
C5 Newton ek flat spot ke paas () huge/undefined step Newton C5
C6 Newton jo diverge / cycle karta hai limiting bad behaviour Newton C6
C7 Double root ( 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 (), aur midpoint root hit kare error case + early exit bisection C10

Hum teeno se milenge, plus pure error cases bhi.


C1 — Clean bracket, textbook bisection


C2 — Sign bookkeeping: kaun sa half survive karta hai


C3 — Degenerate: ek endpoint already root hai


C4 — Newton, good start, quadratic bliss


C5 — Newton ek flat spot ke paas ()


C6 — Newton jo diverge / cycle karta hai (limiting disaster)


C7 — Double root: quadratic convergence break down ho jaati hai


C8 — Real-world word problem (units matter karte hain)


C9 — Exam twist: derivative supply nahi kiya gaya


C10 — Invalid bracket, aur ek midpoint jo root par land kare


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 ise linear tak demote karta hai. (C5) se start karna Newton ko itna dur kyun bhejta hai? ::: Slope near zero hai, toh tangent almost flat hai aur uska x-intercept enormous hai — ek giant step. (C6) par, Newton update kya reduce hota hai? ::: , 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 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 ke root ke liye, wahan kaun se derivatives vanish karte hain? ::: lekin .

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.