xGrid = linspace(min(x1), max(x1), 20);
zGrid = [-0.11 0:5:30 50:50:500];
tGrid = [50 65 75 80 90 100 115];
gridPoints = {xGrid, yGrid, zGrid, tGrid};
smoothness = [1e-4, 1e-3, 1e-3, 1e-2];
% smoothness = [7e-3, 1e-2, 8e-3, 1e-1]; % better values
yPlotLevels = [20 40 60 80];
gridForPlots = cell(4,1);
[gridForPlots{:}] = ndgrid(xGrid, yPlotLevels, zGrid, tPlotLevels);
surfaceHandles = nan(length(tPlotLevels), length(yPlotLevels));
% Calculate regularized surface and time it
wGrid = regularizeNd([x1,y1,z1,t1], w1, gridPoints, smoothness, 'linear');
% create the griddedInterpolant function
wFunction = griddedInterpolant(gridPoints, wGrid, 'linear');
% calculate values for the plots
wPlot = wFunction(gridForPlots{:});
% create the plot levels. Often I use a lot more than 8 levels. Often,
% I will put them on the same figure/axes. However, for simplicity and
% clarity, I left them as individual figures here.
for iT = 1:length(tPlotLevels)
for iY = 1:length(yPlotLevels)
if ishghandle(surfaceHandles(iT,iY))
set(surfaceHandles(iT,iY), 'Zdata', squeeze(wPlot(:,iY,:,iT))');
surfaceHandles(iT,iY) = surf(xGrid, zGrid, squeeze(wPlot(:,iY,:,iT))');
xlabel('x');ylabel('z'); zlabel('w');
title(sprintf('Level y = %g, Level t = %g. Use to check smoothness.', yPlotLevels(iY), tPlotLevels(iT)));
% Ask for a new smoothness
answer = input('Enter a new smoothness to recaculate surface.');
warning('Negative values of smoothness not excepted. No changes made.');
if any(length(answer) == [1 length(gridPoints)])
warning('smoothness must be either scalar or have same number elements as the length of gridPoints. No change to smoothness was made.');
end
Elapsed time is 6.866527 seconds.
smoothness = 1.0000e-03
Elapsed time is 6.677745 seconds.
% calculate the residuals
residualsAbsolute = w1 - wFunction(x1,y1,z1,t1);
histogram(residualsAbsolute, 'FaceColor', 'auto', 'EdgeColor', 'auto')
% Copyright (c) 2016-2026 Jason Nicholson
% Licensed under the MIT License
% See LICENSE file in project root