---
title: "Secant method algorithm"
subject: "Numerical Method"
chapter: 2
key: "semester_4/numerical_method:secant-method-algorithm"
source: https://www.bctengineer.com/q/semester_4/numerical_method/secant-method-algorithm
site: BCT Engineering
---

# Secant method algorithm

Numerical Method · Chapter 2: Solutions of Nonlinear Equations

- Asked in: 2073 Bhadra, 4 marks; 2071 Bhadra, 4 marks (asked 2 times)
- Video: [Secant Method | Lecture 15 | Numerical Methods for Engineers](https://www.youtube.com/watch?v=Zz8AYQ8c5-U) — Jeffrey Chasnov
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/numerical_method/secant-method-algorithm
- Whole chapter: https://www.bctengineer.com/md/semester_4/numerical_method/chapter-2

## Question

Write an algorithm (pseudo-code) of the Secant method for finding a real root of a non-linear equation.

## 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.

## Answer

The Secant method needs two starting guesses x0, x1 and no derivative.

#### Algorithm / pseudo-code
```text
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′.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. After computing x2, the algorithm sets:
   A. x0 = x1 and x1 = x2
   B. x0 = x2 only
   C. x1 = x0
   D. Both to x2
   Answer: A. The two latest points are always kept. (Key point: Update step)

2. Why test |f1 - f0| is very small?
   A. To check convergence
   B. To avoid division by zero
   C. To detect a sign change
   D. To count iterations
   Answer: B. f1 - f0 is the denominator of the secant formula. (Key point: Safety check)

3. The loop stops with a root when:
   A. f1 = f0
   B. i = 1
   C. |x2 - x1| < e
   D. x2 = 0
   Answer: C. Successive approximations agree within tolerance. (Key point: Stopping)

4. Why is secant cheaper than Newton-Raphson per step?
   A. It needs no starting values
   B. It uses quadratic convergence
   C. It never fails
   D. Only one new function value per iteration and no derivative
   Answer: D. The old f1 is reused as f0. (Key point: Cost)

## Related in Numerical Method

- [False position pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Afalse-position-pseudocode) — Numerical Method, chapter 2, asked 2×
- [Bisection method pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Abisection-pseudocode) — Numerical Method, chapter 2, asked 3×
- [Secant method: explain and derive](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Asecant-method-explain-derive) — Numerical Method, chapter 2, asked 3×
- [Gauss-Jordan pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Agauss-jordan-pseudocode) — Numerical Method, chapter 3, asked 4×
- [Secant algorithm, versus false position](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Asecant-pseudocode-vs-false-position) — Numerical Method, chapter 2
- [Power method pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Apower-method-algorithm) — Numerical Method, chapter 3, asked 2×

## Related in other subjects

- [Algorithm/pseudo-code for software PID](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Apid-software-algorithm) — Embedded System, chapter 7, asked 3×
- [Algorithm versus pseudo-code](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aalgorithm-vs-pseudocode) — Computer Programming, chapter 2
- [Real and pseudo-parallelism](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Areal-pseudo-parallelism) — Microprocessor, chapter 6
- [Preemptive vs non-preemptive; real-time scheduling](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Apreemptive-nonpreemptive-realtime) — Operating System, chapter 2
