MATLAB: How do you fit a 3 dimensional surface to the given points, given the X and Y co-ordinates, the gradients at these points and the Z co-ordinate for one of these points

curve fittingMATLABspline

The input is:
– The X and Y co-ordinates of 10 points
-The gradients at these 10 points, assuming a spline interpolated surface
-The Z co-ordinate for one of the points, which would serve as the reference or datum
The output required:
-The surface got by interpolating these points
-The remaining 9 Z co-ordinates

Best Answer

This can be accomplished using functions from the Curve Fitting Toolbox and the Global Optimization Toolbox.
The idea is to initially make a guess of the spline surface using random coefficients and the SPMAK function. Using this spline, the directional derivatives can be found with the given X and Y co-ordinates and the datum Z co-ordinate using the FNVAL and the FNDIR function. Then, using LSQCURVEFIT, we can iteratively arrive at a new guess of the spline with derivatives closer to the actual derivatives.
The sample code attached demonstrates this.
Related Question