Menu

Quadratic Regression Calculator

The parabola of best fit through your points, with exact coefficients and R².

By Nethanel Bar, Co-founder & CEO

Last updated

Want to solve these without the calculator?

The Coddy math course teaches the method itself - you work each step on an interactive board and get told exactly where a move went wrong.

Quadratic regression fits the parabola that misses the points by the least

Some data rises and then falls, or falls and then rises: the height of a thrown ball, the profit at different prices, the fuel a car burns at different speeds. A straight line through data like that is the wrong shape however well it is placed. Quadratic regression fits a parabola instead, y = ax² + bx + c, and chooses a, b and c so that the squared vertical misses from the points add up to as little as possible. It is the same least squares idea as linear regression, with one more coefficient to choose.

Minimising the squared misses leads to three equations in a, b and c, called the normal equations, built from the sums of x, x², x³, x⁴, y, xy and x²y. A graphing calculator solves them in floating point. This page solves them with exact fractions, so a coefficient of -8/7 is printed as -8/7 rather than -1.142857, and R² is an exact fraction too.

Every point's predicted value and residual is listed under the answer. A good quadratic fit leaves residuals that look like noise, scattered above and below zero with no pattern. If they still curve, or grow steadily across the table, a parabola is not the right shape either, and a different model is worth trying.

What to notice about the parabola

  • The sign of a gives the shape: negative a opens downwards with a highest point, positive a opens upwards with a lowest point.
  • Three points with different x values always fit exactly. The points (1, 4), (2, 9) and (3, 20) lie on y = 3x² - 4x + 5 with every residual 0, which says nothing about the data.
  • R² for a parabola is 1 minus the sum of squared residuals divided by the total variation in y. It can never be lower than the r² of a straight line on the same data, because a line is a parabola with a = 0.
  • The vertex of the fitted curve is at x = -b/(2a). For the data 2, 6, 11, 13, 12, 8 at x = 1 to 6 that is x = 33/8, where the curve peaks at about 12.45.
  • The fitted curve is only trustworthy between the smallest and largest x. Past the ends a parabola turns and heads off to plus or minus infinity, whatever the data does.

How to do quadratic regression by hand

  1. Build the sums

    For every point compute x, x², x³, x⁴, y, xy and x²y, then add each column and count the points. For x = 0, 1, 2, 3 and y = 1, 2, 5, 11: n = 4, Σx = 6, Σx² = 14, Σx³ = 36, Σx⁴ = 98, Σy = 19, Σxy = 45 and Σx²y = 121.

  2. Write the normal equations

    aΣx⁴ + bΣx³ + cΣx² = Σx²y, aΣx³ + bΣx² + cΣx = Σxy, and aΣx² + bΣx + cn = Σy. With the sums above: 98a + 36b + 14c = 121, 36a + 14b + 6c = 45, and 14a + 6b + 4c = 19.

  3. Solve the three equations

    Eliminate one letter at a time, keeping fractions exact. This system gives a = 1.25, b = -0.45 and c = 1.05, so y = 1.25x² - 0.45x + 1.05.

  4. Check with the residuals

    Put each x into the curve and subtract the prediction from the actual y. Here the residuals are -0.05, 0.15, -0.15 and 0.05, their squares add to 0.05, and R² = 1214/1215, about 0.9992.

Parabolas of best fit for small data sets

Each row is one data set typed into the calculator above, with the exact coefficients and R² it reports.

x valuesy valuesParabola of best fitR²
0, 1, 2, 31, 2, 5, 11y = 1.25x² - 0.45x + 1.051214/1215 ≈ 0.9992
-2, -1, 0, 1, 2, 39, 4, 1, 0, 1, 4y = x² - 2x + 11
1, 2, 3, 4, 5, 62, 6, 11, 13, 12, 8y = -(8/7)x² + (66/7)x - 7887/917 ≈ 0.9673
0, 1, 2, 3, 42, 17, 22, 17, 2y = -5x² + 20x + 21
1, 2, 34, 9, 20y = 3x² - 4x + 51
0, 1, 2, 3, 4, 50, 1, 4, 9, 16, 25y = x²1

Worked examples

A close fit with decimal coefficients

plain
x: 0, 1, 2, 3; y: 1, 2, 5, 11

The normal equations give a = 1.25, b = -0.45 and c = 1.05, so y = 1.25x² - 0.45x + 1.05. The predictions are 1.05, 1.85, 5.15 and 10.95, the residuals -0.05, 0.15, -0.15 and 0.05, and R² = 1214/1215, about 0.9992.

Data that rises and falls

plain
x: 1, 2, 3, 4, 5, 6; y: 2, 6, 11, 13, 12, 8

The parabola of best fit is y = -(8/7)x² + (66/7)x - 7 with R² = 887/917, about 0.9673. Because a is negative the curve has a peak, at x = 33/8 = 4.125 and y = 697/56, about 12.45. A straight line through the same points reaches only r² = 375/917, about 0.4089, because it cannot turn.

A thrown ball

plain
x: 0, 1, 2, 3, 4; y: 2, 17, 22, 17, 2

Heights in metres at one-second intervals. The fit is exact: y = -5x² + 20x + 2 with every residual 0 and R² = 1. The -5 is half of the gravitational acceleration rounded to 10 m/s², the 20 is the launch speed and the 2 is the launch height. The peak is at x = 2, y = 22.

Points that were already a parabola

plain
x: -2, -1, 0, 1, 2, 3; y: 9, 4, 1, 0, 1, 4

These are the values of (x - 1)², and the calculator returns y = x² - 2x + 1, the same parabola multiplied out, with R² = 1 and every residual 0. It is a quick way to check that a set of values really comes from one quadratic.

Common mistakes

  • Using only three points and reading R² = 1 as a great fit. Any three points with different x values lie on some parabola.
  • Rounding the sums or the coefficients part way through. The normal equations are sensitive, and a small rounding in Σx⁴ can move c noticeably. Keep fractions until the end.
  • Writing the equations with the sums in the wrong places. The top-left entry is Σx⁴ and the bottom-right is n; each row moves the powers down by one.
  • Predicting far outside the data. The parabola turns and runs off to infinity past its ends, whether the real quantity does or not.
  • Choosing a parabola because R² went up. R² for a parabola is always at least the r² of a line on the same data; the question is whether the residuals lose their pattern.

Quadratic regression FAQ

What is quadratic regression?
Fitting a parabola y = ax² + bx + c to data by least squares: choosing a, b and c so that the sum of the squared vertical distances from the points to the curve is as small as possible. It is the method to use when a scatter plot rises and falls, or falls and rises, instead of following a straight line.
How do you find the quadratic regression equation?
Add up x, x², x³, x⁴, y, xy and x²y over the points and solve the three normal equations aΣx⁴ + bΣx³ + cΣx² = Σx²y, aΣx³ + bΣx² + cΣx = Σxy and aΣx² + bΣx + cn = Σy. For x = 0, 1, 2, 3 and y = 1, 2, 5, 11 the solution is a = 1.25, b = -0.45, c = 1.05.
How many points do I need for quadratic regression?
At least three, with at least three different x values. With exactly three the parabola passes through all of them and R² is 1 automatically, so four or more points are needed before the fit tells you anything about the data.
What does R² mean for a quadratic fit?
R² = 1 minus (sum of squared residuals) divided by (total variation of y around its mean). It is the share of the variation in y that the parabola accounts for. For y = 2, 6, 11, 13, 12, 8 at x = 1 to 6, R² = 887/917, about 0.9673.
Is quadratic regression the same as polynomial regression?
It is polynomial regression of degree 2. A degree 3 fit adds an x³ term and a fourth normal equation, and so on. Higher degrees always fit the points more closely, and past a point they fit the noise rather than the trend, so degree 2 is usually as far as a small data set should go.
How do I find the vertex of the fitted parabola?
The same way as for any parabola: x = -b/(2a), then put that x into the equation for y. For y = -(8/7)x² + (66/7)x - 7 that gives x = 33/8 and y = 697/56, about 12.45, which is where the fitted trend peaks.
Why are the coefficients fractions?
Because solving the normal equations on data you can type always gives rational numbers, and the fraction is the exact answer. -8/7 is the leading coefficient; -1.142857 is a rounding of it. The Copy button gives the curve in decimals for a spreadsheet.

More math tools

Coddy programming languages illustration

Learn math with Coddy

GET STARTED