Quadratic Regression Calculator
Fit a parabolic curve to your data using least squares and get the quadratic equation, R², and predictions instantly.
📖 What is Quadratic Regression?
Quadratic regression is a form of polynomial regression that fits a second-degree parabola - y = ax² + bx + c - to a set of observed data points using the method of least squares. While linear regression assumes a straight-line relationship between X and Y, quadratic regression accommodates situations where the relationship is curved, rising to a peak and then falling (or falling then rising).
The three coefficients a, b, and c are determined simultaneously by minimising the total sum of squared residuals: SS_res = Σ(yᵢ − axᵢ² − bxᵢ − c)². Setting the partial derivatives with respect to each coefficient to zero produces a 3×3 system of normal equations, solved here using Gaussian elimination with partial pivoting for numerical stability.
Quadratic regression appears throughout science and engineering. In physics, a thrown ball follows a parabolic trajectory - height versus time is exactly quadratic. In pharmacology, dose-response curves often rise steeply then plateau or decline, fitting a quadratic. In economics, a firm's profit function is classically quadratic in price or output, reflecting diminishing marginal returns. In sports analytics, a player's performance metric may peak at a certain age and decline on either side.
This calculator handles the full 3×3 least-squares solution, reports R², and includes a prediction field so you can evaluate the fitted parabola at any X value.
📐 Formulas
The coefficients a, b, c satisfy the normal equations (derived by setting ∂SS/∂a = ∂SS/∂b = ∂SS/∂c = 0):
Normal equations (3×3 system):
c·n + b·Σx + a·Σx² = Σy
c·Σx + b·Σx² + a·Σx³ = Σxy
c·Σx² + b·Σx³ + a·Σx⁴ = Σx²y
Solved simultaneously for a, b, c using Gaussian elimination with partial pivoting.
R² (goodness of fit): R² = 1 − SS_res / SS_tot
where SS_res = Σ(yᵢ − ŷᵢ)² and SS_tot = Σ(yᵢ − ȳ)²
Vertex (turning point): x* = −b / (2a), y* = ax*² + bx* + c
Prediction: ŷ = ax² + bx + c evaluated at any chosen X.
📖 How to Use This Calculator
📝 Example Calculations
Example 1 - Projectile Height vs Time
A ball is thrown upward. Time (s): 0, 1, 2, 3, 4. Height (m): 0, 15, 20, 15, 0.
Fitting y = at² + bt + c: the normal equations yield a ≈ −5.00, b ≈ 20.00, c ≈ 0.00.
Equation: ŷ = −5.00t² + 20.00t. R² = 1.000 - perfect fit (as expected from physics).
Vertex at t = −20/(2×−5) = 2.00 s, maximum height = 20 m. Matches the observed peak.
Example 2 - Dose-Response Curve
Drug dose (mg): 5, 10, 20, 40, 80, 160. Response (%): 10, 35, 70, 90, 75, 40.
Fitting gives a ≈ −0.0045, b ≈ 1.025, c ≈ 0.30.
Equation: ŷ = −0.0045x² + 1.025x + 0.30. R² ≈ 0.973.
Optimal dose (vertex): x* = −1.025 / (2 × −0.0045) ≈ 114 mg - the dose yielding peak response.
Example 3 - Price vs Demand Profit
Price (£): 10, 20, 30, 40, 50. Profit (£000): 5, 18, 25, 24, 15.
Fit: a ≈ −0.040, b ≈ 2.48, c ≈ −18.0. R² ≈ 0.987.
Equation: ŷ = −0.040x² + 2.48x − 18.0. Vertex at x* = −2.48/(2×−0.040) = £31.00 - the profit-maximising price.
Maximum expected profit: ŷ(31) = −0.040(961) + 2.48(31) − 18 = −38.44 + 76.88 − 18 = £20,440.
Example 4 - Athlete Performance by Age
Age (years): 18, 22, 26, 30, 34, 38. Sprint time (s): 10.8, 10.2, 10.0, 10.3, 10.9, 11.6.
Fit: a ≈ 0.030, b ≈ −1.62, c ≈ 31.8. R² ≈ 0.983.
Vertex (peak performance - minimum time) at age x* = 1.62/(2×0.030) = 27.0 years.
At age 27: ŷ = 0.030(729) − 1.62(27) + 31.8 = 21.87 − 43.74 + 31.8 = 9.93 s.
Example 5 - Revenue vs Units Sold
Units (000s): 1, 2, 3, 4, 5, 6, 7. Revenue (£000s): 8, 20, 36, 46, 50, 48, 38.
Fit: a ≈ −2.21, b ≈ 19.21, c ≈ −9.07. R² ≈ 0.987.
Vertex at x* ≈ 4.35 (000 units) - revenue-maximising output. Max predicted revenue: ŷ(4.35) ≈ £52,800.
Prediction at 8 units: ŷ = −2.21(64) + 19.21(8) − 9.07 = −141.44 + 153.68 − 9.07 = £3,170 - showing the business would lose money at excessive volumes.