How to extrapolate a fitted surface so that it is defined in a certain range?

13 次查看(过去 30 天)
I want to make a piecewise linear interpolation fit of a surface from random points within a range of x and y, and next I want to calculate the fitting error. But how do I make sure the fit is defined on the range of x and y?
Below a simplified example. From the figure it can be seen that the surface fit is only defined in a certain region. How do I make sure that the fit (in this example) is defined from x = 0:10 and y = 0:10, without adding points? If I now fill in a point outside the surface, but within x = 0:10 and y = 0:10, I get Z = NaN.
% Define function
z = @(x,y)x.^2;
% Define x- and y-grid
x_min = 0;
x_max = 10;
x = x_min:0.1:x_max;
y_min = 0;
y_max = 10;
y = y_min:0.1:y_max;
Dim = 2;
N = 10; % Number of interpolation points
% Create Halton Sequence
HaltonSequence = net(haltonset(Dim),N).*([x_max,y_max]-...
[x_min,y_min])+ones(N,Dim).*[x_min,y_min];
% Surface fit
Z = fit(HaltonSequence,feval(z,HaltonSequence(:,1),HaltonSequence(:,2)),'linearinterp');
plot(Z,[HaltonSequence(:,1),HaltonSequence(:,2)],...
feval(z,HaltonSequence(:,1),HaltonSequence(:,2)))

回答(1 个)

Sam McDonald
Sam McDonald 2016-10-25
I understand that you need to extrapolate a piece-wise linear interpolated surface so that it is defined for a desired range of x and y values beyond those needed to define the surface. The 'fit' function allows you to choose the interpolation method, but it does not allow you to specify an extrapolation method. The scatteredInterpolant class will allow you to do this easily. Simply replace the 'fit' function with 'scatteredInterpolant' and specify the interpolation and extrapolation methods to 'linear' as follows:
Z = scatteredInterpolant(HaltonSequence, feval(z, HaltonSequence(:,1), HaltonSequence(:,2)), 'linear', 'linear');
For more information on the 'scatteredInterpolant' function visit:
Piece-wise linear interpolation is not technically the same as fitting. There will be no fitting error when using a linear interpolation in this way because the surface will always pass through every point.

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by