Main Content

Extrapolating Scattered Data

Factors That Affect the Accuracy of Extrapolation

散落的人provides functionality for approximating values at points that fall outside the convex hull. The'linear'extrapolation method is based on a least-squares approximation of the gradient at the boundary of the convex hull. The values it returns for query points outside the convex hull are based on the values and gradients at the boundary. The quality of the solution depends on how well you’ve sampled your data. If your data is coarsely sampled, the quality of the extrapolation is poor.

In addition, the triangulation near the convex hull boundary can have sliver-like triangles. These triangles can compromise your extrapolation results in the same way that they can compromise interpolation results. SeeInterpolation Results Poor Near the Convex Hullfor more information.

You should inspect your extrapolation results visually using your knowledge of the behavior outside the domain.

比较粗糙和细化的分散数据的外推

此示例显示了如何插值相同抛物线函数的两个不同采样。它还表明,更好的样品分布会产生更好的外推结果。

创建一个radial distribution of points spaced 10 degrees apart around 10 concentric circles. Usebsxfunto compute the coordinates, x = cos θ y = sin θ

theta = 0:10:350; c = cosd(theta); s = sind(theta); r = 1:10; x1 = bsxfun(@times,r.',c); y1 = bsxfun(@times,r.',s); figure plot(x1,y1,'*b') axisequal

Figure contains an axes object. The axes object contains 36 objects of type line.

创建一个second, more coarsely distributed set of points. Use the兰德function to create random samplings in the range, [-10, 10].

rngdefault; x2 = -10 + 20*rand([25 1]); y2 = -10 + 20*rand([25 1]); figure plot(x2,y2,'*')

Figure contains an axes object. The axes object contains an object of type line.

Sample a parabolic function,v(x,y), at both sets of points.

v1 = x1.^2 + y1.^2; v2 = x2.^2 + y2.^2;

创建一个散落的人for each sampling ofv(x,y)

f1 = scatseDInterpolant(x1(:),y1(:),v1(:));f2 = scatteredInterpolant(x2(:),y2(:),v2(:));

创建一个grid of query points that extend beyond each domain.

[xq,yq] = ndgrid(-20:20);

评估F1和plot the results.

figure vq1 = F1(xq,yq); surf(xq,yq,vq1)

Figure contains an axes object. The axes object contains an object of type surface.

评估F2和plot the results.

figure vq2 = F2(xq,yq); surf(xq,yq,vq2)

Figure contains an axes object. The axes object contains an object of type surface.

The quality of the extrapolation is not as good forF2由于点的粗略抽样v2

Extrapolation of 3-D Data

This example shows how to extrapolate a well sampled 3-D gridded dataset using散落的人。查询点位于完全是外部域的平面网格上。

创建一个10-by-10-by-10 grid of sample points. The points in each dimension are in the range, [-10, 10].

[x,y,z] = ndgrid(-10:10);

Sample a function,v(x,y,z), at the sample points.

v = x.^2 + y.^2 + z.^2;

创建一个散落的人, specifying linear interpolation and extrapolation.

F = scatteredInterpolant(x(:),y(:),z(:),v(:),'linear','linear');

评估the interpolant over anx-ygrid spanning the range, [-20,20] at an elevation,z= 15.

[xq,yq,zq] = ndgrid(-20:20,-20:20,15); vq = F(xq,yq,zq); figure surf(xq,yq,vq)

Figure contains an axes object. The axes object contains an object of type surface.

The extrapolation returned good results because the function is well sampled.