Login Logout Register Discuss Discuss Edit Edit
Jump to: navigation, search

Using Matlab to fit tensor product splines to bivariate gridded data (2)

This example shows how to use the spline commands in Curve Fitting Toolbox to fit tensor product splines to bivariate gridded data.

Since Curve Fitting Toolbox can handle splines with _vector_ coefficients, it is easy to implement interpolation or approximation to gridded data by tensor product splines. Most spline construction commands in the toolbox take advantage of this.

However, you might be interested in seeing a detailed description of how approximation to gridded data by tensor products is actually done for bivariate data.  This will also come in handy when you need some tensor product construction not provided by the commands in the toolbox.

Model File Tree

Software Used

Matlab

Matlab Logo.png

MATLAB (matrix laboratory) is a multi-paradigm programming numerical computing environment and fourth-generation programming language. A proprietary programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of function and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C , C++, C Sharp, Java, Fortran and Python.

For more details see Matlab .

Results

Here is an example of Least-Squares Approximation to Gridded Data. Lets take some gridded data from Franke's sample function. Note that the grid is somewhat denser near the boundary, to help pin down the approximation there.

JobT64-Figure1.png

Next lets find the choice of spline space in the Y-direction. Figure 2 shows the simultaneous approximation to all curves in the Y-direction.

JobT64-Figure2.png

Note that, for each |x(i)|, both the first two and the last two values are zero since both the first two and the last two sites in |yy| are outside the basic interval for the spline |sp|. Also note the "ridges" that run along the y-direction, most noticeable near the peaks of the surface. They confirm that we are plotting smooth curves in one direction only.

Now lets move from curves to a surface, lets choosing a spline space in the X-direction. Here is the plot of the spline approximant.

JobT64-Figure3.png

There are some more efficient alternatives. Since the matrices |spcol(knotsx,kx,xv)| and |spcol(knotsy,ky,yv)| are banded, it may be more efficient for "large" |xv| and |yv| (though perhaps more memory-consuming) to make use of |fnval|. In fact, |fnval| and |spmak| can deal directly with multivariate splines. Better yet, the construction of the approximation can be done by _one_ call to |spap2|, therefore we can obtain these values directly from the given data. Here is a plot of the error, i.e., the difference between the given data value and the value of the spline approximation at those data sites.

JobT64-Figure4.png

Simultaneous Approximation to All Curves in the X-Direction :-

JobT64-Figure5.png

The Spline Interpolant:

JobT64-Figure6.png

Interpolation error:

JobT64-Figure7.png

Related Models

Following are some related models available for cloning/copying by anyone:

Click on the category links at the bottom of this page to navigate to a full list of simulation models in similar subject area or similar computational methodology.

Model New Results

JobT64-Figure6.png JobT64-Fig1.png JobT64-Figure7.png JobT64-Figure3.png JobT64-Figure1.png JobT64-Figure5.png JobT64-Figure4.png JobT64-Figure2.png