Quadratic equation formula for a,b,c from 3 points
I can solve for a, b, c given three points for a parabola for example (1,1)(2,4)(3,9) but i need to create a program which returns a,b,c in the form:
$$y = ax^2 + bx + c$$
What is a formula that will find out a, b, c? Someone on another forum mentioned Lagrange but being a high school student i don't know much about Uni level physics. Also i can work with matrices if anyone has a matrix formula - but please explain your formulas as to why it works!
Any help appreciated!
Thanks, Itechmatrix
$\endgroup$ 33 Answers
$\begingroup$When you plug in the three points, you have three equations in three unknowns, where the unknowns are A,B,and C. Use matrix arithmetic to solve via simple program.
By Matrix, I mean using Cramer's rule.
Assuming ($x_1, y_1$), ($x_2, y_2$) and ($x_3, y_3$) are three points that satisfy the equation:
$y= ax^2 + bx +c$
we get the three equations:
$y_1= ax_1^2 + bx_1 +c$
$y_2= ax_2^2 + bx_2 +c$
$y_3= ax_3^2 + bx_3 +c$
now $a, b, c$ are the unknowns and we have three equations in three variables. Now you could use Cramer's rule as suggested in the other answer.
In Matrix from:
$ Y = \left[ {\begin{array}{c} y_1 \\ y_2 \\ y_3 \end{array} } \right] $
$ X= \left[ {\begin{array}{ccc} x_1^2 & x_1 & 1 \\ x_2^2 & x_2 & 1 \\ x_3^2 & x_3 & 1 \\ \end{array} } \right] $
and
$ A = \left[ {\begin{array}{c} a \\ b \\ c \end{array} } \right] $
which gives
$Y = X A$
I might be missing a transpose. Here you know $Y$ and you know $X$. Inverting we get
$X^{-1} Y = X^{-1} X A = I A$.
Thus$A = X^{-1} Y $
$\endgroup$ $\begingroup$\begin{equation} y = ax^2 + bx + c \implies a = -\frac{b x + c - y}{x^2} \implies b = -\frac{a x^2 + c - y}{x} \end{equation}Given coordinates $ \qquad(1,1)(2,4)(3,9)$
\begin{equation} (1,1)\implies a = -\frac{1b + c - 1}{1}\implies b = -\frac{1a + c - 1}{1}\\ (2,4)\implies a = -\frac{2b + c - 4}{4}\implies b = -\frac{4a + c - 4}{2}\\ (3,9)\implies a = -\frac{3b + c - 9}{9}\implies b = -\frac{9a + c - 9}{3} \end{equation}
We do not have a complete solution but $a$ and $b$ appear to be complimentary and $c$ has always been a guess in many math operations. If we eliminate $c$, we can always add it back into the original equation form.
\begin{equation} (1,1)\implies a = \frac{1 - b}{1}\implies b = 1(1 - a)\\ (2,4)\implies a = \frac{2 - b}{2}\implies b = 2(1 - a)\\ (3,9)\implies a = \frac{3 - b}{3}\implies b = 3(1 - a) \end{equation}
\begin{equation} \implies a=\frac{x-b}{x}\qquad b=x(1-a)\\ \implies(a,b)\in\{(x,0).(x,-x)\}\quad\text{for}\quad y=x(ax+b) \end{equation}
$\endgroup$