Potential crash in spline?


paolog
01-25-2006, 08:53 AM
The second derivatives are computed as a recurrence relation in the code for spline(), with the first (actually the last, as they are computed in reverse order) of these computed as:

second_derivative[n - 1] = (un - qn * u[n - 2]) / (qn * second_derivative[n - 2] + 1.0));

where qn is set to be 0.5 (unless the derivative at the top end of the interval is huge)

Now, if the denominator is exactly zero, then we have a division by zero. There are two possible scenarios:

* This can happen, and isn't handled by the code, causing any program that uses the algorithm as it stands to crash or produce spurious results;
* This can never happen

Either way, I am surprised that there isn't a comment in the text explaining this. It seems likely that the denominator can easily be zero - all that is required is for second_derivative[n - 2] to be equal to -2. If the denominator can be zero, why isn't there any code to handle it in the function?

I am testing for this in my code but have no idea how I should be handling the situation if it arises other than to give an error message and abort. Under what circumstances could a division by zero happen, if at all, and what is the appropriate course of action to take if it does?

Thanks.

paolog
08-02-2006, 08:45 AM
Six months since posting, and still no reply.

Can I assume that this is an oversight that will be fixed in future editions of the book? Is it corrected in the code (which I do not have and do not intend to download)?

Due to the lack of feedback, I am now using someone else's code for spline-fitting, which is a great shame. :(