HELP. Need to understand MATH behind scatteredInterpolant or Interp2 function
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gregory Nixon
am 12 Feb. 2021
Kommentiert: Gregory Nixon
am 18 Feb. 2021
Hey all! So I need to understand the math behind how MATLAB calculates interpolated vaulses. I repeat MATH because I know how to use the funtions with ease and I understand the vargin, however my goal is to compare MATLABs equtions with another model I'm wokring in.
The other model im working is giving me an interpolated answer of -17 while MATLAB is producing a value of -38 with the same inputs in both models. I understand how the other model is interpolating. But when you step into intrep2 or scatteredInterpolant you are taken to the green comments. ARG. lol.
So i repeat community I need help with the findining the equations and making sense of them :).
interp_val = f0 * f10 - f9 * blah blah blah. Something of that nature guys/ladies.
Please help someone.
11 Kommentare
Bruno Luong
am 16 Feb. 2021
Bearbeitet: Bruno Luong
am 16 Feb. 2021
What method you are using?
If you use nearest, the result is the function value of the seed of the Voronoi cell where the query belong to.
If you use linear it's a linear function that interpolate the Delaunay triangle where the query point belong to.
If you use the natural, it's a convex sum of function values of the vertexes "augmented" adjacent Delaunay cells (insert query point to the data points) where the weights are given by eqt (28) of the paper https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.8.6623&rep=rep1&type=pdf
There we goes those are the "equations". The equations are straighforward once the geometry of Delaunay/Voronoi diagram is computed. The later is harder to compute but their definition is quite natural and intuitive.
Akzeptierte Antwort
Bruno Luong
am 17 Feb. 2021
"Based on the equation that I had in that screen shot would you assume that the other model is using a simplified linear interpolation model?"
Can't assume anything. The equation lacks of explanation. What are f00, f01, f10, f11, r1 r2 ?
It looks like bilinear formula, but it might hide a bug dependeing how those quantities are defined, and it's odd that bilnear can be applied on a non-parallelogram shape.
Weitere Antworten (2)
Steven Lord
am 15 Feb. 2021
If you believe scatteredInterpolant is computing the wrong answer but cannot share the data with the community, please send your call to scatteredInterpolant along with the data necessary to execute that call and a description of why you believe its answer is incorrect (such as the results from a different interpolation routine) to Technical Support for investigation. You can contact Support using the Contact Support link on the Support section of this website.
2 Kommentare
Steven Lord
am 17 Feb. 2021
Can you show us the exact line of code that you run that uses that data to generate the answer around -38.55?
Just doing a little sanity check, your X value of -66.94 is closer to -67.65 than to -65.93 so you'd expect the interpolated value to be closer to the values in the first column of "MATLAB Table". Similarly your Y value of -6.34 is closer to -5.77 than to -7.49 and so the interpolated value should probably be closer to -56.349 than to the other three data values. A -38.55 doesn't seem like an unreasonable answer given this rough argument.
x = [-67.65351209, -65.93466751];
y = [-7.493951899, -5.775107322];
text(x(1), y(1), '-26.1915')
text(x(1), y(2), '-56.3497')
text(x(2), y(1), '-13.1290')
text(x(2), y(2), '-14.2824')
hold on
plot(-66.94213289, -6.346280917, 'rx')
axis([-68, -65, -8, -5.5])
Bruno Luong
am 17 Feb. 2021
Bearbeitet: Bruno Luong
am 17 Feb. 2021
Run this, that show the "formula" and how to get
zq =
-38.5561
zq_check =
-38.5561
Code to check 'linear' method (you seem to not bother to answer my question about the method):
x = [-67.65351209, -65.93466751];
y = [-7.493951899;
-5.775107322];
[X,Y] = meshgrid(x,y);
Z = [-26.19150131, -13.12900262;
-56.3497907, -14.28238121];
xq = -66.94213289;
yq = -6.346280917;
f = scatteredInterpolant(X(:), Y(:), Z(:));
zq = f(xq,yq)
% The Delaunay triangulation showz (xq,yq) belong to triangle of points 2/3/4
M = [X([2 3 4]);
Y([2 3 4]);
[1 1 1]];
w234 = M \ [xq; yq; 1]; % barycentric coordinate
zq_check = Z([2 3 4])*w234 % interpolation value
close all
T = delaunay(X,Y);
trimesh(T,X,Y,Z,'EdgeColor','k');
hold on
for i=1:numel(X)
text(X(i),Y(i),Z(i),num2str(i));
end
plot3(xq, yq, zq, '+r', 'Linewidth', 3, 'Markersize', 20)
text(xq, yq, zq, 'Query point', 'Color', 'r');
PS: Next time please attach data point and code and not only screen capture to avoid us to enter the data by hand.
2 Kommentare
Bjorn Gustavsson
am 17 Feb. 2021
Try and see what you get. This will give you some insight into what is going on:
[x,y] = meshgrid(0:1);
z = [3 2;0 3];
[xi,yi] = meshgrid(0:.1:1);
zi = interp2(x,y,z,xi,yi);
f = scatteredInterpolant(x(:), y(:), z(:));
zq = f(xi,yi);
sph1 = subplot(1,2,1);
surf(xi,yi,zq)
sph2 = subplot(1,2,2);
surf(xi,yi,zi)
linkprop([sph1,sph2],'view')
Then you can rotate the surfaces around, repeat the procedure in your other analysis environments.
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!