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?
-
Is there a specific reason to use Newton's method? You could just explicitly find the roots of each cubic segment. – Christoph Mar 11 '14 at 08:08
-
Our assignment dictates that we use Newton's method – David Bradston Mar 11 '14 at 08:09
2 Answers
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}$.
- 43,483
- 3
- 61
- 122
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.
- 260,315
-
-
@littleO. For sure, this is perfectly feasible but requires extra work. The OP has the spline. Being lazy is not a sin ! – Claude Leibovici Mar 11 '14 at 08:52