0
$\begingroup$

Say I have the following three points:

|  x  |  y  |
|-----|-----|
|6,13 | 73  |
|5,76 | 77,7|
|5,39 | 78,6|

This would result in a graph looking something like this:

enter image description here

If you'd try and draw a curved line closest to these points there would be a peak somewhere to the left. My question is, is there a way to find the parabolic function closest to these three points, or at least the optimal point of that parabola?

  • 0
    What about the interpolating parabola ? If the $x$-values are pairwise distinct, there is exactly one function of the form $f(x)=ax^2+bx+c$, such that the three points lie on $f$. Is that what you want ?2017-02-18
  • 0
    I want to find the function that would result in the line closest to these points. The points are measurements, I'm trying to predict the optimal value of x. Sorry I'm lacking the vocabulary to properly express myself in this, I'm a programmer and this is a hobby experiment for me.2017-02-18
  • 0
    Do you want a parabola passing through these points, or do you want a parabola that seems “closest” to the broken line you have drawn?2017-02-18
  • 0
    @Lubin Actually I thought it would only be possible to find the one that is closest. Both would be interesting to me.2017-02-18

1 Answers 1

1

Let $x_1 < x_2 < x_3$ be three real numbers, and let $y_1,$ $y_2,$ and $y_3$ be real numbers. Then there is exactly one quadratic function $f$ such that $y_1 = f(x_1),$ $y_2 = f(x_2),$ and $y_3 = f(x_3).$ The graph of $f$ is a parabola that passes exactly through the three points $(x_1,y_1),$ $(x_2,y_2),$ and $(x_3,y_3).$

One way to write the formula for the function $f$ is $$ f(x) = \frac{(x-x_2)(x-x_3)}{(x_1-x_2)(x_1-x_3)}y_1 + \frac{(x-x_1)(x-x_3)}{(x_2-x_1)(x_2-x_3)}y_2 + \frac{(x-x_2)(x-x_1)}{(x_3-x_2)(x_3-x_1)}y_3. $$ You can search for "Lagrange interpolating polynomial" for more information about this function.

It is reasonably straightforward to confirm that $f$ as written above is a quadratic function and that it satisfies the necessary conditions $y_1 = f(x_1),$ $y_2 = f(x_2),$ and $y_3 = f(x_3).$ The derivative of the function is $$ f'(x) = \frac{2x-x_2-x_3}{(x_1-x_2)(x_1-x_3)}y_1 + \frac{2x-x_1-x_3}{(x_2-x_1)(x_2-x_3)}y_2 + \frac{2x-x_2-x_1}{(x_3-x_2)(x_3-x_1)}y_3. $$ To find the extreme point of $f,$ substitute $0$ for $f'(x)$ in the equation above and solve for $x.$

In order to make the equations a little less intimidating, you can write \begin{align} k_1 & = \frac{y_1}{(x_1-x_2)(x_1-x_3)}, \\ k_2 & = \frac{y_2}{(x_2-x_1)(x_2-x_3)}, \\ k_3 & = \frac{y_3}{(x_3-x_2)(x_3-x_1)}, \end{align} so that you can calculate the three numbers $k_1,$ $k_2,$ and $k_3$ directly from known values, and then \begin{align} f(x) &= k_1(x-x_2)(x-x_3) + k_2(x-x_1)(x-x_3) + k_3(x-x_2)(x-x_1), \tag1\\ f'(x) &= 2(k_1+k_2+k_3)x - k_1(x_2+x_3) - k_2(x_1+x_3) - k_3(x_2+x_1). \tag2 \end{align}

We therefore have $f'(x) = 0$ when $$ x = \frac{k_1(x_2+x_3) + k_2(x_1+x_3) + k_3(x_2+x_1)}{2(k_1+k_2+k_3)}. \tag3 $$

Note that the original condition $x_1 < x_2 < x_3$ is more than we actually need to make these equations work. The actual necessary condition is that no two of the three $x_i$ values are the same; putting them in increasing order is merely an easy way to enforce that condition.


In your particular example, we plug in the known values \begin{align} x_1 & = 5.39, & y_1 &= 78.6, \\ x_2 & = 5.76, & y_2 &= 77.7, \\ x_3 & = 6.13, & y_3 &= 73. \end{align}

We then get $k_1 \approx 266.6179693207,$ $k_2 \approx -567.5675675676,$ and $k_3 \approx 287.0708546384.$ (I write $\approx$ rather than $=$ to reflect the fact that these values have been rounded off to ten decimal places rather than written as exact fractions.) Plugging these known values into Equation $1$ and collecting terms in equal powers of $x,$ we get $$ f(x) \approx -13.8787436085 x^2 + 152.315558802 x - 339.1742147553. \tag4 $$ Plugging values into Equation $3$ tells us that the maximum value of $f(x)$ occurs when $x = 5.4873684211,$ and then Equation $4$ implies that the maximum value is given (to within the error introduced by rounding off) by $$ f(5.4873684211) \approx 78.7315789474. $$

  • 0
    I think OP would have been helped by your plugging in the values he gives at the top, to get a specific quadratic function.2017-02-18
  • 0
    @Lubin Done. I also found the maximum of that function, which seems to be the ultimate goal of this exercise.2017-02-18
  • 0
    Thanks a lot! This is such a great help to me. So much high school stuff coming back:) I've just converted this into a small PHP script, which might be of little use to you but I'd still like to share it:) https://gist.github.com/jasperkennis/7f138cb837031518a5da4790a61693c42017-02-19