2

Using a Natural Cubic Spline approximation, I've generated an approximation polynomial to six points of data. Using the Cubic Spline approximation polynomial, I now need to use Newton's method to find a root of it (the spline approximation). I'm unsure of how to tweak the Newtonian algorithm to handle a piecewise defined function. Any ideas on how to do this?

2 Answers2

1

I assume you have (or can write) functions that return the value and first derivative of your spline at any given argument value. If so, you can just use Newton's method directly -- no changes are needed to handle piecewise-defined functions.

Saying this another way ...
The fact that the spline is defined piecewise is not visible to your Newton algorithm. It just calls your "black box" functions to get values and derivatives, and doesn't care how they are calculated. The "piecewise" property should be entirely hidden inside these black box functions.

If you don't have function that calculates derivatives, a cheap way to write one is by using central differencing, as suggested in Claude's answer. For central differencing with double-precision arithmetic, I'd suggest a step size of around $10^{-7}$.

bubba
  • 43,483
  • 3
  • 61
  • 122
0

Hint

The simplest way, at least in my mind, would be to numerically evaluate the derivative by one side difference or by central difference. Select a sufficiently small step size (say $\Delta x=\frac{x}{1000}$). Since your function is continuous, even if piecewise defined, this should not make any problem.