Hello,
Thanks for all the helpful hints concerning solving (the not-so-trivial)
quadratic equations. Ted recommended a section of Numerical Recipies
which is helpful. I guess what I learned is that one should be more
careful and tune the solver to the problem at hand. In my application,
we know the correct root of the two to select. The values of the roots
need not be soo accurate, but the collision times of different pairs of
spheres are used as keys in a heap, so their ordering is important. If a
collision time is very large, its exact value is irrelevant since that
collision will never happen. Collision times close to zero on the other
hand need to be resolved accurately. The worst offense is misclassifying
a root as "collision will not happen" if it does, as then a collision is
missed and the simulation goes to segfaults etc. I will use your
suggestions to write a routine which is tuned for this kind of situation...
One question/comment though:
Van Snyder wrote:
>If A == 0.0 can occur
>in your physical problem, you should have a special branch for it.
>
This was the original purpose of my questions. How should I test if
A==0.0. Should I compare to EPSILON, TINY, to the magnitude of B or C,
etc? I can get the mathematics right (yes Van, I can solve quadratic
equations :-), but the mathematical branching is not necessarily the one
to use numerically...
Thanks,
Aleksandar
|