| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
<HTML> |
| 5 |
<HEAD> |
| 6 |
<TITLE>spline(n) manual page</TITLE> |
| 7 |
</HEAD> |
| 8 |
<BODY BGCOLOR="#efefef" TEXT="black" LINK="blue" VLINK="#551A8B" ALINK="red"> |
| 9 |
<A HREF="#toc">Table of Contents</A><P> |
| 10 |
|
| 11 |
<H2><A NAME="sect0" HREF="#toc0">Name</A></H2> |
| 12 |
spline - Fit curves with spline interpolation |
| 13 |
|
| 14 |
<H2><A NAME="sect1" HREF="#toc1">Synopsis</A></H2> |
| 15 |
<P> |
| 16 |
<B>spline natural <I>x y sx sy</I></B> <P> |
| 17 |
<B>spline quadratic <I>x y sx sy</I></B> |
| 18 |
<H2><A NAME="sect2" HREF="#toc2">Description</A></H2> |
| 19 |
The |
| 20 |
<B>spline</B> command computes a spline fitting a set of data points (x and y |
| 21 |
vectors) and produces a vector of the interpolated images (y-coordinates) |
| 22 |
at a given set of x-coordinates. |
| 23 |
<H2><A NAME="sect3" HREF="#toc3">Introduction</A></H2> |
| 24 |
Curve fitting has many applications. |
| 25 |
In graphs, curve fitting can be useful for displaying curves which are |
| 26 |
aesthetically pleasing to the eye. Another advantage is that you can quickly |
| 27 |
generate arbitrary points on the curve from a small set of data points. |
| 28 |
<P> |
| 29 |
A spline is a device used in drafting to produce smoothed curves. The points |
| 30 |
of the curve, known as <I>knots</I>, are fixed and the <I>spline</I>, typically a thin |
| 31 |
strip of wood or metal, is bent around the knots to create the smoothed |
| 32 |
curve. Spline interpolation is the mathematical equivalent. The curves |
| 33 |
between adjacent knots are piecewise functions such that the resulting |
| 34 |
spline runs exactly through all the knots. The order and coefficients of |
| •35 |
the polynomial determine the "looseness" or "tightness" of the curve fit |
| 36 |
from the line segments formed by the knots. <P> |
| 37 |
The <B>spline</B> command performs |
| 38 |
spline interpolation using cubic ("natural") or quadratic polynomial functions. |
| 39 |
It computes the spline based upon the knots, which are given as x and |
| 40 |
y vectors. The interpolated new points are determined by another vector |
| 41 |
which represents the abscissas (x-coordinates) or the new points. The ordinates |
| 42 |
(y-coordinates) are interpolated using the spline and written to another |
| 43 |
vector. |
| 44 |
<H2><A NAME="sect4" HREF="#toc4">Example</A></H2> |
| 45 |
Before we can use the <B>spline</B> command, we need to create two |
| 46 |
BLT vectors which will represent the knots (x and y coordinates) of the |
| 47 |
data that we're going to fit. Obviously, both vectors must be the same length. |
| 48 |
<BR> |
| 49 |
<CODE># Create sample data of ten points. <BR> |
| 50 |
vector x(10) y(10)<BR> |
| 51 |
<P> |
| 52 |
for {set i 10} {$i > 0} {incr i -1} {<BR> |
| 53 |
set x($i-1) [expr $i*$i]<BR> |
| 54 |
set y($i-1) [expr sin($i*$i*$i)]<BR> |
| 55 |
}<BR> |
| 56 |
</CODE><P>We now have two vectors <I>x</I> and <I>y</I> representing the ten data points we're trying |
| 57 |
to fit. The order of the values of <I>x</I> must be monotonically increasing. |
| 58 |
We can use the vector's <B>sort</B> operation to sort the vectors. <BR> |
| 59 |
<CODE>x sort y<BR> |
| 60 |
</CODE><P>The components of <I>x</I> are sorted in increasing order. The components of <I>y</I> |
| 61 |
are rearranged so that the original x,y coordinate pairings are retained. |
| 62 |
<P> |
| 63 |
A third vector is needed to indicate the abscissas (x-coordinates) of the |
| 64 |
new points to be interpolated by the spline. Like the x vector, the vector |
| 65 |
of abscissas must be monotonically increasing. All the abscissas must lie |
| 66 |
between the first and last knots (x vector) forming the spline. <P> |
| 67 |
How the |
| 68 |
abscissas are picked is arbitrary. But if we are going to plot the spline, |
| 69 |
we will want to include the knots too. Since both the quadratic and natural |
| 70 |
splines preserve the knots (an abscissa from the x vector will always produce |
| 71 |
the corresponding ordinate from the y vector), we can simply make the new |
| 72 |
vector a superset of <I>x</I>. It will contain the same coordinates as <I>x</I>, but also |
| 73 |
the abscissas of the new points we want interpolated. A simple way is to |
| 74 |
use the vector's <B>populate</B> operation. <BR> |
| 75 |
<CODE>x populate sx 10<BR> |
| 76 |
</CODE><P>This creates a new vector <I>sx</I>. It contains the abscissas of <I>x</I>, but in addition |
| 77 |
<I>sx</I> will have ten evenly distributed values between each abscissa. You can |
| 78 |
interpolate any points you wish, simply by setting the vector values. <P> |
| 79 |
Finally, |
| 80 |
we generate the ordinates (the images of the spline) using the <B>spline</B> command. |
| 81 |
The ordinates are stored in a fourth vector. <BR> |
| 82 |
<CODE>spline natural x y sx sy<BR> |
| 83 |
</CODE><P>This creates a new vector <I>sy</I>. It will have the same length as <I>sx</I>. The vectors |
| 84 |
<I>sx</I> and <I>sy</I> represent the smoothed curve which we can now plot. <BR> |
| 85 |
<CODE>graph .graph<BR> |
| 86 |
.graph element create original -x x -y x -color blue<BR> |
| 87 |
.graph element create spline -x sx -y sy -color red<BR> |
| 88 |
table . .graph<BR> |
| 89 |
</CODE><P>The <B>natural</B> operation employs a cubic interpolant when forming the spline. |
| •90 |
In terms of the draftsmen's spline, a <I>natural spline</I> requires the least |
| 91 |
amount of energy to bend the spline (strip of wood), while still passing |
| 92 |
through each knot. In mathematical terms, the second derivatives of the |
| 93 |
first and last points are zero. <P> |
| 94 |
Alternatively, you can generate a spline |
| 95 |
using the <B>quadratic</B> operation. Quadratic interpolation produces a spline |
| 96 |
which follows the line segments of the data points much more closely. |
| 97 |
<BR> |
| 98 |
<CODE>spline quadratic x y sx sy <BR> |
| 99 |
|
| 100 |
<H2><A NAME="sect5" HREF="#toc5"></CODE><P>Operations</A></H2> |
| 101 |
|
| 102 |
<DL> |
| 103 |
|
| 104 |
<DT><B>spline natural <I>x y sx sy</I></B> </DT> |
| 105 |
<DD>Computes a cubic spline from the data |
| 106 |
points represented by the vectors <I>x</I> and <I>y</I> and interpolates new points using |
| 107 |
vector <I>sx</I> as the x-coordinates. The resulting y-coordinates are written to |
| 108 |
a new vector <I>sy</I>. The vectors <I>x</I> and <I>y</I> must be the same length and contain |
| 109 |
at least three components. The order of the components of <I>x</I> must be monotonically |
| 110 |
increasing. <I>Sx</I> is the vector containing the x-coordinates of the points to |
| 111 |
be interpolated. No component of <I>sx</I> can be less than first component of |
| 112 |
<I>x</I> or greater than the last component. The order of the components of <I>sx</I> |
| 113 |
must be monotonically increasing. <I>Sy</I> is the name of the vector where the |
| 114 |
calculated y-coordinates will be stored. If <I>sy</I> does not already exist, a |
| 115 |
new vector will be created. </DD> |
| 116 |
|
| 117 |
<DT><B>spline quadratic <I>x y sx sy</I></B> </DT> |
| 118 |
<DD>Computes a quadratic |
| 119 |
spline from the data points represented by the vectors <I>x</I> and <I>y</I> and interpolates |
| 120 |
new points using vector <I>sx</I> as the x-coordinates. The resulting y-coordinates |
| 121 |
are written to a new vector <I>sy</I>. The vectors <I>x</I> and <I>y</I> must be the same length |
| 122 |
and contain at least three components. The order of the components of <I>x</I> |
| 123 |
must be monotonically increasing. <I>Sx</I> is the vector containing the x-coordinates |
| 124 |
of the points to be interpolated. No component of <I>sx</I> can be less than first |
| 125 |
component of <I>x</I> or greater than the last component. The order of the components |
| 126 |
of <I>sx</I> must be monotonically increasing. <I>Sy</I> is the name of the vector where |
| 127 |
the calculated y-coordinates are stored. If <I>sy</I> does not already exist, a |
| 128 |
new vector will be created. </DD> |
| 129 |
</DL> |
| 130 |
|
| 131 |
<H2><A NAME="sect6" HREF="#toc6">References</A></H2> |
| 132 |
<BR> |
| 133 |
<PRE> |
| 134 |
Numerical Analysis |
| 135 |
by R. Burden, J. Faires and A. Reynolds.<tt> </tt> <tt> </tt> |
| 136 |
Prindle, Weber & Schmidt, 1981, pp. 112 |
| 137 |
|
| 138 |
Shape Preserving Quadratic Splines |
| 139 |
by D.F.Mcallister & J.A.Roulier |
| 140 |
Coded by S.L.Dodd & M.Roulier N.C.State University. |
| 141 |
|
| •142 |
</PRE>The original code for the quadratic spline can be found in TOMS #574. |
| 143 |
<H2><A NAME="sect7" HREF="#toc7">Keywords</A></H2> |
| 144 |
spline, |
| 145 |
vector, graph <P> |
| 146 |
<P> |
| 147 |
|
| 148 |
<HR><P> |
| 149 |
<A NAME="toc"><B>Table of Contents</B></A><P> |
| 150 |
<UL> |
| 151 |
<LI><A NAME="toc0" HREF="#sect0">Name</A></LI> |
| 152 |
<LI><A NAME="toc1" HREF="#sect1">Synopsis</A></LI> |
| 153 |
<LI><A NAME="toc2" HREF="#sect2">Description</A></LI> |
| 154 |
<LI><A NAME="toc3" HREF="#sect3">Introduction</A></LI> |
| 155 |
<LI><A NAME="toc4" HREF="#sect4">Example</A></LI> |
| 156 |
<LI><A NAME="toc5" HREF="#sect5">Operations</A></LI> |
| 157 |
<LI><A NAME="toc6" HREF="#sect6">References</A></LI> |
| 158 |
<LI><A NAME="toc7" HREF="#sect7">Keywords</A></LI> |
| 159 |
</UL> |
| 160 |
</BODY></HTML> |