Associated Topics || Dr. Math Home || Search Dr. Math

```
Date: 02/21/2002 at 01:57:27
From: Avin Sinanan

Hello,

I would please like to know how, given a scatter plot of X and Y
cordinates, one finds the best-fitting quadratic curve.

Let's say that Y = A*X^2 + B*X + C is the best fit curve.

How does one find A, B, and C for the best quadratic fit curve?

I looked on many Web sites and they mention that it can be done, but
they never show how to do it.

Thanks,
Yours respectfully,
Avin Sinanan
```

```
Date: 02/21/2002 at 07:52:20
From: Doctor Rob
Subject: Re: Best fit Quadratic Curve

Thanks for writing to Ask Dr. Math, Avin.

Suppose the points you are given are {(X[i],Y[i]): 1 <= i <= N}.
Then you want the values of A, B, and C that minimize the sum of
squares of the deviations of Y[i] from A*X[i]^2 + B*X[i] + C.  They
will give you the best-fitting quadratic equation.

Let the sum of the squares of the deviations be

N
F(A,B,C) = SUM (A*X[i]^2+B*X[i]+C-Y[i])^2.
i=1

To minimize this, take partial derivatives of F with respect to the
three variables A, B, and C, set them all equal to zero, and solve
simultaneously:

dF/dA = SUM 2*(A*X[i]^2+B*X[i]+C-Y[i])*X[i]^2 = 0,
dF/dB = SUM 2*(A*X[i]^2+B*X[i]+C-Y[i])*X[i] = 0,
dF/dC = SUM 2*(A*X[i]^2+B*X[i]+C-Y[i]) = 0.

(Here all sums range over i = 1, 2, ..., N.)  Dividing by 2 and
rearranging, you can see that these are three simultaneous  linear
equations in the three unknowns A, B, and C:

(SUM X[i]^4)*A + (SUM X[i]^3)*B + (SUM X[i]^2)*C = SUM X[i]^2*Y[i],
(SUM X[i]^3)*A + (SUM X[i]^2)*B +   (SUM X[i])*C = SUM X[i]*Y[i],
(SUM X[i]^2)*A +   (SUM X[i])*B +      (SUM 1)*C = SUM Y[i].

I leave it to you to solve these three equations.

Feel free to write again if I can help further.

- Doctor Rob, The Math Forum
http://mathforum.org/dr.math/
```
Associated Topics:
High School Calculus

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search