Equations & optimization

Numerical Root Finding Laboratory

Solves f(x) = 0 for a cubic, cosine or exponential equation by bisection, Newton-Raphson and the secant method side by side. Every iteration is computed and shown, with each method's status (converged, out of iterations, flat slope, no sign change or diverged), its estimate, residual and step, the fastest method, a 151-point function curve and five scored challenges. For learning numerical methods.

Last updated

Calculator overview

Inputs and outputs

This summary comes from the calculator's published input and output contract.

Inputs

Iteration limit (required)
About this input

The most rows each method may use, a whole number from 1 to 50. A method that has not met a tolerance by then reports MAX_ITERATIONS.

Default 50 Range 1 to 50
Starting guess (Newton-Raphson) (required)
About this input

Where Newton-Raphson starts, from -100 to 100. A guess near the root converges fastest; a guess on a flat stretch of the curve can stall it.

Default 1 Range -100 to 100
Equation family (required)
About this input

The shape of the equation to solve. Cubic polynomial is a x^3 + b x^2 + c x + d; Cosine is a cos(b x) + c x + d; Exponential is a exp(b x) + c x + d. The page never accepts typed formulas.

Default Cubic polynomial Allowed Cubic polynomial, Cosine, Exponential
Step tolerance (required)
About this input

A method has also converged when its step is at most this times max(1, size of x), from 1E-14 to 0.01. For bisection the step is the half-width of the bracket.

Default 0.0001 Range 1E-14 to 0.01
Residual tolerance (required)
About this input

A method has converged when the size of f at its new estimate is at most this, from 1E-14 to 0.01. The default 1E-4 shows a handful of Newton-Raphson steps; tighter values show more digits and more rows.

Default 0.0001 Range 1E-14 to 0.01
Your predicted method (required)
About this input

Your answer for challenges 3 and 5: Bisection, Newton-Raphson or Secant, or Not yet predicted. Until you predict, those challenges keep the method results hidden.

Default Not yet predicted Allowed Not yet predicted, Bisection, Newton-Raphson, Secant
Coefficient d (required)
About this input

The constant term d, from -100 to 100, which shifts the whole curve up or down.

Default -2 Range -100 to 100
Challenge number (required)
About this input

0 for free exploration, or 1 to 5 to load a challenge. A challenge replaces the equation with its own; your bracket, guess and other settings stay in use.

Default 0 Range 0 to 5
Bracket low end (required)
About this input

The left end of the interval bisection starts from, and the first of the two points the secant method starts from. From -100 to 100, and below the high end.

Default 1 Range -100 to 100
Bracket high end (required)
About this input

The right end of the interval bisection starts from, and the second starting point of the secant method. Bisection needs f to have opposite signs at the two ends.

Default 2 Range -100 to 100
Coefficient c (required)
About this input

The coefficient c, from -100 to 100: the slope of the straight-line term c x in every family.

Default 0 Range -100 to 100
Coefficient b (required)
About this input

The coefficient b, from -100 to 100. In the cubic it multiplies x^2; in the cosine family it sets the frequency, and in the exponential family the growth rate.

Default 1 Range -100 to 100
Coefficient a (required)
About this input

The coefficient a of the chosen family, from -100 to 100. In the cubic it multiplies x^3; in the cosine and exponential families it scales the wave or the growth curve.

Default 0 Range -100 to 100

Outputs

Newton-Raphson final step
About this output

The size of Newton-Raphson's last step, the distance between its last two estimates. Blank when the last row could not take a step.

No unit declared
Newton-Raphson status
About this output

How Newton-Raphson ended: CONVERGED, MAX_ITERATIONS, DERIVATIVE_ZERO (a flat tangent), DIVERGED (an estimate ran too far) or NOT_RUN.

No unit declared
Root marked on the plot
About this output

The root marked on the plot: the estimate of the first method, of bisection, Newton-Raphson and secant, that converged. Blank when none converged. It shows where the root is without saying which method found it.

No unit declared
Newton-Raphson iterations
About this output

Every Newton-Raphson row: the iteration, x, f(x), the derivative, the correction f/f-prime, the next x, the size of f there, the step and the row status. A tangent on the plot joins (x, f(x)) to (next x, 0).

No unit declared
Newton-Raphson residual, abs f
About this output

The size of f at Newton-Raphson's estimate.

No unit declared
Formula module versions
About this output

The versions of the formula modules the model is built from: the three root-finding methods and the convergence status rules.

No unit declared
Model version
About this output

The version of this calculation model, so a saved result can be matched to the model that produced it.

No unit declared
Newton-Raphson iterations
About this output

How many rows Newton-Raphson used, including the row where it stopped.

No unit declared
Newton-Raphson estimate of the root
About this output

Newton-Raphson's estimate of the root. After a flat tangent or a divergence it is the last point the method could evaluate.

No unit declared
Residual tolerance in effect
About this output

The residual tolerance the methods used.

No unit declared
Secant iterations
About this output

Every secant row: the iteration, x, f(x), the previous point and f there, the next x, the size of f there, the step and the row status. A chord on the plot joins (x, f(x)) to (next x, 0).

No unit declared
Secant final step
About this output

The size of the secant method's last step. Blank when the last row could not take a step.

No unit declared
Step tolerance in effect
About this output

The step tolerance the methods used.

No unit declared
Flat-slope threshold
About this output

A derivative or chord slope smaller than this in size stops Newton-Raphson or the secant method with DERIVATIVE_ZERO, because dividing by it would throw the next estimate far away.

No unit declared
Secant status
About this output

How the secant method ended: CONVERGED, MAX_ITERATIONS, DERIVATIVE_ZERO (a flat chord), DIVERGED or NOT_RUN.

No unit declared
Secant estimate of the root
About this output

The secant method's estimate of the root. After a flat chord or a divergence it is the last point the method could evaluate.

No unit declared
Spread of the converged estimates
About this output

The largest converged estimate minus the smallest, when at least two methods converged. A spread above 1% of the root's size means the methods found different roots.

No unit declared
Secant residual, abs f
About this output

The size of f at the secant method's estimate.

No unit declared
Secant iterations
About this output

How many rows the secant method used, including the row where it stopped.

No unit declared
Challenge feedback
About this output

A one-line explanation of the selected challenge's result, with a hint when it is not met yet, or a request for your prediction in challenges 3 and 5.

No unit declared
Bisection iterations
About this output

Every bisection row: the iteration, the bracket ends a and b with f at each, the midpoint m, the size of f(m), the half-width and the row status. STEP means the method continues; later rows are blank.

No unit declared
Challenge score
About this output

100 when the selected challenge is met, otherwise 0.

No unit declared
Challenge goal
About this output

What the selected challenge asks you to do. Blank with no challenge selected.

No unit declared
Bisection final half-width
About this output

Half the width of bisection's last bracket: the root lies within this distance of the estimate.

No unit declared
Bisection iterations
About this output

How many rows bisection used, including the row where it stopped; 0 when it could not start.

No unit declared
Bisection estimate of the root
About this output

Bisection's estimate of the root: the midpoint of its last bracket. Blank when bisection could not start.

No unit declared
Bisection status
About this output

How bisection ended: CONVERGED, MAX_ITERATIONS, NO_SIGN_CHANGE (the bracket ends give f the same sign) or NOT_RUN (the inputs are not valid, or a prediction challenge is waiting for your prediction).

No unit declared
Bisection residual, abs f
About this output

The size of f at bisection's estimate. Near zero means the estimate nearly solves the equation.

No unit declared
Challenge result
About this output

MET or NOT MET for the selected challenge, scored by the model from the methods' results; No challenge selected when the challenge number is 0.

No unit declared
Function curve: 151 points computed by the model
About this output

151 points of the equation solved, x and f(x), spanning the bracket, the starting guess and every root a method found, at least 1 wide, with 10% to spare on each side. The plot passes only through these computed points; f is blank where the exponential would overflow.

No unit declared
Fastest converged method
About this output

The converged method that needed the fewest iterations; a tie goes to the earlier of bisection, Newton-Raphson and secant. None when no method converged.

No unit declared
Model Status
About this output

OK when all three methods converged to the same root, or while a selected challenge is not met yet (the challenge feedback says what to try). CHECK names the methods that did not converge, or warns that they found different roots. NOT VALID names the input to fix.

No unit declared
Iteration cap in effect
About this output

The iteration limit in effect: your limit, or 6 in challenge 2, whose budget caps every method.

No unit declared
Equation family solved
About this output

The equation family actually solved: yours, or the challenge's while a challenge is selected.

No unit declared
Coefficient b solved
About this output

The coefficient b actually solved: yours, or the challenge's.

No unit declared
Coefficient a solved
About this output

The coefficient a actually solved: yours, or the challenge's.

No unit declared
Coefficient d solved
About this output

The coefficient d actually solved: yours, or the challenge's.

No unit declared
Coefficient c solved
About this output

The coefficient c actually solved: yours, or the challenge's.

No unit declared
This page is provided by LogicCommons for informational purposes only. Results are analysis outputs computed from the inputs you supply and are not professional advice. Verify all inputs and results independently.

LogicCommons is in beta. If a result, label, or reference looks wrong, tell us here; we read every message.

Methodology

Purpose and model boundary

This lab solves one equation f(x) = 0 by three numerical methods side by side: bisection, Newton-Raphson and the secant method. The equation is one of three fixed families (a cubic polynomial, a cosine, or an exponential), each with four coefficients a, b, c and d from -100 to 100. Every iteration of every method is computed and shown, up to 50 rows a method, together with how each method ended (converged, out of iterations, flat slope, no sign change or diverged), its estimate, residual and last step, the fastest converged method, a 151-point curve of f, and five scored challenges.

It is a lab for learning how root-finding methods behave: why bisection needs a sign change, why Newton-Raphson is fast near a simple root and slow near a repeated one, and how a poor start can make a method stall, cycle or run away. It is not a general equation solver. It accepts no typed formulas, finds only real roots, and a CONVERGED status means the method's stopping test was met, not that the root is exact to every digit shown.

The model is the calculation authority. The page sends the values you set to the model and draws only what the model returns: the curve, the tangents, chords and brackets, and the residual plot all come from the model's own rows. The page computes no root, residual or iteration itself.

Inputs and units

Every input is a pure number; the lab has no physical units.

Input Meaning and unit
Equation family Cubic polynomial, Cosine or Exponential. The cubic is a·x³ + b·x² + c·x + d; the cosine family is a·cos(b·x) + c·x + d; the exponential family is a·exp(b·x) + c·x + d.
Coefficient a From -100 to 100. In the cubic it multiplies x³; in the cosine and exponential families it scales the wave or the growth curve.
Coefficient b From -100 to 100. In the cubic it multiplies x²; in the cosine family it sets the frequency, and in the exponential family the growth rate.
Coefficient c From -100 to 100: the slope of the straight-line term c·x in every family.
Coefficient d From -100 to 100: the constant term, which shifts the whole curve up or down.
Bracket low end From -100 to 100, and below the high end. The left end of the interval bisection starts from, and the first of the two points the secant method starts from.
Bracket high end From -100 to 100. The right end of bisection's interval, and the secant method's second starting point. Bisection needs f to have opposite signs at the two ends.
Starting guess (Newton-Raphson) From -100 to 100. Where Newton-Raphson starts; only Newton-Raphson uses it.
Iteration limit A whole number from 1 to 50: the most rows each method may use.
Residual tolerance From 1×10⁻¹⁴ to 0.01 (default 1×10⁻⁴). A method has converged when the size of f at its new estimate is at most this.
Step tolerance From 1×10⁻¹⁴ to 0.01 (default 1×10⁻⁴). A method has also converged when its step is at most this times max(1, size of x).
Challenge number 0 for free exploration, or 1 to 5 to load a challenge.
Your predicted method Not yet predicted, Bisection, Newton-Raphson or Secant: your answer for challenges 3 and 5.

Where each input is set:

  • On the canvas only: your predicted method, chosen with the prediction challenges; it is not in the input panel.
  • In the input panel: every other input. The bracket low end, the bracket high end and the starting guess can also be dragged on the plot, as the two bracket markers and the x₀ marker.
  • The page offers the two tolerances as one choice, from 0.01 to 1×10⁻⁸, which sets both; the model accepts any value from 1×10⁻¹⁴ to 0.01 for each.

The lab has no sign convention beyond the equation itself: x increases to the right, and f(x) is positive above the axis.

Governing relationships

The equation and its derivative. The model evaluates f and its exact derivative f′ in this form:

  • Cubic: f(x) = ((a·x + b)·x + c)·x + d (Horner's form), f′(x) = (3·a·x + 2·b)·x + c.
  • Cosine: f(x) = a·cos(b·x) + c·x + d, f′(x) = -a·b·sin(b·x) + c.
  • Exponential: f(x) = a·exp(b·x) + c·x + d, f′(x) = a·b·exp(b·x) + c.

The exponential can overflow, so a point x is evaluated only while b·x ≤ 700.

The stopping tests. With tolF the residual tolerance and tolX the step tolerance, a method converges on a row when |f(new estimate)| ≤ tolF, or when its step ≤ tolX · max(1, |new estimate|). The residual test is absolute and the step test is relative. A method that has not converged on its last allowed row stops with MAX_ITERATIONS.

Bisection. If f(low) and f(high) have the same sign (the product of their signs is positive), bisection cannot start and reports NO_SIGN_CHANGE with no rows. A root exactly at an end still lets it run. Otherwise it starts from [a₁, b₁] = [low, high] and on row k computes

  • the midpoint m = (a + b) / 2 and the half-width h = (b - a) / 2;
  • converged when |f(m)| ≤ tolF or h ≤ tolX · max(1, |m|);
  • otherwise the next bracket is [a, m] when the signs of f(a) and f(m) multiply to zero or less, and [m, b] otherwise.

The half-width halves on every row, so bisection always closes in once it has a sign change, but slowly.

Newton-Raphson. It starts from x₁ = the starting guess and on row k, in this order:

  1. If |f(x)| ≤ tolF, the guess is already a root: CONVERGED, with a step of 0.
  2. If |f′(x)| < 1×10⁻¹², the tangent is flat: DERIVATIVE_ZERO.
  3. Otherwise the next estimate is x_new = x - f(x) / f′(x), the point where the tangent at (x, f(x)) crosses the axis. If |x_new| > 1,000,000, or the exponential cannot be evaluated there, the method stops with DIVERGED.
  4. Otherwise it is CONVERGED by the stopping tests above, or continues to the next row from x_new.

Secant. It replaces the tangent by the chord through the last two points. It starts from x₀ = the bracket low end and x₁ = the bracket high end (not from the guess), and on row k, with the chord slope s = (f(x_k) - f(x_k-1)) / (x_k - x_k-1):

  1. If |f(x_k)| ≤ tolF: CONVERGED, with a step of 0.
  2. If |s| < 1×10⁻¹², the chord is flat: DERIVATIVE_ZERO.
  3. Otherwise x_new = x_k - f(x_k) / s, then the same DIVERGED and convergence tests as Newton-Raphson. The next row uses x_new and x_k.

Comparing the methods. The fastest method is the converged method with the fewest rows; a tie goes to the earlier of bisection, Newton-Raphson and secant. The converged estimates count as one root when their spread (largest minus smallest) is at most 1% of max(1, the largest estimate's size).

The function curve. The model samples f at 151 evenly spaced points. The window spans the bracket ends, the starting guess and every converged estimate, is widened to at least 1 if narrower (centred on those points), and has 10% of its width added on each side.

Calculation sequence

The model works through the relationships above in this order:

  1. It checks your inputs in the order of the status list under Errors and warnings, up to the challenge number and predicted method.
  2. It fixes the equation solved: your equation, or in a challenge the challenge's own. It then checks that this equation is not zero for every x and, in the exponential family, that it can be evaluated at the bracket ends and the starting guess. Under NOT VALID no method runs. Your bracket, guess, tolerances and iteration limit stay in use; challenge 2 caps the limit at 6.
  3. It runs bisection, Newton-Raphson and the secant method row by row, each until it converges, stops or reaches the iteration limit.
  4. It reads each method's status, estimate, residual and final step from its stopping row, then compares the methods for the fastest converged method and the spread of the converged estimates.
  5. It samples the function curve over a window that spans the bracket ends, the starting guess and every converged estimate.
  6. It sets the status and, in a challenge, scores the challenge.

Outputs and interpretation

  • Status of each method: CONVERGED, MAX_ITERATIONS, DERIVATIVE_ZERO (a flat tangent or chord), NO_SIGN_CHANGE (bisection only), DIVERGED (Newton-Raphson and secant only) or NOT_RUN.
  • Estimate of the root: for CONVERGED or MAX_ITERATIONS, the new estimate of the stopping row (for bisection, the midpoint of its last bracket); after DERIVATIVE_ZERO or DIVERGED, the last point the method could evaluate. Blank when the method did not run.
  • Iterations: the rows used, including the row where the method stopped; 0 when it could not start.
  • Residual: |f| at the estimate. Near zero means the estimate nearly solves the equation.
  • Final step: the distance between the last two estimates, or for bisection the last half-width, which bounds how far the root can be from bisection's estimate. 0 when the starting point already met the residual tolerance; blank when the last row could not take a step (a flat slope or a divergence).
  • Fastest converged method, or None; the spread of the converged estimates when at least two converged; and the root marked on the plot: the estimate of the first converged method, in the order bisection, Newton-Raphson, secant.
  • Settings used: the iteration cap and the two tolerances in effect, the flat-slope threshold (1×10⁻¹²), and the equation family and coefficients actually solved (the challenge's while a challenge is selected).
  • Iteration tables: one per method, 50 rows each; the rows after a method stops are blank. Every row reads STEP while the method continues and its final status on the stopping row.
    • Bisection: iteration, left end a, f(a), right end b, f(b), midpoint m, size of f(m), half-width, status.
    • Newton-Raphson: iteration, x, f(x), derivative, correction f/f′, next x, size of f(next x), step, status. The correction is blank on a row that converged before stepping and on a DERIVATIVE_ZERO row.
    • Secant: iteration, x, f(x), previous x, f(previous x), next x, size of f(next x), step, status.
  • Function curve: 151 points (x, f(x)); f is blank where the exponential would overflow.

Reading the results: the plot draws the curve through the model's points only, with each method's tangent (Newton-Raphson), chord (secant) or bracket (bisection) row by row, and a residual chart of the size of f on each row on a log scale. Several converged methods can find different roots of the same equation; the spread then says so. Near a repeated root a small residual pins x only loosely: for a triple root a residual of 1×10⁻¹² pins x only to about 1×10⁻⁴, and for a double root to about 1×10⁻⁶, so the estimates differ in their later digits.

Challenges

Each challenge replaces the equation with its own (shown under "Settings used"); your bracket, guess, tolerances and other settings stay in use. On the page, selecting a challenge first loads that challenge's starting values, including the bracket, guess, iteration limit and tolerances, and the page names the inputs that challenge lets you change. The model scores each one MET (100) or NOT MET (0) from the methods' own results, and gives a one-line hint while it is not met.

  1. Choose a valid root bracket. Enter a bracket no wider than 1 in which bisection converges.
  2. Reach the residual target within an iteration budget. Every method is capped at 6 iterations (or your lower limit); choose a starting guess from which Newton-Raphson converges with a residual of 1×10⁻¹⁰ or less.
  3. Compare two methods on a difficult function. Predict which needs fewer iterations here, bisection or Newton-Raphson. It is met when both converge and your prediction names the one with fewer rows (a tie counts for bisection).
  4. Repair a poor initial guess. Newton-Raphson cycles from the starting guess given; choose a guess from which it converges.
  5. Identify where bisection is unsuitable. Predict which method cannot find this root. It is met when the method you name does not converge while at least one other method does.

Challenges 3 and 5 hold back the answer until you predict: while your prediction reads Not yet predicted, every method reads NOT_RUN with 0 iterations, the estimates, residuals, steps and spread are blank, the fastest method reads None and the tables are empty. The curve and the root marker stay. Once you predict, every result appears and the challenge is scored. Your prediction changes nothing in challenges 1, 2 and 4.

Validation and status logic

The status reads the first match in the list under Errors and warnings: the NOT VALID checks first, then, while a challenge is selected and not met yet, OK; then the two CHECK items; then OK. Your coefficients are checked even while a challenge replaces them, and the zero-equation check applies to the equation solved. The status does not report a method failure while you work on a challenge; the challenge feedback gives the hint.

Assumptions and limitations

  • Three equation families only, with real coefficients from -100 to 100; bracket ends and the guess from -100 to 100. Only real roots are found.
  • At most 50 rows a method. Tolerances from 1×10⁻¹⁴ to 0.01; the residual test is absolute, the step test is relative to max(1, |x|).
  • A derivative or chord slope smaller than 1×10⁻¹² in size stops a method with DERIVATIVE_ZERO; a new estimate beyond 1,000,000 in size, or where b·x > 700 in the exponential family, stops it with DIVERGED.
  • No cycle detection: a method that cycles runs until its iteration limit and reports MAX_ITERATIONS.
  • A value sitting within about 1×10⁻⁹ (relative) of a tolerance or threshold may flip a status. Chaotic iterations, such as Newton-Raphson on an equation with no real root, amplify last-digit differences over many rows.
  • Near a multiple root the methods slow down and the estimate is less precise than the residual suggests.

Restrictions and non-computing states

Under NOT VALID every method reads NOT_RUN, the tables and the curve are blank, the iteration counts and the challenge score are 0, the fastest method reads None, and a selected challenge reads NOT MET.

In challenges 3 and 5, until you predict, the methods read NOT_RUN and their results are held back, as described under Challenges.

Errors and warnings

The status messages, first match wins:

  • NOT VALID: choose an equation family from the list — the family is not one of the three.
  • NOT VALID: each coefficient must be a number from -100 to 100 — your coefficients are checked even while a challenge replaces them.
  • NOT VALID: the bracket ends and the starting guess must be numbers from -100 to 100
  • NOT VALID: the low end of the bracket must be below the high end
  • NOT VALID: the iteration limit must be a whole number from 1 to 50
  • NOT VALID: each tolerance must be from 1×10⁻¹⁴ to 0.01
  • NOT VALID: the challenge number must be a whole number from 0 to 5, and the predicted method one of the listed choices
  • NOT VALID: this equation is zero for every x, so every number is a root — in the equation solved: a cubic with every coefficient 0, or a cosine or exponential with c = 0 and either a = d = 0, or b = 0 and a + d = 0.
  • NOT VALID: f(x) is too large to evaluate at the bracket ends or the starting guess (b times x is above 700) — exponential family only.
  • OK while a challenge is selected and not met yet: the status does not report a method failure while you work on a challenge; the challenge feedback gives the hint.
  • CHECK: not every method converged (bisection …, Newton-Raphson …, secant …) — any method did not converge; the three final statuses are named.
  • CHECK: the methods converged to different roots; this equation has more than one — all three converged and their spread is above 1% of max(1, the largest estimate's size).
  • OK — all three methods converged to the same root.

References

This laboratory is an educational comparison of three classic ways to find a root of an equation f(x) = 0. Bisection halves a bracket whose ends give f opposite signs, so the root stays inside and the bracket halves on every step. Newton-Raphson follows the tangent, using the exact derivative of the chosen function, and near a simple root roughly doubles the number of correct digits each step, but a flat tangent, a cycle or a distant start can stop it. The secant method replaces the derivative with the slope of the chord through the last two estimates. Each method stops when the size of f falls within the residual tolerance, or its step within the step tolerance (relative to x when the size of x is larger than 1).

Sources and further reading

  • Bisection, Newton's method and the secant method, with their orders of convergence: R. L. Burden, J. D. Faires and A. M. Burden, Numerical Analysis, 10th edition, Cengage Learning, 2016, chapter 2, Solutions of Equations in One Variable.
  • Bracketing, bisection, the secant method and Newton-Raphson in practice, and when each fails: W. H. Press, S. A. Teukolsky, W. T. Vetterling and B. P. Flannery, Numerical Recipes: The Art of Scientific Computing, 3rd edition, Cambridge University Press, 2007, chapter 9, Root Finding and Nonlinear Sets of Equations.
  • The solution of equations by iteration and the rate of convergence: E. Süli and D. F. Mayers, An Introduction to Numerical Analysis, Cambridge University Press, 2003, chapter 1, Solution of equations by iteration. doi:10.1017/CBO9780511801181

No table or text from any of these publications is reproduced, and none of their authors or publishers has reviewed or endorses this laboratory.

This laboratory is for learning. Its results hold only within its stated ranges; check any root you rely on with an independent method.

Results are informational and not professional advice. See our Terms of Use. Powered by SpreadsheetWeb · About · Privacy · Terms