Weighted least-squares fitting by tensor product B-splines to discrete two-dimensional data is performed. Constraints on the spline or its partial derivatives are optional. The spline function
its derivatives, or the square root of its variance function are evaluated after the fitting.
Required Arguments
DATA= DATA(1:4,:) (Input/Output) An assumed-shape array with size(data,1) = 4. The data are placed in the array:
data(1,i) = xi ,
data(2,i) = yi ,
data(3,i) = zi ,
data(4,i) = σi , i = 1,…ndata .
If the variances are not known, but are proportional to an unknown value, use
data(4,i) = 1,i = 1,…ndata .
KNOTSX = KNOTSX (Input) A derived type, ?_SPLINE_KNOTS, that defines the degree of the spline and the breakpoints for the data fitting domain, in the first dimension.
KNOTSY= KNOTSY (Input) A derived type, ?_SPLINE_KNOTS, that defines the degree of the spline and the breakpoints for the data fitting domain, in the second dimension.
Optional Arguments
CONSTRAINTS = SURFACE_CONSTRAINTS (Input) A rank-1 array of derived type ?_SURFACE_CONSTRAINTS that defines constraints the tensor product spline is to satisfy.
COVARIANCE = G (Output) An assumed-shape rank-2 array of the same precision as the data. This output is the covariance matrix of the coefficients. It is optionally used to evaluate the square root of the variance function.
IOPT = IOPT(:) (Input/Output) Derived type array with the same precision as the input array; used for passing optional data to SURFACE_FITTING. The options are as follows:
Packaged Options for SURFACE_FITTING
Prefix = None
Option Name
Option Value
SURFACE_FITTING_SMALLNESS
1
SURFACE_FITTING_FLATNESS
2
SURFACE_FITTING_TOL_EQUAL
3
SURFACE_FITTING_TOL_LEAST
4
SURFACE_FITTING_RESIDUALS
5
SURFACE_FITTING_PRINT
6
SURFACE_FITTING_THINNESS
7
IOPT(IO)= ?_OPTIONS&
(surface_fitting_smallnes, ?_value) This resets the square root of the regularizing parameter multiplying the squared integral of the unknown function. The argument ?_value is replaced by the default value. The default is ?_value = 0.
IOPT(IO) = ?_OPTIONS&
(SURFACE_FITTING_FLATNESS, ?_VALUE) This resets the square root of the regularizing parameter multiplying the squared integral of the partial derivatives of the unknown function. The argument ?_VALUE is replaced by the default value.
The default is ?_VALUE = SQRT(EPSILON(?_VALUE))*SIZE, where
IOPT(IO)= ?_OPTIONS&
(SURFACE_FITTING_TOL_EQUAL, ?_VALUE) This resets the value for determining that equality constraint equations are rank-deficient. The default is ?_VALUE= 10-4.
IOPT(IO) = ?_OPTIONS&
(SURFACE_FITTING_TOL_LEAST, ?_VALUE) This resets the value for determining that least-squares equations are rank-deficient. The default is ?_VALUE =10-4.
IOPT(IO) = ?_OPTIONS&
(SURFACE_FITTING_RESIDUALS, DUMMY) This option returns the residuals = surface - data, in data(4,:). That row of the array is overwritten by the residuals. The data is returned in the order of cell processing order, or left-to-right in x and then increasing in y. The allocation of a temporary for data(1:4,:) is avoided, which may be desirable for problems with large amounts of data. The default is to not evaluate the residuals and to leave data(1:4,:) as input.
IOPT(IO) = ?_OPTIONS&
(SURFACE_FITTING_PRINT, DUMMY) This option prints the knots or breakpoints for x and y, and the count of data points in cell processing order. The default is to not print these arrays.
IOPT(IO)= ?_OPTIONS&
(SURFACE_FITTING_THINNESS, ?_VALUE) This resets the square root of the regularizing parameter multiplying the squared integral of the second partial derivatives of the unknown function. The argument ?_VALUE is replaced by the default value. The default is ?_VALUE = 10-3 × SIZE, where
Specific: The specific interface names are S_SURFACE_FITTING and D_SURFACE_FITTING.
Description
The coefficients are obtained by solving a least-squares system of linear algebraic equations, subject to linear equality and inequality constraints. The system is the result of the weighted data equations and regularization. If there are no constraints, the solution is computed using a banded least-squares solver. Details are found in Hanson (1995).
Fatal and Terminal Error Messages
See the messages.gls file for error messages for SURFACE_FITTING. These error messages are numbered 1151-1152, 1161-1162, 1370-1393.
Examples
Example 1: Tensor Product Spline Fitting of Data
The function
is least-squares fit by a tensor product of cubic splines on the square
There are ndata random pairs of values for the independent variables. Each datum is given unit uncertainty. The grid of knots in both x and y dimensions are equally spaced, in the interior cells, and identical to each other. After the coefficients are computed a check is made that the surface approximately agrees with g(x,y) at a tensor product grid of equally spaced values.
USE surface_fitting_int
USE rand_int
USE norm_int
implicit none
! This is Example 1 for SURFACE_FITTING, tensor product
! B-splines approximation. Use the function
! exp(-x**2-y**2) on the square (0, 2) x (0, 2) for samples.
! The spline order is "nord" and the number of cells is
! "(ngrid-1)**2". There are "ndata" data values in the square.
write(*,*) 'Example 1 for SURFACE_FITTING is correct.'
end if
end
Output
Example 1 for SURFACE_FITTING is correct.
Example 2: Parametric Representation of a Sphere
From Struik (1961), the parametric representation of points (x,y,z) on the surface of a sphere of radius a > 0 is expressed in terms of spherical coordinates,
The parameters are radians of latitude (u) and longitude (ν). The example program fits the same random pairs of latitude and longitude in each coordinate. We have covered the sphere twice by allowing:
for latitude. We solve three data fitting problems, one for each coordinate function. Periodic constraints on the value of the spline are used for both u and ν. We could reduce the computational effort by fitting a spline function in one variable for the z coordinate. To illustrate the representation of more general surfaces than spheres, we did not do this. When the surface is evaluated we compute latitude, moving from the South Pole to the North Pole,
Our surface will approximately satisfy the equality
These residuals are checked at a rectangular mesh of latitude and longitude pairs. To illustrate the use of some options, we have reset the three regularization parameters to the value zero, the least-squares system tolerance to a smaller value than the default, and obtained the residuals for each parametric coordinate function at the data points.
USE surface_fitting_int
USE rand_int
USE norm_int
USE Numerical_Libraries
implicit none
! This is Example 2 for SURFACE_FITTING, tensor product
! B-splines approximation. Fit x, y, z parametric functions
! for points on the surface of a sphere of radius “A”.
! Random values of latitude and longitude are used to generate
! data. The functions are evaluated at a rectangular grid
! in latitude and longitude and checked to lie on the surface
write(*,*) "Example 2 for SURFACE_FITTING is correct."
end if
end
Output
Example 2 for SURFACE_FITTING is correct.
Example 3: Constraining Some Points using a Spline Surface
This example illustrates the use of discrete constraints to shape the surface. The data fitting problem of Example 1 is modified by requiring that the surface interpolate the value one at x = y = 0. The shape is constrained so first partial derivatives in both x and y are zero at x = y = 0. These constraints mimic some properties of the function g(x,y). The size of the residuals at a grid of points and the residuals of the constraints are checked.
USE surface_fitting_int
USE rand_int
USE norm_int
implicit none
! This is Example 3 for SURFACE_FITTING, tensor product
! B-splines approximation, f(x,y). Use the function
! exp(-x**2-y**2) on the square (0, 2) x (0, 2) for samples.
! The spline order is "nord" and the number of cells is
! "(ngrid-1)**2". There are "ndata" data values in the square.
! Constraints are put on the surface at (0,0). Namely
write(*,*) 'Example 3 for SURFACE_FITTING is correct.'
end if
end
Output
Example 3 for SURFACE_FITTING is correct.
Example 4: Constraining a Spline Surface to be non-Negative
The review of interpolating methods by Franke (1982) uses a test data set originally due to James Ferguson. We use this data set of 25 points, with unit uncertainty for each dependent variable. Our algorithm does not interpolate the data values but approximately fits them in the least-squares sense. We reset the regularization parameter values of flatness and thinness, Hanson (1995). Then the surface is fit to the data and evaluated at a grid of points. Although the surface appears smooth and fits the data, the values are negative near one corner. Our scenario for the application assumes that the surface be non-negative at all points of the rectangle containing the independent variable data pairs. Our algorithm for constraining the surface is simple but effective in this case. The data fitting is repeated one more time but with positive constraints at the grid of points where it was previously negative.
USE surface_fitting_int
USE rand_int
USE surface_fitting_int
USE rand_int
USE norm_int
implicit none
! This is Example 4 for SURFACE_FITTING, tensor product
! B-splines approximation, f(x,y). Use the data set from
! Franke, due to Ferguson. Without constraints the function
! becomes negative in a corner. Constrain the surface