# how to compute inverse of interpn function

14 views (last 30 days)
Vijay Anand on 2 Dec 2016
Answered: bio lim on 2 Dec 2016
I am looking for the inverse operation of interpn (VI=interpn(X1,X2,X3,X4,V,Y1,Y2,Y3,Y4)
[Y1,Y2,Y3,Y4] = inv_interpn(X1,X2,X3,X4,V,V1).
Y1,Y2,Y3,Y4 can be scalar, if only single solution exist. or it can be a vector is 2 or more solutions exist.
Linear interpolation between the grid points is good enough.
Vijay Anand on 2 Dec 2016
I further add to understand this problem. In 2D sense, if V = f(x1,x2) and to make it simple, V = x1 + x2.
Now, the matrix V looks like this.
The problem is, if we ask for x1,x2 values corresponding to say V = 5, there are infinite solutions exists. (1,4), (2,3), (1.1,3.9), (-5.5,10.5).
So, the right answer is anypoint on this line. Depending on the function V = f(x,y), this line may become a curve / spline. Even continuity of the curve is also not guaranteed !!!
So, for 2D problem, we are looking for a curve with some data points.
similarly, for a 3D problem, we are looking for a matrix ie a plane with data points...
Hope i made it clear.... cheers vijay

bio lim on 2 Dec 2016
This is how you should approach the problem. Let's study the case when V=5.
Let's say we generate 100 possible combinations of x1 and x2 that sum up to 5.
x1 = zeros(200,1);
x2 = zeros(200,1);
Now, we use an iteration to generate a random number, and we "scale" it.
for i = 1:200
rng shuffle
X = rand(2,1,'double');
V = 5;
X = X/sum(X)*V;
X(1) = X(1) - (V-sum(X));
x1(i) = X(1);
x2(i) = X(2);
end
If we plot the above,
figure(1)
grid on
plot(x1,x2,'-k');
title('V = 5')
xlabel('x1');
ylabel('x2');
We get:

### Categories

Find more on Interpolation in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!