1math::interpolate(n)           Tcl Math Library           math::interpolate(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       math::interpolate - Interpolation routines
9

SYNOPSIS

11       package require Tcl  ?8.4?
12
13       package require struct
14
15       package require math::interpolate  ?1.0.2?
16
17       ::math::interpolate::defineTable name colnames values
18
19       ::math::interpolate::interp-1d-table name xval
20
21       ::math::interpolate::interp-table name xval yval
22
23       ::math::interpolate::interp-linear xyvalues xval
24
25       ::math::interpolate::interp-lagrange xyvalues xval
26
27       ::math::interpolate::prepare_cubic_splines xcoord ycoord
28
29       ::math::interpolate::interp_cubic_splines coeffs x
30
31       ::math::interpolate::interp-spatial xyvalues coord
32
33       ::math::interpolate::interp-spatial-params max_search power
34
35       ::math::interpolate::neville xlist ylist x
36
37_________________________________________________________________
38

DESCRIPTION

40       This package implements several interpolation algorithms:
41
42       ·      Interpolation  into  a table (one or two independent variables),
43              this is useful for example, if the data are  static,  like  with
44              tables of statistical functions.
45
46       ·      Linear  interpolation  into  a  given  set of data (organised as
47              (x,y) pairs).
48
49       ·      Lagrange interpolation. This is mainly of theoretical  interest,
50              because  there  is no guarantee about error bounds. One possible
51              use: if you need a line or a parabola through given  points  (it
52              will calculate the values, but not return the coefficients).
53
54              A  variation  is Neville's method which has better behaviour and
55              error bounds.
56
57       ·      Spatial interpolation using  a  straightforward  distance-weight
58              method.  This  procedure allows any number of spatial dimensions
59              and any number of dependent variables.
60
61       ·      Interpolation in one dimension using cubic splines.
62
63       This document describes the procedures and explains their usage.
64

PROCEDURES

66       The interpolation package defines the following public procedures:
67
68       ::math::interpolate::defineTable name colnames values
69              Define a table with one or two independent variables  (the  dis‐
70              tinction  is  implicit  in  the data). The procedure returns the
71              name of the table - this name  is  used  whenever  you  want  to
72              interpolate  the  values.  Note:  this procedure is a convenient
73              wrapper for the  struct::matrix  procedure.  Therefore  you  can
74              access the data at any location in your program.
75
76              name string (in) Name of the table to be created
77
78              colnames list (in) List of column names
79
80              values  list  (in) List of values (the number of elements should
81              be a
82                     multiple of the number of columns. See EXAMPLES for  more
83                     information on the interpretation of the data.
84
85                     The values must be sorted with respect to the independent
86                     variable(s).
87
88
89       ::math::interpolate::interp-1d-table name xval
90              Interpolate into the one-dimensional table "name" and  return  a
91              list of values, one for each dependent column.
92
93              name string (in) Name of an existing table
94
95              xval float (in) Value of the independent row variable
96
97
98       ::math::interpolate::interp-table name xval yval
99              Interpolate into the two-dimensional table "name" and return the
100              interpolated value.
101
102              name string (in) Name of an existing table
103
104              xval float (in) Value of the independent row variable
105
106              yval float (in) Value of the independent column variable
107
108
109       ::math::interpolate::interp-linear xyvalues xval
110              Interpolate linearly into the list of x,y pairs and  return  the
111              interpolated value.
112
113              xyvalues  list  (in)  List  of  pairs of (x,y) values, sorted to
114              increasing x.
115                     They are used as the breakpoints of  a  piecewise  linear
116                     function.
117
118              xval  float (in) Value of the independent variable for which the
119              value of y
120                     must be computed.
121
122
123       ::math::interpolate::interp-lagrange xyvalues xval
124              Use the list of x,y pairs to construct the unique polynomial  of
125              lowest  degree  that  passes  through  all points and return the
126              interpolated value.
127
128              xyvalues list (in) List of pairs of (x,y) values
129
130              xval float (in) Value of the independent variable for which  the
131              value of y
132                     must be computed.
133
134
135       ::math::interpolate::prepare_cubic_splines xcoord ycoord
136              Returns   a   list   of  coefficients  for  the  second  routine
137              interp_cubic_splines to actually interpolate.
138
139              xcoord list List of x-coordinates for the value of the
140                     function to be interpolated  is  known.  The  coordinates
141                     must  be  strictly  ascending.  At least three points are
142                     required.
143
144              ycoord list List of y-coordinates (the values of the
145                     function at the given x-coordinates).
146
147
148       ::math::interpolate::interp_cubic_splines coeffs x
149              Returns the interpolated value at coordinate x. The coefficients
150              are computed by the procedure prepare_cubic_splines.
151
152              coeffs list List of coefficients as returned by
153                     prepare_cubic_splines
154
155              x float x-coordinate at which to estimate the function. Must
156                     be between the first and last x-coordinate for which val‐
157                     ues were given.
158
159
160       ::math::interpolate::interp-spatial xyvalues coord
161              Use a straightforward interpolation method with weights as func‐
162              tion  of  the inverse distance to interpolate in 2D and N-dimen‐
163              sional space
164
165              The list xyvalues is a list of lists:
166
167                  {   {x1 y1 z1 {v11 v12 v13 v14}}
168                   {x2 y2 z2 {v21 v22 v23 v24}}
169                   ...
170                  }
171
172              The last element of each inner list is either a single number or
173              a list in itself.  In the latter case the return value is a list
174              with the same number of elements.
175
176              The method is influenced by the search radius and the  power  of
177              the inverse distance
178
179              xyvalues  list  (in) List of lists, each sublist being a list of
180              coordinates and
181                     of dependent values.
182
183              coord list (in) List of coordinates for which the values must be
184              calculated
185
186
187       ::math::interpolate::interp-spatial-params max_search power
188              Set the parameters for spatial interpolation
189
190              max_search  float  (in)  Search radius (data points further than
191              this are ignored)
192
193              power integer (in) Power  for  the  distance  (either  1  or  2;
194              defaults to 2)
195
196       ::math::interpolate::neville xlist ylist x
197              Interpolates  between  the  tabulated values of a function whose
198              abscissae are xlist and whose ordinates are ylist to produce  an
199              estimate  for  the  value of the function at x.  The result is a
200              two-element list; the first element is the function's  estimated
201              value,  and  the  second is an estimate of the absolute error of
202              the result.  Neville's algorithm for polynomial interpolation is
203              used.  Note that a large table of values will use an interpolat‐
204              ing polynomial of high degree, which  is  likely  to  result  in
205              numerical instabilities; one is better off using only a few tab‐
206              ulated values near the desired abscissa.
207

EXAMPLES

209       TODO Example of using the cubic splines:
210
211       Suppose the following values are given:
212
213           x       y
214         0.1     1.0
215         0.3     2.1
216         0.4     2.2
217         0.8     4.11
218         1.0     4.12
219
220       Then to estimate the values at 0.1, 0.2, 0.3, ... 1.0, you can use:
221
222          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}]
223          foreach x {0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0} {
224             puts "$x: [::math::interpolate::interp_cubic_splines $coeffs $x]"
225          }
226
227       to get the following output:
228
229       0.1: 1.0
230       0.2: 1.68044117647
231       0.3: 2.1
232       0.4: 2.2
233       0.5: 3.11221507353
234       0.6: 4.25242647059
235       0.7: 5.41804227941
236       0.8: 4.11
237       0.9: 3.95675857843
238       1.0: 4.12
239
240       As you can see, the values at the abscissae are reproduced perfectly.
241

KEYWORDS

243       interpolation, math, spatial interpolation
244
246       Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
247       Copyright (c) 2004 Kevn B. Kenny <kennykb@users.sourceforge.net>
248
249
250
251
252math                                 1.0.2                math::interpolate(n)
Impressum