1 //static const char* sccsid = "@(#)math_BissecNewton.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
2 #include <math_BissecNewton.ixx>
3 #include <math_FunctionWithDerivative.hxx>
6 void math_BissecNewton::Perform(math_FunctionWithDerivative& F,
7 const Standard_Real Bound1,
8 const Standard_Real Bound2,
9 const Standard_Integer NbIterations)
11 Standard_Boolean GOOD;
13 Standard_Real dxold, fh, fl;
14 Standard_Real swap, temp, xh, xl;
16 GOOD = F.Values(Bound1, fl, df);
18 Done = Standard_False;
19 TheStatus = math_FunctionError;
22 GOOD = F.Values(Bound2, fh, df);
24 Done = Standard_False;
25 TheStatus = math_FunctionError;
28 // Modified by Sergey KHROMOV - Wed Jan 22 12:06:45 2003 Begin
29 Standard_Real aFTol = RealEpsilon();
31 // if(fl * fh >= 0.0) {
32 if(fl * fh > aFTol*aFTol) {
33 Done = Standard_False;
34 TheStatus = math_NotBracketed;
38 if(fl < -aFTol || (fl < aFTol && fh < -aFTol)) {
49 // Modified by Sergey KHROMOV - Wed Jan 22 12:06:49 2003 End
50 x = 0.5 * (Bound1 + Bound2);
51 dxold = fabs(Bound2 - Bound1);
53 GOOD = F.Values(x, f, df);
55 Done = Standard_False;
56 TheStatus = math_FunctionError;
59 for(j = 1; j <= NbIterations; j++) {
60 if((((x - xh) * df - f) * ((x - xl) * df - f) >= 0.0)
61 || (fabs(2.0 * f) > fabs(dxold * df))) {
82 if(IsSolutionReached(F)) {
87 GOOD = F.Values(x, f, df);
89 Done = Standard_False;
90 TheStatus = math_FunctionError;
103 Done = Standard_True;
107 TheStatus = math_TooManyIterations;
108 Done = Standard_False;
112 Standard_Boolean math_BissecNewton::IsSolutionReached
113 //(math_FunctionWithDerivative& F)
114 (math_FunctionWithDerivative& )
116 return Abs(dx) <= XTol;
120 math_BissecNewton::math_BissecNewton(math_FunctionWithDerivative& F,
121 const Standard_Real Bound1,
122 const Standard_Real Bound2,
123 const Standard_Real TolX,
124 const Standard_Integer NbIterations) {
127 Perform(F, Bound1, Bound2, NbIterations);
131 void math_BissecNewton::Dump(Standard_OStream& o) const {
133 o << "math_BissecNewton ";
135 o << " Status = Done \n";
136 o << " The Root is: " << x << endl;
137 o << " The value at this Root is: " << f << endl;
140 o << " Status = not Done \n";