Interpolation of scattered data in 4 dimensions
Scattered data consists of a set of points X and corresponding values V, where the points have no structure or order between their relative locations. There are various approaches to interpolating scattered data. One widely used approach uses a Delaunay triangulation of the points. In this example a single-valued multivariate function is defined over random scattered 4D data. Then the value of the function is found at an intermediate requested point through interpolation between its values at neighboring points. The function involves an analytic formula so that the interpolation result can be checked directly by evaluating the function at the requested point. Note that the number of required scattered points increases in higher dimensions, in order to maintain the accuracy of the interpolated value.
Set the random number generator.
Set the dimension of the problem.
Set the unit 4D cube vertices over which the function is defined.
ends=[0 1]; points1=zeros(2^d,d); for i=0:d-1 rep=repmat(ends,2^(d-i-1),2^i); points1(:,i+1)=rep(:); end points1=10*points1-5+0.001*rand(size(points1));
Set the scattered random 4D data over which the function is defined.
Set the function values.
Set the query point.
Find the Delaunay triangulation of the 4D scattered data.
Find the vertices of the simplex the query point lies in. For this purpose, find the barycentric coordinates of the query point with respect to each simplex of the Delaunay triangulation . If all of the barycentric coordinates are larger than 0 for a given simplex, then this simplex contains the query point and the loop is terminated.
for i=1:size(T,1) psimplex=points(T(i,:),:); pdiff=psimplex-psimplex(ones(d+1,1),:); pointdiff=pquery-psimplex(1,:); st=pdiff(2:d+1,:)'\pointdiff'; barcoords=zeros(d+1,1); barcoords(1,:)=1-sum(st); barcoords(2:d+1,:)=st; if all(barcoords>0) interp_simplex=i; interp_barcoords=barcoords; break; end end
Approximate the value of the function at the query point through linear interpolation of the function values at the vertices of the simplex containing the query point.
Calculate the value of the function at the query point through its analytical formula.
Find the relative error due to the interpolation.
rel_err = 0.5297
(c) 2014 by George Papazafeiropoulos First Lieutenant, Infrastructure Engineer, Hellenic Air Force Civil Engineer, M.Sc., Ph.D. candidate, NTUA