Using a parabola for interpolation

1.4k Views Asked by At

I am trying to use a parabola to interpolate between 3 values and I have been struggling with finding an equation that works for me.

The constraints are:

  • passes through the points $(0, s), (x,m), (1, n)$ [$x$ is not given, but must be between $0$ and $1$]
  • $0 < s < 1$
  • $0 < m < 1$
  • $0 < n < 1$
  • $0 < x < 1$
  • $x$ is the x-coordinate of the maximum/minimum of the parabola
  • $m > s$ and $m > n$ or $m < s$ and $m < n$ ($m$ will never be between $s$ and $n$)

In the standard $y = ax^2 + bx + c$ form, I have been able to determine:

  • $c = s$
  • $a + b + c = n$
  • $c - \frac{b^2}{4a} = m$
  • $n - s = a + b$
  • $a = \frac{b^2}{ 4*(s - m)}$

I always seem to come out with 2 possible values for $b$ (due to a $\pm \sqrt{...}$), and only one of those will give me a maximum/minimum between $0$ and $1$. I am almost certain that there is a way to determine $a$, $b$, and $c$ from the given $s$, $n$, and $m$.

I have been slamming my head against a wall for the past week and a half trying to figure this out.

EDIT: I have gotten the equation to a point where all I need to do is calculate $a$ from the inputs $s$,$n$, and $m$.

2

There are 2 best solutions below

5
On

If you want a vertical parabola $\;f(x)=y=ax^2+bx+c\;$ then it may be easier. Since $\;(0,s)\;$ is on it, we get $\;s=f(0)=c\;$ ,and also:

$$n=f(1)=a+b+c=a+b+s\implies a+b=n-s$$

and since $\;(x_0,m)\;$ (changed the notation for convenience) is the parabola's vertex, we get that

$$\begin{cases}x_0=-\frac b{2a}\\{}\\m=-\frac{\Delta}{4a}=-\frac{b^2-4ac}{4a}=-\frac{b^2}{4a}+s\end{cases}$$

Solving the above

$$b=-2ax_0\implies m=-\frac{4a^2x_0^2}{4a}+s=-ax_0^2+s\implies a=\frac{s-m}{x_0^2}$$

and you have all your parabola's coefficient in function of the given points.

2
On

Some computation gives you: $$b=2(m-s)\pm 2\sqrt{(m-s)(m-n)}\\ a=(n-s)-b=-(m-s)-(m-n)\mp 2\sqrt{(m-s)(m-n)}$$

We see that there are two solutions. However it turns out that one of them does not give us an $x$ which is in the interval $(0,1)$.

Remember that $x=-\frac{b}{2a}$. This is $$\frac{(m-s)\pm\sqrt{(m-s)(m-n)}}{(m-s)+(m-n)\pm 2 \sqrt{(m-s)(m-n)}}\\ =\frac{\sqrt{m-s}(\sqrt{m-s}\pm \sqrt{m-n})}{(\sqrt{m-s}\pm \sqrt{m-n})^2}\\ =\frac{\sqrt{m-s}}{(\sqrt{m-s}\pm \sqrt{m-n})}$$

where I assumed $m>s, m>n$. For the other case, you just need to switch the two terms of all the subtractions. The result is the following: $$\frac{-(s-m)\pm\sqrt{(s-m)(n-m)}}{-(s-m)-(n-m)\pm 2 \sqrt{(s-m)(n-m)}}\\ =\frac{\sqrt{s-m}(\sqrt{s-m}\mp \sqrt{n-m})}{(\sqrt{s-m}\mp \sqrt{n-m})^2}\\ =\frac{\sqrt{s-m}}{(\sqrt{s-m}\mp \sqrt{n-m})}$$

You can see easily with the minus sign the $x$ values in both cases are greater than $1$. So only the plus sign works.