Module Summary

Interfaces for the NAG Mark 29.3 fit Chapter.

fit - Curve and Surface Fitting

The main aim of this module is to assist you in finding a function which approximates a set of data points. Typically the data contain random errors, as of experimental measurement, which need to be smoothed out. To seek an approximation to the data, it is first necessary to specify for the approximating function a mathematical form (a polynomial, for example) which contains a number of unspecified coefficients: the appropriate fitting function then derives for the coefficients the values which provide the best fit of that particular form. The module deals mainly with curve and surface fitting (i.e., fitting with functions of one and of two variables) when a polynomial or a cubic spline is used as the fitting function, since these cover the most common needs. However, fitting with other functions and/or more variables can be undertaken by means of general linear or nonlinear functions (some of which are contained in other modules) depending on whether the coefficients in the function occur linearly or nonlinearly. Cases where a graph rather than a set of data points is given can be treated simply by first reading a suitable set of points from the graph.

The module also contains functions for evaluating, differentiating and integrating polynomial and spline curves and surfaces, once the numerical values of their coefficients have been determined.

There is also a function for computing a Padé approximant of a mathematical function (see Background to the Problems).

See Also :

This subpackage contains examples for the fit module. See also the Examples subsection.

Functionality Index

Automatic fitting

with cubic splines: dim1_spline_auto()

Automatic knot placement

with bicubic splines

data on rectangular mesh: dim2_spline_grid()

Data on lines: dim2_cheb_lines()

Data on rectangular mesh: dim2_spline_grid()


of bicubic splines: dim2_spline_derivm()

of polynomials: dim1_cheb_deriv()


at a point

of cubic splines: dim1_spline_eval()

of cubic splines and derivatives: dim1_spline_deriv()

at vector of points

of bicubic splines at vector of points: dim2_spline_evalv()

of scattered fit: dim2_spline_ts_evalv()

of cubic splines and optionally derivatives: dim1_spline_deriv_vector()

of polynomials

in one variable: dim1_cheb_eval2()

in one variable (simple interface): dim1_cheb_eval()

in two variables: dim2_cheb_eval()

of rational functions: pade_eval()

on mesh

of bicubic splines: dim2_spline_evalm()

of scattered fit: dim2_spline_ts_evalm()


of cubic splines (definite integral): dim1_spline_integ()

of polynomials: dim1_cheb_integ()


with constraints: glinc_l1sol()

with general linear function: glin_l1sol()

Least squares curve fit

with cubic splines: dim1_spline_knots()

with polynomials

arbitrary data points: dim1_cheb_arb()

selected data points: dim1_cheb_glp()

with constraints: dim1_cheb_con()

Least squares surface fit

with bicubic splines: dim2_spline_panel()

with polynomials: dim2_cheb_lines()

Minimax space fit

with general linear function: glin_linf()

with polynomials in one variable: dim1_minimax_polynomial()

Padé approximants: pade_app()

Scattered data fit

bicubic spline: dim2_spline_sctr()

spline: dim2_spline_ts_sctr()

Service functions

general option getting function: opt_get()

general option setting function: opt_set()

Sorting: dim2_spline_sort()

For full information please refer to the NAG Library document


Example for

Minimax curve fit by polynomials.

>>> main() Python Example Results.
Minimax curve fit by polynomials.
Coefficients of degree-5 polynomial fit of exp:
(1.0000e+00, 1.0001e+00, 4.9909e-01, 1.7042e-01, 3.4784e-02, 1.3909e-02)[source]

Example for

Spline approximation to a set of scattered data using a two-stage approximation method.

>>> main() Python Example Results.
Fit a spline for the Franke function.
Spline value at (0.00, 0.00) is 0.76.