Posts

Showing posts from August, 2025

Multiple Graphs for Comparison - plus ggplot2

 At this point, I have decided to use the ggplot2 library, rather than use the more primitive 'plot' command in the base R.  Here is the re-worked example (with_ggplot2.R) from the previous post on piecewise linear interpolation - the Wiggins Average Angle Method on the Matlab1 dataset. The next step is to extend the code to allow comparison of two methods on one dataset (multiple_plots.R) .  At this point, ChatGPT was extremely useful in debugging and tidying the code.  Here is the comparison of the two Wiggins methods on the Matlab1 dataset. This shows quite effectively the tighter fit of the Average Angle Method (in red).  Next for nostalgia we compare the two methods from the NAG Graphics Library (formerly NAG Graphical Supplement), on the peak dataset which we used in the example program in the first release of the Supplement. Finally we compare the two approaches to piecewise linear interpolation - regular and adaptive spacing.  Here is a compa...

Piecewise Linear Interpolation of Cubic Polynomial

When the NAG Graphics curve drawing routines were created, in 1979, the most common graphics device was a graph plotter. The curve was drawn as a piecewise linear approximation of the cubic polynomial.  It was useful to be able to avoid taking too many 'pieces' for the linear approximation since sending commands to the plotter took time and bandwidth.  Equally we wanted to avoid taking too few pieces since the approximation would then be poor.   We made use of work at AERE Harwell by Sid Marlow and Mike Powell, who carefully chose the number of pieces to satisfy a specified level of accuracy.  Long segments are used where the curvature is small, and shorter segments where the curvature is large.  The work was published as a Harwell report - which I once had but must have binned at some point!  The reference is: Marlow , S. and   Powell , M.J.D. (1973) “A FORTRAN subroutine for plotting a cubic spline function”. Report No. R7470, AERE   Harwel...

Wiggins Methods

At this point I decided that my R code should be tidied, with a clear modular structure, and sufficient comments added to allow the work to be understood at any later time. This having been done, I decided to explore the two methods proposed by Wiggins in 1976.  As explained in the previous post, these were entirely new to me, having been published in the seismology literature. First, a reminder of the methods.  The average slopes method in our notation gives s 3  as  s 3   = 0.5 * (m 2  + m 3 ) The average angle method is: s 3  = tan [ 0.5 * tan  -1  (m 2 ) + 0.5 * tan  -1  (m 3 ) ] The first method is as simple as could be.  The slope at a data point is estimated as the average of the slopes of the adjacent chords - so for evenly spaced data this would just be the osculatory method.  For unequally spaced data, it gives equal weight to the chords either side of a data point and this can result in perfectly good curve...