## Does interp3 (with linear option) perform trilinear interpolation?

Asked by Jordan Y

### Jordan Y (view profile)

on 15 Jun 2018
Latest activity Answered by Jordan Y

### Jordan Y (view profile)

on 17 Jun 2018
Accepted Answer by John D'Errico

### John D'Errico (view profile)

Can anyone confirm that interp3 (with the linear interpolation method) performs trilinear interpolation as described by: https://en.wikipedia.org/wiki/Trilinear_interpolation?
Similarly, can anyone confirm that interp2 (with the linear interpolation method) performs bilinear interpolation as described by: https://en.wikipedia.org/wiki/Bilinear_interpolation?

### Release

R2017a ### John D'Errico (view profile)

Answer by John D'Errico

### John D'Errico (view profile)

on 15 Jun 2018
Edited by John D'Errico

### John D'Errico (view profile)

on 15 Jun 2018

Both interp2 and interp3 use n-dimensional tensor product linear interpolation, thus respectively bilinear and trilinear interpolation.
Interp2 uses bilinear interpolation.
Interp3 uses trilinear interpolation.
How do I know this? Both tools use griddedInterpolant, when called with the 'linear' option.
In the help for griddedInterpolant, we see the statement:
% The Method is one of the following:
% 'linear' - (default) linear, bilinear, trilinear,... interpolation
Just to be painfully sure, I checked. Both interp2 and interp3 produce a characteristic NONLINEAR interpolation, when applied along the diagonal of the corresponding 2-d and 3-d hypercubes. This is a known fact about bilinear and trilinear interpolation, that bilinear interpolation when applied through the main diagonal of a square produces a characteristic quadratic function along the path where X==Y. Likewise, a trilinear interpolant produces a characteristic cubic polynomial along the corresponding diagonal path where X==Y==Z.
Ok, I said this behavior is a known fact. I did not say it was a well known fact. Not difficult to prove though. Just for kicks, in case you might not believe me...
Vq = interp2(0:1,0:1,[0 1;1 0],0:.1:1,0:.1:1,'linear')
Vq =
0 0.18 0.32 0.42 0.48 0.5 0.48 0.42 0.32 0.18 0
plot(Vq) You can do a similar test for interp3, generating a very pretty cubic curve.
Note that the nonlinear behavior of bilinear and trilinear interpolation along that diagonal are in fact a reason why other interpolation methods are sometimes chosen, when a linear interpolant is required. However, it is also true that any variety of "linear" interpolant will exhibit similarly interesting artifacts if you push them. And yes, there is at least one alternative method one can choose that also produces an interpolant that is arguably "linear".