FPrime - TestTolerance grows without bound. (e.g. somewhere in the magnitude of 10^32 in 100 iterations).
You know the derivative can just be calculated in constant time for a given polynomial, right?
(ax^2 + bx + c --->
2ax + b).
Forget about the code for a second. Can you please explain the method or algorithm you are trying to implement, in words?
For example, if my input is 1x^2 + 1x + 1, at x = 1, what process do you expect to be happening? What should the answer be after 1 iteration, for example?
If we pretend that we can't just calculate the result in constant time, what I would do is the following:
Calculate:
-
x1 = x - delta,
-
x2 = x + delta,
-
y1 = f(x - delta),
-
y2 = f(x + delta),
- calculate
slope = (y2 - y1) / (x2 - x1),
- and halve delta each time until old_slope ~= new_slope.
It's possible for this to have rounding errors due to the small denominator, though. Perhaps there's a better algorithm for this that is escaping my memory! I'm not sure, but I can probably help if you tell me what's supposed to be happening in your code.
Edit: Apparently there are ways to mitigate the rounding error with my method, see:
https://en.wikipedia.org/wiki/Numerical_differentiation
"Practical considerations using floating point arithmetic"