Changeset 8073 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 10/16/06 19:43:37 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MMath.cc
r8029 r8073 554 554 // An exact solution of the cubic polynomial equation: 555 555 // 556 // x^3 + a*x^2 + b*x + c = 0556 // x^3 + a*x^2 + b*x + c = 0 557 557 // 558 558 // was first published by Gerolamo Cardano (1501-1576) in his treatise, … … 563 563 // discovered. Zeno source code 564 564 // 565 // http://home.att.net/~srschmitt/cubizen.html 566 // 565 567 // % compute real or complex roots of cubic polynomial 566 568 // function cubic( var z1, z2, z3 : real, a, b, c : real ) : real … … 598 600 // end function 599 601 // 602 // see also http://en.wikipedia.org/wiki/Cubic_equation 603 // 600 604 Int_t MMath::SolvePol3(Double_t a, Double_t b, Double_t c, 601 605 Double_t &x1, Double_t &x2, Double_t &x3) 602 606 { 607 // Double_t coeff[4] = { 1, a, b, c }; 608 // return TMath::RootsCubic(coeff, x1, x2, x3) ? 1 : 3; 609 603 610 const Double_t Q = (a*a - 3*b)/9; 604 611 const Double_t R = (9*b*a - 27*c - 2*a*a*a)/54; … … 607 614 // ----- The single-real / duplicate-roots solution ----- 608 615 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 609 623 if (D==0) 610 624 { 611 625 const Double_t r = MMath::Sqrt3(R); 612 626 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 616 632 return 2; 617 633 }
Note:
See TracChangeset
for help on using the changeset viewer.