ECN No Name Newsletter: September, 1990

The ECN No Name Newsletter is no longer being published. This is an archived issue.

[previous article] [next article]

Smoothing Grap Output With Spline

Tom Davey

Have you ever wished that the straight lines between your sparse data points could be "smoothed" to more clearly represent your results? Well, if you use grap you can integrate the shell command spline to do just that. Shown below are two graphs produced by grap. The first is the output produced by the three data points provided, along with the grap text input that created it.

                           graph shown

 .G1
 frame wid 2.4
 draw solid box
 copy "orig.data"
 .G2
 ... where the file "orig.data" contains:


        0         0
        1         1
        2         8

The second graph is the smoothed grap output, along with its text input. Our general approach is first to plot the bare data points provided by the original data and then to connect them using the output from the splined data. Let's examine the command line in grap's input:

"sh X spline < orig.data > smooth.data X"

The sh X...X command tells grap to execute the shell command contained inside the two "X" delimiters (in our case, the shell command is:

"spline < orig.data > smooth.data"

The spline shell command takes sparse data points (in this case, 3) from standard input and writes to standard output a larger number (in this case, 101) of interpolated points that serve to smooth the curve between the original data points. For more information on this smoothing function, refer to the spline(1) command in ECN #110 UNIX Reference Manual.

                           graph shown

 .G1
 frame wid 2.4
 draw invis box
 copy "orig.data"
 sh X spline < orig.data > smooth.data X
 new solid
 copy "smooth.data"
 .G2
 ... where the splined file "smooth.data" contains:


        0.000000        0.000000
        0.020000        -0.009988
                     .                            .
                     .                            .
                     .                            .
        0.580000        0.002668
        0.600000        0.024000
                     .                            .
                     .                            .
                     .                            .
        1.980000        7.830012
        2.000000        8.000000

It's important to note that these data points "fabricated" by spline may not exactly fit the graph that would have resulted had more "true" data points been provided. In the example above, the data points in the file "orig.data" show the results of the function $x sup 3$ for integers from 1 to 3. Note that the second y-coordinate in the splined file is actually a negative number, causing a slight dip in the graph. In some instances, this divergence would be unacceptable. However, in many cases, the spline function can make better-looking curves for your grap output.


webmaster@ecn.purdue.edu
Last modified: Friday, 24-Oct-97 12:01:31 EST

[HTML Check] HTML