%% Recover the Underlying Exact Smooth Values from Noised Data
% The following code obtains values of a smooth function at 31 randomly chosen sites, adds some random noise to these values, and then uses tpaps to recover the underlying exact smooth values. To illustrate how well tpaps does in this case, the code plots, in addition to the smoothing spline, the exact values (as black balls) as well as each arrow leading from a smoothed value to the corresponding noisy value.

rng(23); nxy = 31;
xy = 2*(rand(2,nxy)-.5); vals = sum(xy.^2);
noisyvals = vals + (rand(size(vals))-.5)/5;
st = tpaps(xy,noisyvals); fnplt(st), hold on
avals = fnval(st,xy);
plot3(xy(1,:),xy(2,:),vals,'wo','markerfacecolor','k')
quiver3(xy(1,:),xy(2,:),avals,zeros(1,nxy),zeros(1,nxy), ...
         noisyvals-avals,'r'), hold off

% Copyright 2019 The MathWorks, Inc.