# Get polynomial function from 3 points

I need to understand how to define a polynomial function from 3 given points. Everything I found on the web so far is either too complicated or the reversed way around. (how to get points with a given function) It's over 12 years since I last used this at school, so please try to explain how to solve this.

I know that the funcion is like ax²+bx+c, that its centered on the x=0, and that its lowest point is at x=0/y=5000.

and i know 3 given points: x=0 y=5000 x=1 y=5026.5 x=3 y=5208.9

Knowing this data, how can I get the coefficients that generate the curve? Please try to keep it simple.

• Use the Lagrange Interpolation Formula. Feb 18, 2014 at 9:36
• en.wikipedia.org/wiki/Lagrange_polynomial gives a formula
– oks
Feb 18, 2014 at 9:36
• This old question popped up due to a recent answer, and I wonder why none of the comments and answers mention that the problem as stated has no solutions. Sure, one can find a quadratic going through all 3 given points, and as mentioned in the answers, there are various ways to find the coefficients, but then the resulting quadratic polynomial isn't centered on the $x=0$ axis as requested. Aug 16, 2021 at 8:17

Let us suppose that you have this general problem when you need the quadratic function which goes through three points $$[x_i,y_i]$$ and let, as written by dinosaur, $$y=f(x)=ax^2+bx+c$$ So, the three equations are $$y_1 = a {x_1}^2+b {x_1}+c$$ $$y_2 = a {x_2}^2+b {x_2}+c$$ $$y_3 = a {x_3}^2+b {x_3}+c$$ Subtracting the first to the second and the second from the third already eliminates $$c$$ and your are left with two linear equations for two unknowns. You could even eliminate from the first difference $$b$$ and plug it in the second difference and solve a linear equation in $$a$$. When $$a$$ is obtained, go backwards for getting $$b$$ and then $$c$$.

If you do the above, you will end with $$a=\frac{{x_1} ({y_3}-{y_2})+{x_2} ({y_1}-{y_3})+{x_3} ({y_2}-{y_1})}{({x_1}-{x_2}) ({x_1}-{x_3}) ({x_2}-{x_3})}$$ $$b=\frac{y_2-y_1}{x_2-x_1}-a (x_1+x_2)$$ $$c = y_1-a {x_1}^2-b {x_1}$$ Simple, isn't ?

• This is brilliant and helpful. Along the same lines, do you have the formulas for calculating the coefficients for a 3rd order polynomial? Jun 30, 2019 at 10:33
• @IamIC. For sure, it is doable but the formulae will become messy. Why don't you use Lagrange polynomials ? Jun 30, 2019 at 10:39
• As I understand it, Lagrange requires an iteration through the set in order to determine a point. (I have it in Excel). My application requires many single calculations (i.e. find y for a particular x), which makes the quadratic formula desirable due to its efficiency. Jun 30, 2019 at 10:46
• Lagrange interpolation delivers an explicit formula that gives you the $y$ corresponding to any given $x$. Aug 4, 2021 at 23:33

well, you know even more properties of the polynomial than you actually need.

You already have all the tools you need. Given the general form of your polynomial $y=f(x)=ax^2+bx+c$ you can just insert the given points one by one, which leads to a system of 3 equations and 3 variables (namely $a,b,c$).

\begin{align*} 5000 & = a\cdot 0^2 + b\cdot 0 + c = c \\ 5026 & = a\cdot 1^2 + b\cdot 1 + c \\ 5208.9 & = a\cdot 3^2 + b\cdot 3 + c \end{align*}

By solving this system of equations you can obtain the parameters $a,b,c$ of your quadratic function.

• sounds pretty clear, but i think i am still missing one last connection: from the first equation i do get C... but what do i get from the second and third if A and B are still unknown? thanks! Feb 18, 2014 at 9:41
• You get $c$ directly because you know the value in $x=0$. This might not be the case in other examples. You have to see these three equations as a system, not as independent equations. By e.g. Gaussian elimination or simply by using a computer algebra system like wolfram alpha you can solve it, obtaining the values of $a,b$ and $c$. Feb 18, 2014 at 9:48
• Thank you. My problem is that i have to implement this in a software myself, so i have to actually program the procedure to solve this. Feb 18, 2014 at 9:50
• Programing the analytical solutions of a small system of linear equations is very simple. Just use elimination, if you want. Feb 18, 2014 at 9:53
• Solving linear systems of equations is one of the key exercises in numerical mathmatics, so you can find tons of algorithms to solve these kinds of systems. The most basic is, as I pointed out, Gaussian elimination or LU decomposition, but you could also try iterative methods like Richardson's method. Feb 18, 2014 at 9:54

Lagrange interpolation delivers an explicit formula that gives you the $$y$$ corresponding to any given $$x$$. So, I think it’s exactly what you need. Some of the other answers are essentially just re-inventing the Lagrange formula. This has some value because yours is a special case that makes thing easier (one of your $$x$$ values is zero, so this causes some collapse/simplification in the formulas).

If you’re doing this in Excel, why not just use Excel’s curve fitting function —- it’s called “fit trendline”. It gives you the formula of the curve, which you can copy into a cell. Choose the “polynomial” option with order = 3 or 4.

Since you need a curve from 3 points, not specifically through 3 points, you might consider a Bézier curve.

If you know three points you can work out the vector equations of the line segments joining them,

$$r_1=p_1+td_1$$ $$r_2=p_2+td_2$$

where $$p_i=(u_i,v_i)$$ is the starting point of each line and $$d_i=(\alpha_i,\beta_i)$$ is the direction of the line whose length $$|d_i|$$ is that of the line segment itself. The $$r_i=(x_i,y_i)$$ is just the point on your lines as you move over $$t\in[0,1]$$.

Now consider a new line joining these two lines at any given time $$t\in[0,1]$$,

$$r_3=r_1+t(r_2-r_1).$$

Expanding and collecting the $$t$$'s gives

$$r_3=p_1+t(d_1+p_2-p_1)+t^2(d_2-d_1).$$

You can probably tweak the Bézier model to obtain different types of curve to suite you needs.