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.
$\endgroup$ 34 Answers
$\begingroup$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 ?
$\endgroup$ 4 $\begingroup$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.
$\endgroup$ 7 $\begingroup$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.
$\endgroup$ $\begingroup$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.
$\endgroup$