Secant Method Calculator

Enter a function and two starting values and this calculator drives the secant iteration to a root of f(x) = 0, printing every step: the current pair, the new iterate, the residual and the change in x. No derivative is required, which is the whole point - the slope is estimated from the last two function values instead. Switch to the false position variant when you want the root kept inside a guaranteed bracket, and read the observed order of convergence to see whether the iteration is behaving as theory predicts.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Function f(x)Use x as the variable, ^ for powers, and names such as sin, cos, exp, ln, log and sqrt. Angles are radians.x^3 - 2*x - 5
First starting value x₀Any point near the root. For false position it must lie on the opposite side of the root from x₁.2
Second starting value x₁A second point, different from the first and with a different function value.3
VariantFalse position replaces the endpoint that shares a sign with the new value, so the root stays trapped.Secant (fastest)
Stopping tolerance on |Δx|The iteration stops when successive estimates differ by less than this.1e-10
Maximum iterationsA safety limit. False position on a strongly curved function can need several hundred.50

It returns

  • Root estimate — The last iterate produced before the stopping test was met.
  • Residual f(root) — Essentially zero at a genuine root. A large value means the iteration stopped somewhere else.
  • Iterations used
  • Final change in x
  • Observed order of convergence — About 1.618 for the secant method on a simple root, about 1 for false position.

The formula

xn+1=xnf(xn)(xnxn1)f(xn)f(xn1)
p=1+521.618

In plain text: xₙ₊₁ = xₙ − f(xₙ)·(xₙ − xₙ₋₁) / (f(xₙ) − f(xₙ₋₁))

  • xₙThe current estimate of the root
  • xₙ₋₁The previous estimate
  • fThe function whose zero you are looking for
  • xₙ₊₁The next estimate — where the chord through the last two points crosses the axis

The denominator is the slope of the chord through the last two points; it stands in for f′(xₙ) in Newton's method.

Updated Category Numerical Methods, Root Finding & Interpolation Verified against published test cases Reading time 11 min

What the secant method is for

The secant method solves f(x) = 0 using nothing but values of f. No derivative, no algebra, no rearranging - which is exactly what you need when f is a lookup table, the output of a simulation, or an expression whose derivative is unpleasant to write down.

The idea is one line long. Take your two most recent points, draw the straight line through (xₙ₋₁, f(xₙ₋₁)) and (xₙ, f(xₙ)), and take the point where that line crosses the axis as your next estimate. Repeat. Because a straight line through two nearby points on a smooth curve is a good local model of it, the estimates close in on the root quickly.

The variant this calculator also offers, false position (regula falsi), uses the identical formula but keeps the two points on opposite sides of the root. It gives up some speed and gains a guarantee: the root stays trapped between the endpoints, so the method cannot run away. Which you want depends on whether you value speed or safety more for the function in front of you.

The iteration, term by term

The update is

xₙ₊₁ = xₙ − f(xₙ) · (xₙ − xₙ₋₁) / (f(xₙ) − f(xₙ₋₁))

Read it as Newton's method with the derivative replaced by a difference quotient. Newton takes x − f(x)/f′(x); here the slope f′(xₙ) is estimated by (f(xₙ) − f(xₙ₋₁)) / (xₙ − xₙ₋₁), the slope of the chord through the last two points. Everything else is identical.

That substitution costs accuracy per step and saves a function evaluation. Newton needs both f and f′ at every iteration and converges quadratically, meaning the number of correct digits roughly doubles each step. The secant method needs only one new value of f per iteration - the previous one is reused - and converges with order φ = (1 + √5)/2 ≈ 1.618, the golden ratio. Measured per function evaluation rather than per iteration, that makes the secant method the faster of the two whenever a derivative evaluation costs about as much as a function evaluation, because 1.618 exceeds √2 ≈ 1.414, the effective per-evaluation order of Newton.

The denominator is the only thing that can fail. If the two function values are equal, the chord is horizontal and never meets the axis; the calculator stops and says so rather than dividing by zero. If they are merely close, the chord is nearly horizontal and the next iterate is thrown a long way off - the classic secant failure, and the reason a bad starting pair can diverge.

False position uses the same expression but chooses which old point to discard by sign rather than by age: it replaces whichever endpoint has the same sign as the new value, so the bracket survives every step. The cost is that on a convex stretch of curve one endpoint can sit still forever, and the interval then shrinks from one side only. That reduces the order of convergence to 1 - linear - which is why a stubborn regula falsi run can need many more iterations than the secant method on the same function.

Worked example: the root of x³ − 2x − 5

This is the cubic Newton used to illustrate his own method, published by Wallis in 1685. Its real root is 2.0945514815. Start from x0 = 2 and x1 = 3.

  1. Evaluate the ends. f(2) = 8 − 4 − 5 = −1. f(3) = 27 − 6 − 5 = 16. The signs differ, so a root lies between them.
  2. First step. x2 = 3 − 16(3 − 2)/(16 − (−1)) = 3 − 16/17 = 3 − 0.9411765 = 2.0588235.
  3. Evaluate there. 2.05882353 = 8.7268472, so f(2.0588235) = 8.7268472 − 4.1176470 − 5 = −0.3907998. The sign has flipped, so the estimate has crossed the root.
  4. Second step. Using the pair (3, 2.0588235): the numerator is (−0.3907998)(2.0588235 − 3) = (−0.3907998)(−0.9411765) = 0.3677645, and the denominator is −0.3907998 − 16 = −16.3907998. The correction is 0.3677645 ÷ (−16.3907998) = −0.0224373, so x3 = 2.0588235 − (−0.0224373) = 2.0812608.
  5. Keep going. Three more steps bring successive iterates into agreement at ten decimal places, at 2.0945514815.

Six iterations, six new function evaluations, ten correct digits. Bisection on the same starting interval would need about 34 evaluations to reach the same accuracy - log₂(1/10−10) = 33.2 halvings of a unit interval - because each step buys you a fixed factor of two rather than an accelerating one.

Watch the errors shrink. After the first step the estimate is off by 2.0945515 − 2.0588235 = 0.0357280; after the second, by 2.0945515 − 2.0812608 = 0.0132907. Each new error is roughly proportional to the product of the two before it, which is the relation eₙ₊₁ ≈ C eₙ eₙ₋₁ that produces the golden-ratio order.

Reading the iteration table

Start with the residual. A converged root has f(root) at or near the limits of floating-point precision - typically 10−12 or smaller for a well-scaled function. If the iterates have stopped moving but the residual is large, you have not found a root: you have found a place where the iteration is stuck, usually a pole where f blows up and changes sign. The calculator flags exactly that combination.

Next look at the |Δx| column. Healthy secant convergence shows this column collapsing faster than geometrically - each entry roughly the product of the two before it, scaled. A column falling by a constant factor each row means you are getting linear convergence, which happens at a multiple root (where f and f′ vanish together) or when running false position against a one-sided curve.

The observed order is estimated from the last four iterates as ln(eₙ/eₙ₋₁) / ln(eₙ₋₁/eₙ₋₂). Expect roughly 1.6 for the secant method on a simple root and roughly 1 for false position or for a repeated root. It is blank when there are too few iterations or when the errors are not decreasing monotonically, because the estimate is meaningless then.

A stopping test on |Δx| alone can lie in both directions. On a very flat function, small steps do not mean a small residual; on a very steep one, a large step can still leave you at a tiny residual. If your problem is scaled awkwardly, check both columns before accepting the answer.

Root-finders compared

Convergence order and cost for the standard one-dimensional methods on a simple root.
MethodOrderNew f evaluations per stepNeeds f′?Guaranteed to converge?
Bisection1 (factor 0.5 per step)1NoYes, given a sign change
False position11NoYes, given a sign change
Secant1.6181NoNo
Newton-Raphson21 plus one f′YesNo
Muller1.8391NoNo
Brent1.618 typical, 0.5 worst case1NoYes, given a sign change

Order p means the error obeys e_{n+1} ≈ C·eₙᵖ near the root. At a repeated root every method in this table drops to linear convergence.

What goes wrong, and what to do about it

  • The two starting values give nearly equal f. The chord is almost horizontal and the next iterate is flung far away. Separate the starting points, or pick them on opposite sides of the root.
  • The iteration leaves the domain. A step into negative territory under a square root or logarithm returns an undefined value and the run stops. False position cannot do this, because it never leaves the original bracket - a good reason to prefer it for functions with a restricted domain.
  • The root is repeated. If f touches the axis without crossing, both f and f′ vanish there, and every method in the table above degrades to linear convergence. Apply the secant method to f(x)/f′(x) instead, which turns a repeated root back into a simple one.
  • You converged to a pole, not a root. Functions like 1/(x−2) change sign across the pole and fool any sign-based test. Always check the residual, and plot the function across the interval before trusting a bracket.
  • False position stagnates. One endpoint never moves and the interval shrinks by an ever-smaller amount. The Illinois modification - halving the retained endpoint's function value each time it is kept - fixes this; so does switching to the plain secant variant once you are close.
  • The tolerance is tighter than the arithmetic. Below about 10−15 relative, double precision cannot distinguish successive iterates and the loop simply runs out of iterations. Set the tolerance to what the problem needs, not to the smallest number you can type.

Where the secant method fits

Every general-purpose root-finding routine in a numerical library is a hybrid, and the secant method is usually the fast half of it. Brent's method - the algorithm behind scipy.optimize.brentq and MATLAB's fzero - keeps a bracket like bisection but attempts an inverse quadratic interpolation step first, falling back to the secant step, and falling back again to bisection when the fast steps misbehave. You get secant speed on well-behaved functions and bisection's guarantee on badly behaved ones.

Seen from another angle, the secant method is inverse linear interpolation applied repeatedly: it fits a straight line to x as a function of f and reads off where f = 0. Fit a parabola through three points instead and you get Muller's method, with order 1.839. The connection to polynomial interpolation is exact, not analogical.

If you can differentiate your function cheaply and in closed form, Newton-Raphson is the better tool and its quadratic convergence is hard to beat near the root. If you are solving a differential equation and need a root inside each implicit time step - the situation in stiff solvers - a secant or Newton step is what sits inside the loop of an implicit Runge-Kutta or backward Euler scheme. And for a system of nonlinear equations rather than a single one, Broyden's method is the secant idea generalised: it maintains an approximate Jacobian updated from successive function differences instead of computing derivatives.

Historically the method is older than calculus. A rule equivalent to false position appears in the Egyptian Rhind papyrus and in Chinese and medieval Islamic arithmetic texts as a way to solve linear problems by guessing twice and correcting. The modern reading - as Newton's method with the derivative approximated - only makes sense after Newton, but the arithmetic long predates it.

Frequently asked questions

What is the difference between the secant method and false position?

The formula is identical; the bookkeeping is not. The secant method always discards the older of its two points, so the pair chases the root and can end up on the same side of it. False position discards whichever point shares a sign with the new value, so the pair always straddles the root. That makes false position safe but linear, and the secant method fast but capable of diverging. Choose false position when the function has a restricted domain or a nearby pole.

Why does the secant method converge with order 1.618?

Because the error at each step is proportional to the product of the two previous errors: eₙ₊₁ ≈ C·eₙ·eₙ₋₁. Assume the errors behave like eₙ₊₁ = K·eₙᵖ and substitute, and the exponent must satisfy p² = p + 1. The positive solution is the golden ratio (1 + √5)/2 = 1.618. That is not a coincidence of this method - it is the signature of any two-term recurrence in the errors.

Do I need my starting points to bracket the root?

Not for the plain secant method - it will happily start with two points on the same side and often still converge. You do need a bracket for false position, and the calculator refuses to run that variant without one. In practice, bracketing is worth the trouble even for the secant method: it tells you a root exists, which the method itself never checks.

How many iterations should I expect?

From a decent starting pair, five to eight iterations reach the limits of double precision on a simple root. If you are past twenty and still moving, something structural is wrong - a repeated root, a pole, or starting points far from any crossing. The default limit of 50 is generous for the secant method and sometimes tight for false position, which can need hundreds of steps on a strongly convex curve.

What tolerance should I use?

Set it to the precision your answer actually needs, typically 10−8 to 10−10 for engineering work. Tolerances below about 10−15 relative to the size of the root are below what double precision can resolve, so the loop cannot satisfy them and simply exhausts its iteration limit. Remember the test is on the change in x, not on the residual, and check both before accepting a result.

Can the method find complex roots?

Not as implemented here, which works entirely in real arithmetic. The secant iteration does generalise to complex numbers directly, and Muller's method is often preferred for that job because its quadratic fit can jump to a complex root from real starting points. For polynomials specifically, a companion-matrix eigenvalue computation finds every root, real and complex, in one shot.

Why did my run stop with a value that is not a root?

Two common causes. Either the iteration hit the maximum number of steps, in which case the value shown is just the last iterate and the warning says so; or the iterates converged to a pole, where f changes sign by going through infinity rather than through zero. Check the residual f(root) that the calculator reports - at a genuine root it is essentially zero, and at a pole it is enormous.

How do I enter my function?

Use x as the variable, ^ for powers, and the usual function names: sin, cos, tan, exp, ln, log (base 10), sqrt, abs. Multiplication can be written explicitly or implied, so 2x, 2*x and 2 x all work. Angles are in radians, and pi and e are recognised constants.

References

  • Numerical Analysis, 10th ed. (Chapter 2, Solutions of Equations in One Variable) — Richard L. Burden and J. Douglas Faires, Cengage Learning
  • Algorithms for Minimization Without Derivatives (Chapter 4, zeroin) — Richard P. Brent, Prentice-Hall; Dover reprint
  • Numerical Recipes: The Art of Scientific Computing, 3rd ed. (Chapter 9, Root Finding) — Press, Teukolsky, Vetterling and Flannery, Cambridge University Press