I am trying to create a formula to calculate x for given y. I have 74 samples. I tried to do it with linear interpolation. However, the accuracy isn't good.
These are my samples:
x:
1 , 1.5, 2, 2.5, 2.6, 2.7, 2.8, 2.9, 3, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8, 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9, 9.1, 9.2, 9.3, 9.4, 9.5
y:
211, 208, 203, 199, 197, 195, 193, 190.6, 188.5, 186.5, 183.8, 181.8, 178.9, 176, 173.1, 170.2, 167.3, 164.1, 160.8, 157.7, 154.6, 152.4, 149.3, 146, 142.8, 139, 135.9, 132.7, 129.5, 126.1, 122.8, 120, 116.4, 112.8, 109.9, 106.4, 103.1, 99.8, 94.5, 91.4, 88.2, 85.1, 81.6, 78.5, 75.2, 71.8, 68.7, 65.3, 61.9, 58.8, 55.8, 52.7, 49.3, 46.8, 44.1, 41.3, 38.7, 36.1, 33.5, 31.2, 28.8, 26.7, 24.2, 22.2, 19.9, 18, 15.9, 14.2, 12.6, 11.1, 9.5, 8.3, 6.9, 5.8
I take a look at the wikipedia page for linear interpolation formula. This is the formula that I used to calculate.
I put $x_0$=$1$, $y_0$ = $211$ and $x_1$ = $9.5$ , $y_1$ = $5.8$. The first and last members of my samples.
The formula is:
$y = \frac{(-205,2x)+(1998,7)}{8,5}$
For given $x$ = $2$ , $y$ = $186,85$. However the real value is $203$. Also for given $x$ = $3$, $y$ = $162,71$.But the real value is $188,5$.
I need more accuracy. The tolerance could be plus-minus 5.
How can I do it ?
One solution is to use linear approximations in smaller intervals... If you want to approximate $y$ for a given $x$, start by locating the data interval where $x$ belongs, say $x \in (x_i, x_{k})$. Then, use the approximation $$ y \approx y_i + \dfrac{y_{k}-y_i}{x_{k}-x_i} (x- x_i). $$
Alternatively, you can fit the data with more general functions. Look up "least squares approximation". For instance, the approximation $$ y \approx \frac{247.699}{\left(0.00177047 x^{2.75192}+1\right)^{2.95026}}-34.9627 $$
yields a maximum error less than 1.7. If you want to get $x$ in terms of $y$, you just need to invert this expression and get $$ x \approx 9.99993 \left(\frac{6.4778}{(y+34.9627)^{0.338953}}-1\right)^{0.36338} $$