File: spline.html

package info (click to toggle)
blt 2.5.3%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: buster
  • size: 24,864 kB
  • sloc: ansic: 133,724; tcl: 17,680; sh: 2,722; makefile: 799; cpp: 370
file content (160 lines) | stat: -rw-r--r-- 8,172 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
                     <!-- manual page source format generated by PolyglotMan v3.0.8+XFree86, -->
<!-- available via anonymous ftp from ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z -->

<HTML>
<HEAD>
<TITLE>spline(n) manual page</TITLE>
</HEAD>
<BODY BGCOLOR="#efefef" TEXT="black" LINK="blue" VLINK="#551A8B" ALINK="red">
<A HREF="#toc">Table of Contents</A><P>
 
<H2><A NAME="sect0" HREF="#toc0">Name</A></H2>
spline -  Fit curves with spline interpolation

<H2><A NAME="sect1" HREF="#toc1">Synopsis</A></H2>
<P>
<B>spline natural <I>x y sx sy</I></B> <P>
<B>spline quadratic <I>x y sx sy</I></B> 
<H2><A NAME="sect2" HREF="#toc2">Description</A></H2>
The
<B>spline</B> command computes a spline fitting a set of data points (x and y
vectors) and produces a vector of the interpolated images (y-coordinates)
at a given set of x-coordinates. 
<H2><A NAME="sect3" HREF="#toc3">Introduction</A></H2>
Curve fitting has many applications.
 In graphs, curve fitting can be useful for displaying curves which are
aesthetically pleasing to the eye.  Another advantage is that you can quickly
generate arbitrary points  on the curve from a small set of data points.
<P>
A spline is a device used in drafting to produce smoothed curves.  The points
of the curve, known as <I>knots</I>, are fixed and the <I>spline</I>, typically a thin
strip of wood or metal, is bent around the knots to create the smoothed
curve.  Spline interpolation is the mathematical equivalent.  The curves
between adjacent knots are piecewise functions such that the resulting
spline runs exactly through all the knots.  The order and coefficients of
the polynomial determine the "looseness" or "tightness" of the curve fit
from the line segments formed by the knots. <P>
The <B>spline</B> command performs
spline interpolation using cubic ("natural") or quadratic polynomial functions.
 It computes the spline based upon the knots, which are given as x and
y vectors.  The interpolated new points are determined by another vector
which represents the abscissas (x-coordinates) or the new points.  The ordinates
(y-coordinates) are interpolated using the spline and  written to another
vector. 
<H2><A NAME="sect4" HREF="#toc4">Example</A></H2>
Before we can use the <B>spline</B> command, we need to create two
BLT vectors which will represent the knots (x and y coordinates) of the
data that we're going to fit.  Obviously, both vectors must be the same length.
<BR>
<CODE># Create sample data of ten points. <BR>
vector x(10) y(10)<BR>
<P>
for {set i 10} {$i &gt; 0} {incr i -1} {<BR>
    set x($i-1) [expr $i*$i]<BR>
    set y($i-1) [expr sin($i*$i*$i)]<BR>
}<BR>
</CODE><P>We now have two vectors <I>x</I> and <I>y</I> representing the ten data points we're trying
to fit.  The order of the values of <I>x</I> must be monotonically increasing. 
We can use the vector's <B>sort</B> operation  to sort the vectors. <BR>
<CODE>x sort y<BR>
</CODE><P>The components of <I>x</I> are sorted in increasing order.  The components of <I>y</I>
are rearranged so that the original x,y coordinate pairings are retained.
<P>
A third vector is needed to indicate the abscissas (x-coordinates) of the
new points to be interpolated by the spline.  Like the x vector, the vector
of abscissas must be monotonically increasing.  All the abscissas must lie
between the first and last knots (x vector) forming the spline. <P>
How the
abscissas are picked is arbitrary.  But if we are going to plot the spline,
we will want to include the knots too.  Since both the quadratic and natural
splines preserve the knots (an abscissa from the x vector will always produce
the corresponding ordinate from the y vector), we can simply make the new
vector a superset of <I>x</I>. It will contain the same coordinates as <I>x</I>, but also
the abscissas of the new points we want interpolated.  A simple way is to
use the vector's <B>populate</B> operation. <BR>
<CODE>x populate sx 10<BR>
</CODE><P>This creates a new vector <I>sx</I>.  It contains the abscissas of <I>x</I>, but in addition
<I>sx</I> will have ten evenly distributed values between each abscissa.  You can
interpolate any points you wish, simply by setting the vector values. <P>
Finally,
we generate the ordinates (the images of the spline) using the <B>spline</B> command.
 The ordinates are stored in a fourth vector. <BR>
<CODE>spline natural x y sx sy<BR>
</CODE><P>This creates a new vector <I>sy</I>.  It will have the same length as <I>sx</I>.  The vectors
<I>sx</I> and <I>sy</I> represent the smoothed curve which we can now plot. <BR>
<CODE>graph .graph<BR>
.graph element create original -x x -y x -color blue<BR>
.graph element create spline -x sx -y sy -color red<BR>
table . .graph<BR>
</CODE><P>The <B>natural</B> operation employs a cubic interpolant when forming the spline.
 In terms of the draftsmen's spline, a <I>natural spline</I> requires the least
amount of energy to bend the spline (strip of wood), while still passing
through each knot.  In mathematical terms, the second derivatives of the
first and last points are zero. <P>
Alternatively, you can generate a spline
using the <B>quadratic</B> operation.  Quadratic interpolation produces a spline
which follows  the line segments of the data points much more closely. 
 <BR>
<CODE>spline quadratic x y sx sy <BR>

<H2><A NAME="sect5" HREF="#toc5"></CODE><P>Operations</A></H2>

<DL>

<DT><B>spline natural <I>x y sx sy</I></B>  </DT>
<DD>Computes a cubic spline from the data
points represented by the vectors <I>x</I> and <I>y</I> and interpolates new points using
vector <I>sx</I> as the x-coordinates.  The resulting y-coordinates are written to
a new vector <I>sy</I>. The vectors <I>x</I> and <I>y</I> must be the same length and contain
at least three components.  The order of the components of <I>x</I> must be monotonically
increasing. <I>Sx</I> is the vector containing the x-coordinates of the points to
be interpolated.  No component of <I>sx</I> can be less than first component of
<I>x</I> or greater than the last component.  The order of the components of <I>sx</I>
must be monotonically increasing. <I>Sy</I> is the name of the vector where the
calculated y-coordinates will be stored.  If <I>sy</I> does not already exist, a
new vector will be created. </DD>

<DT><B>spline quadratic <I>x y sx sy</I></B>  </DT>
<DD>Computes a quadratic
spline from the data points represented by the vectors <I>x</I> and <I>y</I> and interpolates
new points using vector <I>sx</I> as the x-coordinates.  The resulting y-coordinates
are written to a new vector <I>sy</I>.  The vectors <I>x</I> and <I>y</I> must be the same length
and contain at least three components.  The order of the components of <I>x</I>
must be monotonically increasing. <I>Sx</I> is the vector containing the x-coordinates
of the points to be interpolated. No component of <I>sx</I> can be less than first
component of <I>x</I> or greater than the last component.  The order of the components
of <I>sx</I> must be monotonically increasing.  <I>Sy</I> is the name of the vector where
the calculated y-coordinates are stored.  If <I>sy</I> does not already exist, a
new vector will be created. </DD>
</DL>

<H2><A NAME="sect6" HREF="#toc6">References</A></H2>
<BR>
<PRE>
Numerical Analysis
by R. Burden, J. Faires and A. Reynolds.<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;
Prindle, Weber &amp; Schmidt, 1981, pp. 112

Shape Preserving Quadratic Splines 
by D.F.Mcallister &amp; J.A.Roulier
Coded by S.L.Dodd &amp; M.Roulier N.C.State University.

</PRE>The original code for the quadratic spline can be found in TOMS #574. 
<H2><A NAME="sect7" HREF="#toc7">Keywords</A></H2>
spline,
vector, graph <P>
 <P>

<HR><P>
<A NAME="toc"><B>Table of Contents</B></A><P>
<UL>
<LI><A NAME="toc0" HREF="#sect0">Name</A></LI>
<LI><A NAME="toc1" HREF="#sect1">Synopsis</A></LI>
<LI><A NAME="toc2" HREF="#sect2">Description</A></LI>
<LI><A NAME="toc3" HREF="#sect3">Introduction</A></LI>
<LI><A NAME="toc4" HREF="#sect4">Example</A></LI>
<LI><A NAME="toc5" HREF="#sect5">Operations</A></LI>
<LI><A NAME="toc6" HREF="#sect6">References</A></LI>
<LI><A NAME="toc7" HREF="#sect7">Keywords</A></LI>
</UL>
</BODY></HTML>