# Spline1

by
Mark Fischler
—
last modified
2006-06-28 15:46

Contributors:
Mark Fischler

C++

Code Fragment

Fitting

Classes representing cubic splines in one variable and grids with mixes of uniform and non-uniform regions.

Mark Fischler

A Spline1 is an approximation of a user-supplied function, obtained by sampling on a specified grid. The approximation uses a cubic spline, which is accurate to fourth order in the grid spacing. This can be useful as a means of providing rapid evaluation for many invocations of of what would otherwise be an expensive function, at a cost of some fixed number evaluations at initialization time.

To use a Spline1, first form a Grid1 to specify the points to be sampled, in one of two ways:

Grid1 ( double lowerLimit, // A grid with uniform spacing double upperLimit, // on the HALF-OPEN interval [a,b) unsigned int nGridPoints ); // Grid1(0, 100, 100) would be// {0, 1, 2, 3, ..., 98, 99} or

templateiter can be anything with the usual iterator semantics dereferncing to a type convertible to double; typically, one would doinline Grid1 ( iter begin, iter end ); // A grid with non-uniform spacing

std::vectorThen supply that grid and your desired function to form the Spline1:myPoints; Grid1 g ( myPoints.begin(), myPoints.end() );

double f (double x) { return horribly_complicated_calculation(x); } Spine1 f_approx ( f, g );The spline is used as if it were an ordinary function:

double myValue = f_approx (4.2);The spline setup involves sampling the function at N points (where N is however many points are in the grid), plus O(N) simple arithmetic steps. Invoking the spline to get a value involves about 20 arithmetic operations, pkus in the case of a non-uniform grid a binary search of the grid.

mf@fnal.gov

- Uploaded file by File Uploader Account — last modified 2006-06-26 16:47
- TAR file, -- windows users can use http://gnuwin32.sourceforge.net/packages/tar.htm
- Uploaded document by File Uploader Account — last modified 2006-06-26 16:47
- Documentation file