Finite Difference Numerical Derivative (Forward O(h) vs. Central O(h²) & Second Derivative) Calculator

Compare O(h) forward difference vs. O(h²) central difference truncation errors.

Central Difference First Derivative f′(x) 24.003 df/dx
Exact Analytical First Derivative 24 df/dx
Forward Difference O(h) Estimate 24.453 df/dx
Central 2nd Derivative f″(x) 18 d²f/dx² (exact 18)
Inputs
Try:
x
Point x at which to differentiate f(x) = x³ + a·x².
a
Coefficient a in f(x) = x³ + a·x².
h
Finite difference step size h.
Results & Graph
Central Difference First Derivative f′(x)
24.003 df/dx
Exact Analytical First Derivative
24 df/dx
Forward Difference O(h) Estimate
24.453 df/dx
Central 2nd Derivative f″(x)
18 d²f/dx² (exact 18)

Central Difference First Derivative f′(x)

Graph 1 • How the inputs feed Finite Difference Derivative
Finite Difference Numerical Derivative (Forward O(h) vs. Central O(h²) & Second Derivative) Calculator • Custom Domain Schematic (Numerical Analysis & Calculus) evaluatiquadratiFinite Difference Deri Evaluation Point X: 2 x • Quadratic Coeff A: 3 a CENTRAL DIFFERENCE FIRST D 24.003 df/dx • Exact Analytical First: 24 df/dx • Forward Difference O(h: 24.453 df/dx Eq: f′_central(x) = [f(x+h) − f(x−h)
Graph 2 • Central Difference First Derivative f′(x) as Evaluation Point X changes (40% to 160% of current)
0 df/dx 27.46 df/dx 54.91 df/dx 6.72 0.800x 11.52 1.20x 17.28 1.60x 24.00 2x 31.68 2.40x 40.32 2.80x 49.92 3.20x
Graph 3 • Evaluation Point X and Quadratic Coeff A together Compares Central Difference First Derivative f′(x) when Quadratic Coeff A is shifted +25% (solid) vs. −25% (dashed).
0 df/dx 21.88 df/dx 43.76 df/dx --- Quadratic Coeff A @ 75% 16.38 -30% 21.42 -15% 27.00 +0% 33.12 +15% 39.78 +30%
Summary: At x=2 (h=0.05), Central Difference O(h²) is 24.0025 (error 0.0025) vs. Forward Difference O(h) 24.4525 (error 0.4525).
Summary: At x=2 (h=0.05), Central Difference O(h²) is 24.0025 (error 0.0025) vs. Forward Difference O(h) 24.4525 (error 0.4525).
Interactive chart & math engine powered by CalculatorGraph

Formula: Finite Difference Derivative Formula

f′central(x) = [f(x+h) − f(x−h)] / (2h)
f″central(x) = [f(x+h) − 2f(x) + f(x−h)] / h²
f′_central(x) = [f(x+h) − f(x−h)] / (2h); f″_central(x) = [f(x+h) − 2f(x) + f(x−h)] / h²
  • evaluationPointX: Evaluation Point X (x)
  • quadraticCoeffA: Quadratic Coeff A (a)
  • stepSizeH: Step Size H (h)

Frequently Asked Questions

Why is the central error the same at every x on this page?

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.

How do I calculate the forward difference error by hand?

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.

Why does halving h quarter the central error but only halve the forward error?

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.

Can I enter my own function?

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.

Why is the second derivative estimate always exact?

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.

What happens if I type a step size of zero?

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.

Is a smaller step always more accurate?

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.

Why do forward and central estimates match at x = −1?

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.

What does the coefficient a change?

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.

When should I prefer a forward difference?

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.

How many decimal places should I trust in the result?

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.

Does the forward difference overestimate or underestimate the slope?

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.

The test function and why it was chosen

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.

Forward difference: an error that shrinks with h

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.

Central difference: why the error is always h squared here

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 three-point second derivative is exact on a cubic

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.

A point where forward and central agree

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.

Very small steps and the rounding wall

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.

Squeezing more accuracy from two forward estimates

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.

Reading the rounded display carefully

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.

Taking these results into real numerical work

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.