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

EXAMPLES

220       TODO Example of using the cubic splines:
221
222       Suppose the following values are given:
223
224           x       y
225         0.1     1.0
226         0.3     2.1
227         0.4     2.2
228         0.8     4.11
229         1.0     4.12
230
231       Then to estimate the values at 0.1, 0.2, 0.3, ... 1.0, you can use:
232
233          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}]
234          foreach x {0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0} {
235             puts "$x: [::math::interpolate::interp-cubic-splines $coeffs $x]"
236          }
237
238       to get the following output:
239
240       0.1: 1.0
241       0.2: 1.68044117647
242       0.3: 2.1
243       0.4: 2.2
244       0.5: 3.11221507353
245       0.6: 4.25242647059
246       0.7: 5.41804227941
247       0.8: 4.11
248       0.9: 3.95675857843
249       1.0: 4.12
250
251       As you can see, the values at the abscissae are reproduced perfectly.
252

BUGS, IDEAS, FEEDBACK

254       This document, and the package it describes, will  undoubtedly  contain
255       bugs  and  other  problems.  Please report such in the category math ::
256       interpolate    of    the    Tcllib    SF    Trackers    [http://source
257       forge.net/tracker/?group_id=12883].   Please  also report any ideas for
258       enhancements you may have for either package and/or documentation.
259

KEYWORDS

261       interpolation, math, spatial interpolation
262
264       Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
265       Copyright (c) 2004 Kevn B. Kenny <kennykb@users.sourceforge.net>
266
267
268
269
270math                                 1.0.2                math::interpolate(n)
Impressum