Tcl Library Source Code

Documentation
Login
EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

math::interpolate - Interpolation routines

Table Of Contents

SYNOPSIS

package require Tcl ?8.5 9?
package require struct
package require math::interpolate ?1.1.4?

::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

DESCRIPTION

This package implements several interpolation algorithms:

This document describes the procedures and explains their usage.

INCOMPATIBILITY WITH VERSION 1.0.3

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).

PROCEDURES

The interpolation package defines the following public procedures:

EXAMPLES

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

Then to estimate the values at 0.5, 1.5, 2.5 and 3.5, you can use:

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]"
}

For one-dimensional tables the first row is not used. For two-dimensional tables, the first row represents the values for the second independent variable.

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

Then to estimate the values at 0.1, 0.2, 0.3, ... 1.0, you can use:

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]"
}

to get the following output:

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

As you can see, the values at the abscissae are reproduced perfectly.

Bugs, Ideas, Feedback

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. 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.

KEYWORDS

interpolation, math, spatial interpolation

CATEGORY

Mathematics

COPYRIGHT

Copyright © 2004 Arjen Markus
Copyright © 2004 Kevn B. Kenny