Cubic Regression Calculator

Fit a cubic curve to your data using least squares and get all four coefficients, R², and predictions instantly.

∼ Cubic Regression Calculator
Coefficient a (x³)
-
Coefficient b (x²)
-
Coefficient c (x)
-
Coefficient d (const)
-
R² (R-squared)
-
Data Points (n)
-

📖 What is Cubic Regression?

Cubic regression fits a third-degree polynomial - y = ax³ + bx² + cx + d - to a set of data points using the method of least squares. It extends quadratic regression by adding a cubic term, allowing the fitted curve to have up to two turning points and an inflection point where the curvature changes sign.

Cubic polynomials are remarkably versatile. They can model S-curves (slow start, rapid middle growth, then levelling off), data with a local peak followed by a trough, and non-symmetric bell-shaped relationships. In engineering, stress-strain curves for ductile materials follow a roughly cubic shape: linear elastic region, yield point, plastic hardening, then failure. In environmental science, pollutant concentration in a river over distance sometimes follows a cubic pattern. In economics, total cost functions are often modelled as cubic polynomials to capture economies of scale and eventually rising marginal costs.

The four coefficients a, b, c, d are determined by solving a 4×4 system of normal equations derived from the least-squares criterion. This calculator uses Gaussian elimination with partial pivoting - a numerically stable direct solver - to find the solution without requiring matrix inversion.

Compared to higher-degree polynomials, the cubic is often a practical sweet spot: complex enough to capture non-linear patterns with one or two turning points, but simple enough to avoid excessive oscillation and overfitting that plague degree-5 or degree-6 models.

📐 Formulas

ŷ = ax³ + bx² + cx + d

The normal equations (4×4 system) are derived by setting ∂SS/∂d = ∂SS/∂c = ∂SS/∂b = ∂SS/∂a = 0:

d·n + c·Σx + b·Σx² + a·Σx³ = Σy

d·Σx + c·Σx² + b·Σx³ + a·Σx⁴ = Σxy

d·Σx² + c·Σx³ + b·Σx⁴ + a·Σx⁵ = Σx²y

d·Σx³ + c·Σx⁴ + b·Σx⁵ + a·Σx⁶ = Σx³y

Solved by Gaussian elimination with partial pivoting for [d, c, b, a].

R²: R² = 1 − Σ(yᵢ − ŷᵢ)² / Σ(yᵢ − ȳ)²

Inflection point: x_inf = −b / (3a) where the curve changes concavity.

Turning points: solve dy/dx = 3ax² + 2bx + c = 0 using the quadratic formula. Real solutions exist when discriminant (2b)² − 4(3a)(c) ≥ 0.

📖 How to Use This Calculator

1
Enter the X values as a comma-separated list. Use at least 6–8 data points so the 4-parameter cubic model is reliably constrained.
2
Enter the corresponding Y values in the same order. Both lists must have identical lengths.
3
Click Calculate Cubic Regression. The 4×4 normal equations are solved and all four coefficients, R², and the full equation are shown.
4
Use the Prediction field to evaluate ŷ = ax³ + bx² + cx + d at any X - within or beyond the observed range.
5
Compare R² with a quadratic fit. If the improvement is small (< 0.01), the quadratic model is likely sufficient and less prone to overfitting.

📝 Example Calculations

Example 1 - Temperature Variation Over 24 Hours

Hour (X): 0, 4, 8, 12, 16, 20, 24. Temperature °C (Y): 14, 11, 15, 25, 28, 22, 15.

Fit yields a ≈ 0.0062, b ≈ −0.210, c ≈ 1.882, d ≈ 12.60. R² ≈ 0.982.

Equation: ŷ = 0.0062x³ − 0.210x² + 1.882x + 12.60.

Prediction at hour 14 (early afternoon): ŷ = 0.0062(2744) − 0.210(196) + 1.882(14) + 12.60 ≈ 27.1°C.

Result = ŷ = 0.0062x³ − 0.210x² + 1.882x + 12.60, R² ≈ 0.982
Try this example →

Example 2 - Stress-Strain Curve

Strain ε (×10⁻³): 0, 1, 2, 3, 4, 5, 6. Stress σ (MPa): 0, 200, 370, 480, 520, 490, 420.

Fit: a ≈ −4.286, b ≈ 40.357, c ≈ 148.71, d ≈ 1.43. R² ≈ 0.994.

Inflection at ε = −40.357/(3×−4.286) ≈ 3.14 × 10⁻³ - the approximate yield strain.

Peak stress predicted at ε ≈ 4.2 × 10⁻³: ŷ ≈ 524 MPa, close to the observed maximum.

Result = ŷ = −4.286x³ + 40.357x² + 148.71x + 1.43, R² ≈ 0.994
Try this example →

Example 3 - S-Curve Technology Adoption

Year (X, 0=2015): 0, 1, 2, 3, 4, 5, 6, 7. Adoption % (Y): 2, 5, 12, 28, 52, 72, 84, 90.

Fit: a ≈ −0.637, b ≈ 7.310, c ≈ −7.167, d ≈ 2.095. R² ≈ 0.993.

Inflection at x = −7.310/(3×−0.637) ≈ 3.83 years after 2015 (mid-2018) - the point of fastest adoption growth.

At year 8 (2023): ŷ = −0.637(512) + 7.310(64) − 7.167(8) + 2.095 ≈ 92% adoption predicted.

Result = ŷ = −0.637x³ + 7.310x² − 7.167x + 2.095, R² ≈ 0.993
Try this example →

Example 4 - Total Cost Function in Economics

Output Q (units): 1, 2, 3, 4, 5, 6, 7. Total cost TC (£000): 12, 16, 18, 22, 32, 50, 80.

Fit: a ≈ 1.286, b ≈ −9.143, c ≈ 24.71, d ≈ −4.43. R² ≈ 0.997.

Marginal cost dTC/dQ = 3(1.286)Q² − 2(9.143)Q + 24.71 = 3.857Q² − 18.286Q + 24.71.

Minimum marginal cost at Q = 18.286/(2×3.857) ≈ 2.37 units - the most efficient production scale.

Result = ŷ = 1.286x³ − 9.143x² + 24.71x − 4.43, R² ≈ 0.997
Try this example →

Example 5 - River Pollutant Concentration by Distance

Distance from source (km): 0, 5, 10, 15, 20, 25, 30. Concentration (mg/L): 0.5, 2.8, 6.1, 7.4, 5.9, 2.6, 0.8.

Fit: a ≈ 0.00040, b ≈ −0.01952, c ≈ 0.2892, d ≈ 0.501. R² ≈ 0.997.

Peak concentration predicted at x ≈ 14.2 km downstream - close to the observed maximum at 15 km.

At 35 km: ŷ ≈ −0.27 mg/L (slightly negative due to cubic extrapolation - shows the limits of polynomial extrapolation outside the data range).

Result = ŷ = 0.00040x³ − 0.01952x² + 0.2892x + 0.501, R² ≈ 0.997
Try this example →

❓ Frequently Asked Questions

What is cubic regression?+
Cubic regression fits a third-degree polynomial y = ax³ + bx² + cx + d to a set of data points using the method of least squares. With four parameters (a, b, c, d), a cubic curve can capture more complex shapes than linear or quadratic models - including S-curves, inflection points, and data that changes direction twice. The four coefficients are found simultaneously by solving a 4×4 system of normal equations using Gaussian elimination.
When should I use cubic regression?+
Cubic regression is appropriate when a scatter plot of your data shows a pattern that changes direction twice (two turning points), or when there is an inflection point - where the curve transitions from concave-up to concave-down (or vice versa). Common applications include temperature variation over a 24-hour period, engineering stress-strain curves with an initial linear region followed by yielding, biochemical reaction kinetics, and economic data with cyclical patterns.
How is cubic regression calculated mathematically?+
The normal equations are obtained by minimising SS_res = Σ(yᵢ − axᵢ³ − bxᵢ² − cxᵢ − d)². Setting ∂SS/∂a = ∂SS/∂b = ∂SS/∂c = ∂SS/∂d = 0 yields a 4×4 linear system involving sums Σ1, Σx, Σx², Σx³, Σx⁴, Σx⁵, Σx⁶ and Σy, Σxy, Σx²y, Σx³y. This system is solved using Gaussian elimination with partial pivoting for numerical stability.
What does R-squared mean in cubic regression?+
R² = 1 − SS_res/SS_tot measures the proportion of variance in Y explained by the cubic model. Higher R² indicates a better fit. Because a cubic has more parameters than linear or quadratic models, it will always achieve at least as high an R² - this is overfitting risk. If the cubic model R² is only marginally higher than the linear R², the cubic terms are likely capturing noise rather than signal.
What is an inflection point in a cubic curve?+
An inflection point is a point where the curve changes from concave-up (∂²y/∂x² > 0) to concave-down (∂²y/∂x² < 0), or vice versa. For y = ax³ + bx² + cx + d, the second derivative is 6ax + 2b = 0, giving the inflection point at x = −b/(3a). In stress-strain curves, the inflection point marks the transition from elastic to plastic deformation. In epidemic models it marks the peak rate of new infections (the point where growth begins to slow).
How many data points do I need for cubic regression?+
A cubic polynomial has 4 parameters (a, b, c, d), so you need at least 4 points. However, with exactly 4 points the cubic passes through all of them exactly (R² = 1, no genuine fit quality measure). Use at least 6–8 points for a reliable R² and to avoid overfitting. With many data points the cubic is estimated robustly and R² is a meaningful measure.
How does cubic regression compare to spline interpolation?+
Cubic regression fits a single global cubic polynomial to all data. Cubic splines fit multiple cubic pieces joined smoothly at knots. Regression is preferred for noisy data where you want a smooth global trend; splines are preferred for precise interpolation between closely-spaced clean data points. For prediction well beyond the observed range (extrapolation), cubic regression is generally safer as splines can oscillate wildly outside the knot range.
What are the turning points of the fitted cubic?+
The turning points (local maxima and minima) are where the first derivative equals zero: dy/dx = 3ax² + 2bx + c = 0. This is a quadratic in x, solved by the quadratic formula: x = [−2b ± √(4b² − 12ac)] / (6a). Real turning points exist when the discriminant 4b² − 12ac ≥ 0. This calculator does not display them automatically, but you can compute them from the reported a, b, c coefficients.