| math::interpolate(3tcl) | Tcl Math Library | math::interpolate(3tcl) |
math::interpolate - Interpolation routines
package require Tcl ?8.4?
package require struct
package require math::interpolate ?1.1?
::math::interpolate::defineTable name colnames values
::math::interpolate::interp-1d-table name xval
::math::interpolate::interp-table name xval yval
::math::interpolate::interp-linear xyvalues xval
::math::interpolate::interp-lagrange xyvalues xval
::math::interpolate::prepare-cubic-splines xcoord ycoord
::math::interpolate::interp-cubic-splines coeffs x
::math::interpolate::interp-spatial xyvalues coord
::math::interpolate::interp-spatial-params max_search power
::math::interpolate::neville xlist ylist x
This package implements several interpolation algorithms:
A variation is Neville's method which has better behaviour and error bounds.
This document describes the procedures and explains their usage.
The interpretation of the tables in the ::math::interpolate::interpolate-1d-table command has been changed to be compatible with the interpretation for 2D interpolation in the ::math::interpolate::interpolate-table command. As a consequence this version is incompatible with the previous versions of the command (1.0.x).
The interpolation package defines the following public procedures:
The values must be sorted with respect to the independent variable(s).
The list xyvalues is a list of lists:
{ {x1 y1 z1 {v11 v12 v13 v14}}
{x2 y2 z2 {v21 v22 v23 v24}}
...
}
The method is influenced by the search radius and the power of the inverse distance
Example of using one-dimensional tables:
Suppose you have several tabulated functions of one variable:
x y1 y2
0.0 0.0 0.0
1.0 1.0 1.0
2.0 4.0 8.0
3.0 9.0 27.0
4.0 16.0 64.0
set table [::math::interpolate::defineTable table1 {x y1 y2} { - 1 2
0.0 0.0 0.0
1.0 1.0 1.0
2.0 4.0 8.0
3.0 9.0 27.0
4.0 16.0 64.0}]
foreach x {0.5 1.5 2.5 3.5} {
puts "$x: [::math::interpolate::interp-1d-table $table $x]"
}
Example of using the cubic splines:
Suppose the following values are given:
x y
0.1 1.0
0.3 2.1
0.4 2.2
0.8 4.11
1.0 4.12
set coeffs [::math::interpolate::prepare-cubic-splines {0.1 0.3 0.4 0.8 1.0} {1.0 2.1 2.2 4.11 4.12}]
foreach x {0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0} {
puts "$x: [::math::interpolate::interp-cubic-splines $coeffs $x]"
}
0.1: 1.0 0.2: 1.68044117647 0.3: 2.1 0.4: 2.2 0.5: 3.11221507353 0.6: 4.25242647059 0.7: 5.41804227941 0.8: 4.11 0.9: 3.95675857843 1.0: 4.12
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category math :: interpolate of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.
interpolation, math, spatial interpolation
Mathematics
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net> Copyright (c) 2004 Kevn B. Kenny <kennykb@users.sourceforge.net>
| 1.1 | tcllib |