"MathNewbie" <ma********@example.orgwrote in message

news:45*********************@news.xs4all.nl...

[...]

Anyway, i have an array of points on a basic 2 dimensional axis. They are

all points of a sine shaped line. (not a perfect sine though, as it's

actually tide movement data that is roughly looking as a sine).

I would like to calculate the y dimension for a point with a known x

value.

If the points are sorted on the x coordinate, this is not hard at all. For

x where x is actually in your data set, it's simply a matter of looping

through the array to find x. With a sorted array, you can use a binary

search to more quickly find the point of interest.

If the x value does not actually correspond to one of the points within the

array, then you'll have to interpolate the value from one of the known

values. You'll still have to search, but rather than finding the exact

match, you'll find a pair of points in the array, between which that x value

would be found. Once you've done that, you apply the ratio of the desired x

to the interval between the x values of the two known points, to the

interval between the y values of the two known points, to find the desired y

value.

For example:

Suppose you have the set describing f(x) as { {0, 0}, {2, 3}, {4, 5}, {6,

8} }

(yes, I'm aware that's not a sine wave :) )

Suppose also that you want y = f(x) where x is 3. Searching through your

array, you fail to find an entry where x is 3, but you do find the entries

{2, 3} and {4, 5}. Call these {x0, y0} and {x1, y1}. Then...

y = y0 + (y1 - y0) * (x - x0) / (x1 - x0);

In the specific example:

y = 3 + (5 - 3) * (3 - 2) / (4 - 2)

= 3 + 2 * 1 / 2 = 4;

Can anyone help me solve this issue or give a pointer in the right

direction by providing some of the math slang for this problem?

"Interpolation" is the math buzz word that applies to your question. But

hopefully the above gives you the details you need.

Note that x needs to be within the range of known x values (or you have to

"extrapolate" off each end), and this does not guarantee a perfect match to

the curve that may represent your data. This is a linear interpolation, so

between each known point, the interpolated points fall on a straight line.

Since the actual data is curved, this means that the calculated value will

deviate from the correct value by some (usually small) amount. The error is

greatest when the desired value is farthest from either end of the

interpolation range.

If you want more accurate results, you will have to use more complex forms

of interpolation. Another common method is "polynomial approximation",

where you solve a large matrix of equations (one for each data point you

have) to establish constants and exponents to whatever degree you want. Yet

another method would involve fitting a sin function to subsets of your data,

allowing you to use an interpolated sin approximation of the function.

Of course, in all cases you are not guaranteed to have an exactly correct

answer. Any time you are filling in data that is absent from actual

empirical recordings, you have no way to know for sure that you have

interpolated the correct data. All you can say is that you have

interpolated a relatively useful simile of the correct data.

Pete