- Asked 2/13
- 2073 Bhadra · 4 marks
- 2071 Bhadra · 4 marks
Secant method algorithm
Short answer
Use initial guesses x0, x1; compute x2 = x1 - f(x1)*(x1-x0)/(f(x1)-f(x0)). If |x2-x1| < tolerance, x2 is root; otherwise set x0=x1, x1=x2 and iterate.
Write an algorithm (pseudo-code) of the Secant method for finding a real root of a non-linear equation.
The Secant method needs two starting guesses x0, x1 and no derivative.
Algorithm / pseudo-code
Algorithm: Secant method
Input : f(x), initial guesses x0, x1,
tolerance e, maximum iterations N
Output: approximate root
1. Read x0, x1, e, N
2. Set i = 1
3. Repeat steps 4 to 9 while i <= N
4. f0 = f(x0), f1 = f(x1)
5. If |f1 - f0| is very small then
print "Division by zero; change guesses"
stop
6. x2 = x1 - f1 * (x1 - x0) / (f1 - f0)
7. If |x2 - x1| < e then
print "Root =", x2, "after", i, "iterations"
stop
8. x0 = x1
x1 = x2
9. i = i + 1
10. Print "Method does not converge in N iterations"
11. Stop
For clarity the pseudo-code evaluates both f0 and f1 in every pass. In a real program only one new function value, f(x2), is needed per iteration, because the old f1 can be reused as the new f0. This makes each step cheaper than a Newton-Raphson step, which needs both f and f′.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- False position pseudo-code · Numerical Method, chapter 2 · asked 2×
- Bisection method pseudo-code · Numerical Method, chapter 2 · asked 3×
- Secant method: explain and derive · Numerical Method, chapter 2 · asked 3×
- Gauss-Jordan pseudo-code · Numerical Method, chapter 3 · asked 4×
- Secant algorithm, versus false position · Numerical Method, chapter 2
- Power method pseudo-code · Numerical Method, chapter 3 · asked 2×
- Algorithm/pseudo-code for software PID · Embedded System, chapter 7 · asked 3×
- Algorithm versus pseudo-code · Computer Programming, chapter 2
- Real and pseudo-parallelism · Microprocessor, chapter 6
- Preemptive vs non-preemptive; real-time scheduling · Operating System, chapter 2