Finding a point on a curve given a series of points

79 views Asked by At

I have a series of values (x & y) which I can put into Excel and create a curve, as shown below.

enter image description here

Using this graph, I can see what the value of y might be for a given value of x (and vise-versa)

e.g.

  • for an x value of 815 - y is approx. 750
  • for a y value of 400 - x is approx 812.5

Is there a simple algorithm that will take a series of points and return a value for x or y given y or x respectively?

I've been reading lots on calculating various curves; but nothing seems to be working towards my goal, and it all gets very complex very quickly. The answer may be that I need to plow through that maths, but just incase there is a simple answer I'm asking here!

The accuracy isn't super important, so long as it's as good as me reading the excel graph...

3

There are 3 answers

0
Agriseld On

You might want to look into regressions. Simply put, applying a regression to a set of x/y values enables you to get a function representing the relationship between x and y. With this function, it is easy to get y for any x.

There are many possible models for regression depending on the shape of your data. Given your data, it looks like a linear regression might be a good fit. In this case, you will get the straight line that best represents your data. Once you have this line as a equation y = ax +b, you can get from x to y or from y to x easily. a and b are computed automatically (lookup least square error to learn more about how).

Regressions and particularly linear regressions are very common statistical tools, so any language/program you use should have a tool for that.

0
Tomer Geva On

A simple method can be through linear interpolation between points (which is what you do when you "eyeball" a solution when looking at the plot.

You can perform linear interpolaiton in a simple matter using the following method:

If you want to know a y value based on x, do the following:

  1. take the two (x,y) points that are the closest points from the right or left to the wated point in the x axis (in the example you got, the point x=815 is in the [814,817] section so taking the points

    1.1. (x1,y1) = (814, 600)

    1.2. (x2,y2) = (817, 1050)

  2. calculate the slope of the section using the following formula:

slope = (y2 - y1) / (x2 - x1)

In our case, this gives:

slope = (1050 - 600) / (817 - 814) = 150
  1. comute the y value of the wanted x using the following:
y = (x-x1) * slope + y1

again, in our example this gives:

y = (815-814)*150 + 600 = 750

If you want to know the 'x' value, based on y, do the following:

  1. take the two (x,y) points that are the closest points from the right or left to the wated point in the y axis (in the example you got, the point y=400 is in the [301,500] section so taking the points

    1.1. (x1,y1) = (812, 301)

    1.2. (x2,y2) = (813, 500)

  2. compute the slope, using the same formula:

slope = (y2 - y1) / (x2 - x1)

In our case, this will be:

slope = (500-301) / (813-812) = 199
  1. compute the wanted x value by:
x = x1 + (y - y1) / slope

and again, in our case it will be:

x = 812 + (400-301) / 199 = 812.4974874
1
Anton Ivanov On

In addition to Tomer Geva answer. Excel(and other similar programs) have builtin function for linear interpolation called FORECAST that works exactly as you want. And if you need to get x by y, just swap x range and y range.