Re: revised quadratic.fs



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
.



Relevant Pages

  • Re: Difficult Set of Equations
    ... Doing this gives c as the roots of the quadratic equation: ... I missed the constant term ... Of course, there may be as many as 4 real roots for 'a', ...
    (sci.math)
  • Re: A dead subject
    ... > more like Spock, control your emotions. ... roots with the equation in any number of forms. ... all use the standard form exclusively and we don't always ...
    (sci.math)
  • Bernsetin polynomial and Sturm sequences-[possible answer]
    ... With the Bernstein polynomials, is there a simple form for the Sturm ... Then B_Nhas exactly n real roots if and only if ... the roots z_1,...,z_n of P_Nas in by using ... Sur la signe de la partie r\'eelle des racines ...
    (sci.math.research)
  • Re: revised quadratic.fs
    ... quadratic equation would have to be revisited, ... The complex number roots, returned by solve_quadratic, are ... 2e fsqrt 3e F/ fconstant sqrt/3 ...
    (comp.lang.forth)
  • Re: polynomials with real roots
    ... what do you mean by "with real roots"? ... are missing terms allowed (i.e. possible coefficients of 0 ... I stole the reference to Newton's inequality from this paper: ...
    (sci.math)

Loading