John CAE
John CAE

Reputation: 21

Finding intersections of curves that cannot be represented as y=f(x)

I have two pairs of data sets, x1 vs y1 and x2 vs y2. x1, y1, x2, y2 all have uneven distribution of data represented by the following images:

x1 x2 y1 y2

My problem is to determine the intersection of the two pairs of data sets, x1/y1 and x2/y2, shown in following image:

x1/y1 vs x2/y2

I tried interpolating the data points to have even spacing, but due invalid regions of x1/y1 where there are multiple solutions for the same x value.

Here is a zoom in of the x1/y1 and x2/y2 relationship, showing that there are knots within the data set that cannot be interpolated in any orientation:

zoom in of x1/y1 and x2/y2 relationship

Upvotes: 2

Views: 162

Answers (1)

HackerBoss
HackerBoss

Reputation: 829

It seems that x2/y2 is a smooth curve, so you should be able to interpolate it piecewise with polynomials, and get decent results. Of course you will not want to do this with x1/y1, as your data is crazy. I will refer to the independent variable in the last two images as t. You can use the matlab spline function to do this interpolation from arrays of t and x2/y2 values. Your t value array in this case should be the same size as your set of x2/y2 values. Then you could loop over your x1/y1 points, using the interpolation to estimate x2/y2 at the same value of t. Then you could subtract these values. When the sign of this value changes for two consecutive x1/y1 points, you have a point of intersection between them. Then perform a linear interpolation between those two x1/y1 points and find the intersection of that line with your interpolated x2/y2 function. The code may get a little messy, but it should work. You will want to look at the MATLAB spline documentation.

Upvotes: 1

Related Questions