Does Mathematica have 2D smoothing spline interpolation built in? I requires an interpolation method with smooth first derivatives and cubic bivariate splines fulfill this nicely. In python I would use RectBivariateSpline
or SmoothBivariateSpline
.
A quick search only revealed this answer, which I guess could be adapted to 2D with some effort.
Here is some test data:
RANGEX = 8;
RANGEY = 8;
F[x_, y_] :=
Sin[.5 y] Cos[.9 x]/Sec[0.1 x y] -
0.01 (x^2 + y^2) RiemannSiegelZ[1.5 Sqrt[x^2 + y^2]]
data = N[Flatten[
Table[{x, y, F[x, y]}, {x, -RANGEX, RANGEX, 1}, {y, -RANGEY,
RANGEY, 1}], 1]];
(*add some noise*)
data[[All, 3]] =
data[[All, 3]] +
RandomVariate[NormalDistribution[0, 0.1], Length[data]];
PlotPointsAndSurface[points_, surface_, label_] := Module[{},
Show[
ListPointPlot3D[points,
PlotStyle -> {Directive[PointSize[0.01], Red],
Directive[PointSize[0.01], Green]}, PlotLabel -> label,
ImageSize -> Medium],
Plot3D[surface, {x, -RANGEX, RANGEX}, {y, -RANGEY, RANGEY},
PlotStyle -> Directive[Purple, Opacity[0.2]]]
]];
PlotPointsAndSurface[data, F[x, y], "orig and noise"]
Comments
Post a Comment