Re: revised quadratic.fs
- From: Krishna Myneni <krishna.myneni@xxxxxxxxxxx>
- Date: Thu, 20 Aug 2009 04:04:57 -0700 (PDT)
On Aug 20, 12:08 am, m...@xxxxxx (Marcel Hendrix) wrote:
Krishna Myneni <krishna.myn...@xxxxxxxxxxx> writes Re: revised quadratic.fs
On Aug 18, 7:28 am, Krishna Myneni <krishna.myn...@xxxxxxxxxxx> wrote:[..]
I discovered that our algorithm
fails for the simple case of b = 0, c = 0:
All these changes do not seem to have led to improved robustness.
The recent changes, made to address a numerical problem with accuracy
in extreme cases, actually decreased the robustness of the algorithm.
IMO, Numerical Recipes overstates their case for the "correct" way to
solve the quadratic formula. The loss of accuracy with the ordinary
quadratic formula seems to be manifested only for extreme, low-
probability, cases. Nevertheless, since we are trying to make a
general purpose library module, we should try to take these cases into
account.
The problem for b=0, c=0 can be fixed in a simple way, e.g.
( F: a b c -- z1 z2 )
f2dup f0= >r f0= r> and IF fdrop f2drop 0e 0e 0e 0e EXIT THEN
With respect to the ordering of the roots, the complex-conjugate case
is known. For the real roots, I'm inclined to just add the extra code
necessary to ensure a predictable ordering.
This is something I did in 2002 on the basis of one of your first versions.
It offers a test that could be made exhaustive.
The algorithm does not like a = 0.
After reflecting a bit more on the a = 0 case, I'm convinced that the
decision to make this a case of invalid input for solve_quadratic is
the correct one, for the following reason: A quadratic equation can
have two degenerate real roots when the discriminant is exactly zero,
as with the test case,
t{ 9e 12e 4e solve_quadratic -> -2/3 0e
-2/3 0e zz}t
Now, if the a = 0 case was permitted as valid input to
solve_quadratic, the routine would have to return two equal real
roots, to be consistent with the expected number of values on the
stack/fpstack. The calling word wouldn't be able to tell, without
further checking, whether the two equal, real roots, came about from
the solution of a linear equation, or from a quadratic equation that
happened to give degenerate roots. Such a distinction could be very
important in an application, in which case the calling word must check
for a=0 anyway.
Regarding your test code below, a consistency-check to ensure the
returned roots solve the equation is a good idea. Perhaps a word which
does this should be added to allow the user to perform the consistency
check, if he/she is extra paranoid (and when it comes to numerics, one
should be).
Krishna
.
- References:
- Re: revised quadratic.fs
- From: Krishna Myneni
- Re: revised quadratic.fs
- From: Marcel Hendrix
- Re: revised quadratic.fs
- Prev by Date: Re: revised quadratic.fs
- Next by Date: Re: revised quadratic.fs
- Previous by thread: Re: revised quadratic.fs
- Next by thread: Re: revised quadratic.fs
- Index(es):
Relevant Pages
|
Loading