To interpolate/extrapolate solution on a uniform grid to a non-uniform grid, or vice versa, using the $\mathtt{TriScatteredInterp}$ class is the way to go.
Let say your u
is associated with nodes: p
, an array size $(\text{ # of nodes})\times (\text{Dimension})$, is originally where your solution u
is defined on, so that size(u,1) = size(p,1)
. The the following commmand let you create an interpolant class (abstractly):
uI = triScatteredInterp(p(:,1),p(:,2),u,'natural');
for two dimensional data, or
uI = triScatteredInterp(p(:,1),p(:,2),p(:,3),u,'natural');
for 3D data. I personally prefer 'natural'
as method here, 'nearest'
is not that nice for PDE solution, and 'linear'
will result in loss of interpolation near boundary where two sides data are needed.
Now to get the values on the non-uniform grid, what is best about triScatteredInterp
class is that it works like a function, you can use feval
to evaluate like a function handle: say your non-uniform grid points are array q
uInterp_at_q = uI(q(:,1),q(:,2));
in 2D or
uInterp_at_q = uI(q(:,1),q(:,2),q(:,3));
in 3D. And uInterp_at_q(i,1)
is the value of the interpolant associated with the $i$-th node q(i,:)
.
Notice mathworks' doc says that
TriScatteredInterp
will be removed in a future release. Use scatteredInterpolant
instead.
The usage will almost the same, just scatteredInterpolant
has an extra extrapolation method switch.