reverse of interpolation.....

29 views (last 30 days)
KSSV
KSSV on 5 Jul 2016
Edited: John D'Errico on 5 Jul 2016
I have a function V that is computed from two inputs (X,Y). I am using a grid of points and performing 2d interpolation.
X = [1,2,3];
Y = [1,2,3];
V =[3,4,5;6,7,8;9,10,11];
Is is easy to obtain V for any combination of (X,Y), for example:
Vq = interp2(X,Y,V,1.8,2.5)
Vq = 8.3000
I now want to inverse that function and for fixed V, how one can find respective X, Y?
Thank you in advance.
  4 Comments
José-Luis
José-Luis on 5 Jul 2016
Edited: José-Luis on 5 Jul 2016
Well, you have your own answer: Use contour for the values you are interested in. There are quite a few algortihms to get isolines. Looking at contour.m does not say much about how it's done so if you want the details you'd have to ask the Mathworks I guess.
John D'Errico
John D'Errico on 5 Jul 2016
I added an answer that explains how a contour tool does its job.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 5 Jul 2016
Edited: John D'Errico on 5 Jul 2016
As others have said, this problem IS solved using contour. The followup question seems to have been, HOW does contour do it? That part is simple.
1. Break any cell of a regular grid into a set of rectangles. We can reduce the large problem with many rects into a sequence of small problems, one on every rect in the overall mesh.
2. Next, break the given rect into a pair of triangles. Solve the problem on each triangle independently.
So, really, the issue is, how do you solve the contour finding problem over a single triangle? That part is trivial. Given a triangle with known function values at each vertex, and a contour level.
Does the contour cross the triangle? This is trivial to do. Test each edge of the triangle. A contour must pass through exactly zero or two edges of a triangle. (Or it must pass through a vertex. Handle the vertex case separately.)
If the contour is perceived to pass through two edges, then use linear interpolation to locate the points where the contour crosses them. Then connect the two points as part of the contour.
Note that IF a function is assumed to be linear on a triangle, then if we determine two points that lie on the line, we can simply connect those two points. Two points determine a line, and the line MUST lie in the plane of the triangle.
Repeat the above for EVERY triangle in the mesh. You will get a set of line segments, that form a contour.
There are two options. You can use a marching scheme, where you follow the contour from triangle to triangle, until you either fall off the edge of the world, or you return to a start point. Or you can simply generate all those segments in a massively vectorized solution. (The latter is how I wrote my codes that solve this same problem.)
Regardless, the solution to the inverse interpolation problem on a two-dimensional problem requires the creation of a path through the (x,y) plane that satisfies the inverse problem. You can think of the locus of solutions as a piecewise linear approximation to a 1-manifold, embedded in the (x,y) plane.

More Answers (2)

José-Luis
José-Luis on 5 Jul 2016
Some time ago, contourc() the low-level function on which contour() is based, used to do it through linear interpolation. That might have changed, but since contourc() is a built-in function, the implementation is hidden from the user.
Apparently there used to be a description in the documentation but that is no longer accessible.

Star Strider
Star Strider on 5 Jul 2016
I would experiment with the contour function. You can have contour return the (x,y) coordinates for a specific value or range of values of ‘V’. (This is a common way of determining the zeros of a bivariate function.) See the contour documentation for Display Single Contour Line for details.
Returning the (x,y) coordinates for a specific value of ‘V’ requires that you use the first column for a specific value to determine the value (first row), and the number of (x,y) pairs that contour calculates (second row).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!