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 Harwell.

The key point is the error formula for linear approximation.  Suppose the function f(x) is approximated over the interval [x0, x1] by a straight line joining (x0, f(x0)) to (x1, f(x1)).  The error, E, in this approximation is bounded above by Uh2/8, where h = (x1 - x0) and U = max | f''(x) | for x in [x0, x1].

Here the function f is the special case of a cubic polynomial, c(x) - so 

f(x) = c(x) = c0 + c1*(x-x0) +c2*(x-x0)2/2 + c3*(x-x0)3/6

where c0 = c(x0), c1 = c'(x0), c2 = c''(x0) and c3 = c'''(x0).

Thus for the special case of a cubic, we have:

U = max |f''(x)| = max | c''(x) | for x in [x0, x1]

Since c''(x) = c2 + h*c3, a linear function of h, the maximum of | c''(x) | will occur at an end-point of the interval [x0, x1].  Thus

U = max( | c2 |, | c2 + h*c3 | ).  

Now suppose the maximum error we allow in the piecewise linear approximation of the cubic is Δ y.  Then the required number of pieces, M, must satisfy:

U (h/M)2 / 8 < Δ y

ie M2 > U h2 / (8 * Δ y).

To see the effect of this choice, I incorporated this into the code which draws the piecewise linear approximation of the cubic polynomial, and noted the number of line segments used in each interval.  The tolerance, Δ y , was set to 0.001 times the y-range.  This is probably much tighter than would be needed in practice.  Running this code on the 'Matlab1' dataset, we can compare the number of segments with the naive approach I had been using up to now, where I subdivided each interval into 10 segments.  

Here is the plot, followed by a table with the comparison:





Interval Equal Spacing Adaptive Spacing
1 – 2 10 1
2 - 3 10 8
3 - 4 10 11
4 - 5 10 16
5 – 5.5 10 13
5.5 - 7 10 15
7 - 8 10 15
8 - 9 10 10
9 – 9.5 10 7
9.5 – 10 10 1
TOTAL 100 97

It is clear that the adaptive method is using approximately the same total number of straight line pieces, but these are concentrated in the intervals where the curve is changing the greatest.  In particular, the greatest number of pieces is in the interval between x=4 and x=5, which is where the curvature is greatest.

x3 y3 m2 s3 w2 a2

Comments

Popular posts from this blog

Wiggins Methods

Curve Drawing Over the Years