Formula: Finite Difference Derivative Formula
- evaluationPointX: Evaluation Point X (x)
- quadraticCoeffA: Quadratic Coeff A (a)
- stepSizeH: Step Size H (h)
Compare O(h) forward difference vs. O(h²) central difference truncation errors.
The leading central difference error is h² times the third derivative divided by six. For f(x) = x³ + a·x², the third derivative is always 6, so the error is exactly h² everywhere. At h = 0.05 that is 0.0025, which is why the 1.2, 2 and 3 presets all report the same central error.
For this function the forward error is h times (3x + a), plus h². At x = 2, a = 3 and h = 0.05 that gives 0.05 × 9 = 0.45, plus 0.0025, for 0.4525. Add it to the exact slope of 24 and you get the forward estimate of 24.4525 the calculator shows.
The forward error is dominated by a term proportional to h, so halving h halves it. The central error is proportional to h², so halving h divides it by four. That difference is exactly what O(h) and O(h²) mean, and you can confirm it by running steps of 0.1 and 0.05 here.
No. The function is fixed as x³ + a·x², and you control only the coefficient a, the point x and the step h. That fixed form lets the calculator show exact derivatives beside the estimates. To test another function, apply the same three formulas in a spreadsheet or script with your own expression.
The three-point formula has a leading error proportional to the fourth derivative. A cubic has a fourth derivative of zero, so at ordinary step sizes the estimate matches 6x + 2a exactly. At an extremely small step such as 0.000000001, rounding takes over and the line drops to 0. On functions like sine the formula also has a genuine h² error.
The calculator returns an error asking for a step above zero, because the formulas divide by h. Negative steps are refused the same way. For a backward difference, keep h positive and compare the forward and central results. Any positive step is accepted, including very small ones that expose rounding error.
Only down to a point. Truncation error shrinks as h shrinks, but subtracting two nearly equal function values loses precision in floating-point arithmetic, and dividing by a tiny h magnifies that loss. The total error is smallest at an intermediate step that depends on the function and the machine precision.
With a = 3, the second derivative 6x + 6 is zero at x = −1, which removes the first-order part of the forward error. Both estimates are then off by h² only, 0.0025 at the default step. This is an inflection point, where a one-sided formula behaves better than usual.
It shifts the curvature of the function, since the second derivative is 6x + 2a. A larger a makes the curve bend more at a given x, which increases the forward difference error. It has no effect on the central first derivative error, which depends only on the constant third derivative.
Use it when you cannot evaluate the function at x − h, for example at the left edge of a domain or when stepping forward in time. It is also a reasonable choice when function evaluations are expensive and you already have f(x), since it needs only one new value.
The headline and supporting lines are rounded to three decimals, so differences smaller than about 0.0005 disappear. The interpretation sentence carries four decimals and shows errors such as 0.0025 directly. For convergence checks at small steps, read the sentence rather than the rounded result lines.
On this cubic with the defaults it overestimates, because the function is curving upward at x = 2 and a chord to the right is steeper than the tangent. Where the curvature 6x + 2a is negative, the forward estimate falls below the true slope instead. The sign of the error follows the sign of the second derivative.
This calculator does not take an arbitrary formula. It always differentiates the same family of curves, f(x) = x³ + a·x², where you choose the evaluation point x, the coefficient a and the step size h. That restriction is deliberate. Because the function is a simple polynomial, its exact derivatives are known in closed form, so every numerical estimate on the page can be compared with the true answer and its error read off directly.
The exact first derivative is 3x² + 2ax. The exact second derivative is 6x + 2a. The third derivative is the constant 6, and every derivative after that is zero. Those four facts explain almost everything the calculator shows, including a few results that look surprising at first.
With the defaults of x = 2, a = 3 and h = 0.05, the exact slope is 12 + 12 = 24 and the exact curvature is 12 + 6 = 18. The headline result is the central difference estimate of the slope, shown as 24.003, with the forward difference estimate of 24.453 and the second derivative of 18 listed below it.
The forward difference is (f(x+h) − f(x))/h. It looks only to one side of the point, so it measures the slope of a chord from x to x + h rather than the tangent at x. Expanding f(x+h) as a Taylor series shows the leading error is h·f″(x)/2, which is proportional to h. That is what O(h), first order, means: halve the step and you roughly halve the error.
For this cubic the error can be written out exactly. It is h·(3x + a) + h². At the defaults that is 0.05 × 9 plus 0.0025, which is 0.4525, and the forward estimate is 24.4525, displayed as 24.453. Try h = 0.1 and the error becomes 0.91; try h = 0.01 and it becomes 0.0901. The error falls by about ten times when h falls by ten times, the signature of a first-order method.
Notice the error depends on x and a through the curvature term. At x = 1.2 the forward error is 0.3325, and at x = 3 it is 0.6025. The more curved the function is at the point, the more a one-sided chord overshoots.
The central difference is (f(x+h) − f(x−h))/(2h). It takes the chord between two points placed symmetrically around x. When you subtract the two Taylor series, the curvature terms cancel, because they have the same sign on both sides. What survives as the leading error is h²·f‴(x)/6, which is second order, O(h²).
For this function f‴ is always 6, so the central error is exactly h², no matter what x or a you choose. At h = 0.05 that is 0.0025. Run x = 1.2 and the central estimate is 11.5225 against an exact 11.52, the same error of 0.0025. Run x = 3 and it is 45.0025 against 45, again 0.0025. The interpretation line on every preset shows the same central error for that reason.
That makes this page a clean demonstration of convergence order. Divide h by ten and the central error drops by a hundred: 0.01 at h = 0.1, 0.0025 at h = 0.05, 0.0001 at h = 0.01. On a general function the constant in front of h² changes with x, but the scaling is the same.
The third output is the second derivative estimate (f(x+h) − 2f(x) + f(x−h))/h². Its leading error is h²·f⁗(x)/12. On a cubic the fourth derivative is zero, so the error term vanishes and the formula returns the exact curvature, apart from floating-point rounding.
That is why the result line reads 18 with exact 18 at the defaults, 13.2 with exact 13.2 at x = 1.2, and 24 with exact 24 at x = 3. It stays exact even with a coarse step: at h = 1 the second derivative still comes out as 18, while the central first derivative has an error of 1 and the forward one an error of 10.
This is a property of the test function, not of the method. Applied to sin(x), an exponential or measured data, the three-point formula has a real O(h²) error. Do not read the perfect match here as evidence that the second derivative formula is more accurate than the first derivative formulas in general.
Try x = −1 with the default a = 3. The curvature 6x + 2a is zero there, so the first-order term in the forward error disappears and only the h² term remains. The calculator reports both estimates as −2.9975 against an exact −3, each with an error of 0.0025. The second derivative reads 0.
This is an inflection point, and it is a useful reminder of what the O(h) label really describes. It says how the error behaves in the worst case as h shrinks. At points where f″ happens to vanish, a one-sided formula can do much better than its order suggests.
The opposite case is also worth running. Set a = −6 and x = 0. The exact slope is 0, the central estimate is 0.0025, and the forward estimate is −0.2975. When the true derivative is close to zero, a forward difference error that would be small in relative terms elsewhere becomes the whole answer, and can even get the sign wrong.
Mathematically, a smaller h always reduces truncation error. Numerically it does not. When h is tiny, f(x+h) and f(x) are almost equal, and subtracting them throws away most of the significant digits in double-precision arithmetic. Dividing that noisy difference by a tiny h then magnifies it. Past a certain point, rounding error grows faster than truncation error shrinks, and the estimate gets worse.
The calculator lets you see this happen. At h = 0.0001 the forward error is 0.0009 and the central error rounds to zero at the displayed precision, so everything still looks healthy. Now enter h = 0.000000001. The first derivatives still display as 24, but the second derivative line collapses to 0 against an exact 18. Its formula divides by h squared, so the rounding noise in the numerator is multiplied enormously and the true curvature is lost completely.
The step must be above zero. A zero or negative h returns an error rather than a result; for a backward difference, use a positive h and compare the forward and central results instead.
In your own code, a common rule of thumb is a step near the square root of machine precision, scaled by the size of x, for a forward difference, and near the cube root for a central difference. Second differences need a larger step still. The best h depends on how smooth and how well scaled the function is.
You can turn two forward differences into something better without evaluating to the left of x. The trick is Richardson extrapolation. Because the forward error is mostly proportional to h, an estimate at h and another at h/2 have errors in a ratio of about two to one. Taking twice the finer estimate minus the coarser one cancels that leading term.
Run the calculator at h = 0.05 and at h = 0.025. The forward estimates are 24.4525 and 24.22563 (the second has an error of 0.2256, close to half of 0.4525). Twice 24.22563 minus 24.4525 is about 23.999, which is far closer to the exact 24 than either input. The leftover error is second order, the same order as a central difference.
The same idea applied to two central differences cancels the h² term and gives a fourth-order result. It is a cheap way to check, and improve, any finite difference you already have.
The main result and supporting lines are shown to three decimal places, while the interpretation sentence shows four. That is why the default central estimate appears as 24.003 in the headline but as 24.0025 in the sentence below. When you compare errors at small steps, use the interpretation line, because three decimals hide differences below 0.0005.
At h = 0.01, for example, the central estimate is displayed as 24, which looks perfect, while the sentence reveals 24.0001 and an error of 0.0001. The method is not exact there; the display simply cannot show the difference.
Units are labelled df/dx and d²f/dx², and the inputs carry their own symbols, x, a and h. They are dimensionless here because the function has no physical units. If you adapt the method to a real quantity, the derivative carries the unit of f divided by the unit of x.
The practical lesson is that the central difference is usually the better default when you can evaluate the function on both sides of the point. It costs the same two function evaluations as the forward difference for the first derivative, yet it gains a full order of accuracy. Forward differences remain useful at a boundary, where x − h is outside the domain, or in simulations that march forward in time.
A good habit, which this page lets you rehearse, is to check convergence. Compute the estimate at h and at h/2. If the change shrinks by about four each time you halve h, you are in the O(h²) regime. If it stops shrinking or starts jumping around, rounding error has taken over and you should stop reducing h.
For noisy measured data, neither formula is a cure. Differencing amplifies noise. Smoothing first, or fitting a curve and differentiating the fit, is often more reliable than any finite difference on raw samples.