Deriving formula for curve given a set of points

4.3k Views Asked by At

I'm looking for a way to derive the equation of a curve that will fit a set of points.

I have a set of points like this:
{130,20},
{150,30},
{160,40},
{165,50},
{175,60},
{185,70},
{192,80},
{200,90},
{205,100},
{210,120},
{215,140}

How can I programmatically derive a formula for this curve? I'm writing software that will have different data for the X values but all data will follow the general shape of the curve.

For more background information, I'm estimating Training Stress Score (Y values) from heart rate (x values). More information on that here: https://www.trainingpeaks.com/blog/estimating-training-stress-score-tss/.

So given a heart rate of 170, it would return a value of 50. However, this should be able to be made more accurate with a curve since a heart rate of 174 should have a TSS value of closer to 60 than 50.

Since I'll be allowing a user to define their own heart rate values (depending on their own personal heart rate zones), the method of finding the curve will need to be derived from those values.

2

There are 2 best solutions below

2
On BEST ANSWER

A simple approach which preserves the monotonicity (strict increasing property) of the data is linear interpolation.

In the case you mentioned for a heart rate of $170$, this occurs at the midpoint between the points $(165,50)$ and $(175,60)$. Linear interpolation thus returns the midpoint value of $55$ for heart rate $170$, and for heart rate $174$ we get:

$$ 50 + (174 - 165)\frac{60-50}{175-165} = 59 $$

In general one locates the two data points $(x_0,y_0)$ and $(x_1,y_1)$ which bracket an input value $X$, i.e. $x_0 \lt x \lt x_1$ in ascending order, and we calculate:

$$ y = y_0 + (x - x_0) \frac{y_1 - y_0}{x_1 - x_0} $$

1
On

I don't know much about the technical details for this kind of thing, but here is the way I heuristically think of polynomial approximation:

When I say point, I mean "generically," as in assuming that the points are distinct, and no $k+2$ live on a $k$-dimensional affine space (point, line, plane, etc.)

$2$ points determine a line.

$3$ points determine a quadratic

$11$ points determine a degree $10$ polynomial.

hence, we can make the following computation:

assuming that the curve is $p(x)=a_0+\cdots a_{10} x^{10}$, we can solve for the variables by substituting points $(x,y)=(a,b)$ and solving what is now a linear system of equations.

{130,20}, {150,30}, {160,40}, {165,50}, {175,60}, {185,70}, {192,80}, {200,90}, {205,100}, {210,120}, {215,140}

\begin{align*}20 &=a_0+\cdots+a_{10}\cdot130^{10}\\ 30 &=a_0+\cdots+a_{10}\cdot150^{10}\\ 40 &=a_0+\cdots+a_{10}\cdot160^{10}\\ 50 &=a_0+\cdots+a_{10}\cdot165^{10}\\ 60 &=a_0+\cdots+a_{10}\cdot175^{10}\\ 70 &=a_0+\cdots+a_{10}\cdot185^{10}\\ 80 &=a_0+\cdots+a_{10}\cdot192^{10}\\ 90 &=a_0+\cdots+a_{10}\cdot200^{10}\\ 100 &=a_0+\cdots+a_{10}\cdot205^{10}\\ 120 &=a_0+\cdots+a_{10}\cdot210^{10}\\ 140 &=a_0+\cdots+a_{10}\cdot215^{10}\\ \end{align*}

But solving this correctly will amount to row reducing matrices, since this is a $10 \times 10$ linear system of equations. I don't have time to punch this into an online calculator, but I think this should give you a "reasonable" approximation.