Secant Method Calculator

Stephanie Ben-Joseph headshot Stephanie Ben-Joseph

What is the Secant Method?

The secant method is an iterative numerical technique for approximating solutions of the equation f(x) = 0. It is similar to Newton's method but does not require an explicit derivative f'(x). Instead, it estimates the derivative using the slope of a secant line through two recent points on the graph of f(x).

This makes the method especially useful when the function is easy to evaluate but hard or expensive to differentiate. Typical use cases include engineering models, applied physics, and numerical analysis homework problems, where you only have a formula (or even empirical data) for f(x), not for its derivative.

Secant Method Formula

Suppose you want to solve f(x) = 0 and you have two initial guesses, x₀ and x₁, that you believe are near a root. The secant method constructs a line through the points (x₀, f(x₀)) and (x₁, f(x₁)) and then uses the intersection of this line with the x-axis as the next approximation.

The approximate derivative from these two points is the secant slope

f(x1) f(x1) f(x0) x1 x0

From this, the iteration formula for n ≥ 1 is

xn+1 = xn f(xn) (xn xn1 ) f(xn) f(xn1)

You start with x₀ and x₁, compute x₂ from the formula, then use x₁ and x₂ to compute x₃, and so on, until successive approximations become sufficiently close.

How to Use This Secant Method Calculator

The calculator applies the iteration above automatically. To run it effectively, follow these steps:

  1. Enter the function f(x):
    • Use math.js syntax (standard mathematical operators).
    • Examples: x^3 - x - 2, cos(x) - x, exp(x) - 5, x^2 + 3*x - 1.
    • Use sqrt(x) for square roots, exp(x) for e^x, and functions like sin, cos, log, etc.
  2. Choose two initial guesses x₀ and x₁:
    • They must be distinct values.
    • Pick values where you expect a root nearby (for example, where the function changes sign or crosses the axis on a quick plot).
    • The closer your initial guesses are to the actual root, the fewer iterations you typically need.
  3. Set the tolerance:
    • This controls how close successive approximations must be before the method stops.
    • Common values are 1e-4 (0.0001), 1e-6, or 1e-8.
    • Smaller tolerance means higher accuracy but potentially more iterations.
  4. Set the maximum number of iterations:
    • Protects against infinite loops when the method fails to converge.
    • Values between 20 and 100 are typical for most problems.
  5. Run the calculation and read the result:
    • The tool reports the last approximation to the root and how many iterations it used.
    • If the maximum number of iterations is reached before the tolerance is met, the output is only an approximate value and may be far from an actual root.

Interpreting the Results

The final value returned by the calculator is an approximate root of f(x) = 0. In practice, this means that f(x) evaluated at the reported value should be close to zero within the chosen tolerance.

You can check the quality of the solution by:

If the results change dramatically when you adjust the initial guesses or tolerance, the problem may be ill-conditioned for the secant method, or there may be multiple nearby roots.

Worked Example: Solving a Cubic Equation

Consider the equation f(x) = x^3 - x - 2 = 0. This function has a real root slightly above 1. We will apply the secant method with initial guesses x₀ = 1 and x₁ = 2.

  1. Evaluate the function:
    • f(1) = 1^3 - 1 - 2 = -2
    • f(2) = 2^3 - 2 - 2 = 4
  2. Compute the first new approximation:

    Using the secant update x₂ = x₁ - f(x₁) * (x₁ - x₀) / (f(x₁) - f(x₀)), we have

    x₂ = 2 - 4 * (2 - 1) / (4 - (-2)) = 2 - 4 / 6 = 1.333333...

  3. Next iteration:
    • f(1.3333) ≈ 1.3333^3 - 1.3333 - 2 ≈ -0.9629
    • Now use x₁ = 1.3333, x₂ ≈ 1.3333 and x₀ = 2 in the formula to get x₃.
    • Continuing this process, the sequence converges toward x ≈ 1.52138, which is the real root of x^3 - x - 2 = 0.

If you enter x^3 - x - 2 as f(x), set x₀ = 1, x₁ = 2, and choose a tolerance like 1e-6, the calculator should return a value very close to 1.52138.

Secant Method vs Other Root-Finding Methods

The secant method occupies a middle ground between derivative-based methods and more robust bracketing methods. The table below compares it with Newton's method and the bisection method.

Method Needs derivative? Convergence speed (when it works) Guarantee of staying in an interval? Typical use cases
Secant No Superlinear (faster than linear, slower than quadratic) No explicit guarantee When f(x) is easy to evaluate but f'(x) is hard or unknown
Newton's method Yes Quadratic near a simple root No; can diverge or jump away from the root Problems with a good initial guess and an analytic derivative
Bisection No Linear (relatively slow) Yes, stays inside the initial bracketing interval When you can find an interval where f changes sign and need guaranteed convergence

Assumptions, Limitations, and Common Pitfalls

While the secant method is simple and efficient, it has important limitations you should keep in mind when using this calculator:

For critical engineering decisions or sensitive scientific computations, treat the calculator as a helper rather than a final authority. Cross-check with alternative methods or analytical solutions when possible.

Enter function and guesses.

Embed this calculator

Copy and paste the HTML below to add the Secant Method Calculator - Root Finding Without Derivatives to your website.