Ignore:
Timestamp:
10/16/06 19:43:37 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MMath.cc

    r8029 r8073  
    554554// An exact solution of the cubic polynomial equation:
    555555//
    556 // x^3 + a*x^2 + b*x + c = 0
     556//   x^3 + a*x^2 + b*x + c = 0
    557557//
    558558// was first published by Gerolamo Cardano (1501-1576) in his treatise,
     
    563563// discovered. Zeno source code
    564564//
     565// http://home.att.net/~srschmitt/cubizen.html
     566//
    565567// % compute real or complex roots of cubic polynomial
    566568// function cubic( var z1, z2, z3 : real, a, b, c : real ) : real
     
    598600// end function
    599601//
     602// see also http://en.wikipedia.org/wiki/Cubic_equation
     603//
    600604Int_t MMath::SolvePol3(Double_t a, Double_t b, Double_t c,
    601605                       Double_t &x1, Double_t &x2, Double_t &x3)
    602606{
     607    //    Double_t coeff[4] = { 1, a, b, c };
     608    //    return TMath::RootsCubic(coeff, x1, x2, x3) ? 1 : 3;
     609
    603610    const Double_t Q = (a*a - 3*b)/9;
    604611    const Double_t R = (9*b*a - 27*c - 2*a*a*a)/54;
     
    607614    // ----- The single-real / duplicate-roots solution -----
    608615
     616    // D<0:  three real roots
     617    // D>0:  one real root
     618    // D==0: maximum two real roots (two identical roots)
     619
     620    // R==0: only one unique root
     621    // R!=0: two roots
     622
    609623    if (D==0)
    610624    {
    611625        const Double_t r = MMath::Sqrt3(R);
    612626
    613         x1 = 2*r - a/3.;               // real root
    614         x2 =   r - a/3.;               // real root
    615 
     627        x1 = r - a/3.;               // real root
     628        if (R==0)
     629            return 1;
     630
     631        x2 = 2*r - a/3.;               // real root
    616632        return 2;
    617633    }
Note: See TracChangeset for help on using the changeset viewer.