I have following values:

x = [0, 12.5, 25, 50, 75, 87.5, 100]
y = [0.0, 0.2, 0.31, 0.5, 0.66, 0.76, 1.0]

These values represent display values from a device that provides something like a charging status. My problem is that the display (which is a mechanical hand) is not providing the correct values. When everything is correct, it should be a straight linear curve (x against x). But what I see is y against x. What I would like to do: How can I create a function that takes into account these values and provides the correct valuse I would like to have? My idea is: Fit the measured values and create a function which shifts the data points such that they ly on a straight line, finally.

Does that make sense?

Goal: How do I get the correct values? It looks like I have to shift the values below 50 % downwards and the values above 50 % upwards.


  • $\begingroup$ So what is your question again? $\endgroup$ – Art Nov 19 '19 at 9:22
  • $\begingroup$ Finally, how do I get the correct values? $\endgroup$ – Ben Nov 19 '19 at 9:27
  • $\begingroup$ Is it possible to obtain more data (for example, a finer grid for x values)? Do you always get x = 12.5 when y = 0.2? $\endgroup$ – Art Nov 19 '19 at 9:32
  • 1
    $\begingroup$ Yes, always the same. Isn't just an inverse function doing the job? So I fit the data and then I use the inverse of it. $\endgroup$ – Ben Nov 19 '19 at 9:33
  • 1
    $\begingroup$ But I do measure it. The uncertainties are quite small. $\endgroup$ – Ben Nov 19 '19 at 9:37

If you can measure $y$ for all values of $x$, then you're done...

From the comments above, when there's no uncertainty, there's no need to "fit" any curve. What you have is a function $y = f(x)$ where $y$ is what you're measuring. To get $x$ from this, you simply take the inverse function $x = f^{-1}(y)$, where $f^{-1}$ could be as simple as a piecewise function, for example, $f^{-1}(0.2) = 12.5$

If you cannot measure $y$ for all values of $x$, you could interpolate using spline interpolation (Python reference).

| cite | improve this answer | |

Looking at the scatterplot, the data seemed to me as if it were similar to a sine wave plus a straight line. I fitted the data to several trigonometric functions of this type, and found that a hyperbolic cosine (cosh) with linear growth appears to fit the data well. The below equation and three fitted parameter values yield R-squared = 0.9978 and RMSE): 0.0149

amplitude = 8.6803997548024585E-03
center = 7.3734550922795378E+01
width = 1.5909052889748179E+02

pi = 3.14159265358979323846

y = amplitude * cosh(pi * (x - center) / width) * x


| cite | improve this answer | |
  • $\begingroup$ I forgot to mention that the fitted parameter "width" should be the wavelength. $\endgroup$ – James Phillips Nov 19 '19 at 11:54
  • $\begingroup$ thanks, but how does this provide the "correct" values? $\endgroup$ – Ben Nov 19 '19 at 12:28
  • $\begingroup$ The difference between your fitted straight line and this hyperbolic cosine is the correction factor you are looking for. $\endgroup$ – James Phillips Nov 19 '19 at 13:43
  • $\begingroup$ The line is not fitted, it represents how the correct function should look like. $\endgroup$ – Ben Nov 20 '19 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.