- 2068 Magh · 4 marks
Newton-Raphson algorithm
Short answer
Newton-Raphson iteration: x(n+1) = x(n) - f(x(n))/f'(x(n)). Algorithm: input f, f', x0, tolerance e, max N. Loop: if |f'(x0)| near 0 stop; compute x1 = x0 - f(x0)/f'(x0); if |x1-x0| < e or |f(x1)| < e, root = x1; else x0 = x1; repeat until convergence or N iterations.
Write an algorithm to find a real root of a non-linear equation using the Newton-Raphson method.
Newton-Raphson iteration: x(n+1) = x(n) − f(x(n)) / f′(x(n)).
Algorithm / pseudo-code
Algorithm: Newton-Raphson method
Input : f(x), f'(x), initial guess x0,
tolerance e, maximum iterations N
Output: approximate root
1. Read x0, e, N
2. Set i = 1
3. Repeat steps 4 to 9 while i <= N
4. If |f'(x0)| is very small (near 0) then
print "Derivative is zero; choose another x0"
stop
5. x1 = x0 - f(x0) / f'(x0)
6. If |x1 - x0| < e (or |f(x1)| < e) then
print "Root =", x1, "after", i, "iterations"
stop
7. x0 = x1
8. i = i + 1
9. End repeat
10. Print "Method does not converge in N iterations"
11. Stop
Notes
- Both f(x) and f′(x) must be coded as functions.
- The check in step 4 avoids division by zero.
- The iteration limit N stops an endless loop when the method diverges or oscillates.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Limitations of Newton-Raphson · Numerical Method, chapter 2
- Derive Newton-Raphson formula · Numerical Method, chapter 2 · asked 2×
- Secant method algorithm · Numerical Method, chapter 2 · asked 2×
- Loop closure equation and Newton-Raphson method · Theory of Mechanism and Machine I, chapter 2
- Preemptive vs non-preemptive; real-time scheduling · Operating System, chapter 2
- Linear momentum and impulse-momentum equation · Fluid Machines, chapter 1
- What is a stack; linear or non-linear · Data Structure and Algorithm, chapter 2