0022904: Clean up sccsid variables
[occt.git] / src / math / math_NewtonFunctionRoot.cxx
CommitLineData
7fd59977 1#include <math_NewtonFunctionRoot.ixx>
2#include <math_FunctionWithDerivative.hxx>
3
4
5math_NewtonFunctionRoot::math_NewtonFunctionRoot (math_FunctionWithDerivative& F,
6 const Standard_Real Guess,
7 const Standard_Real EpsX ,
8 const Standard_Real EpsF ,
9 const Standard_Real A,
10 const Standard_Real B,
11 const Standard_Integer NbIterations ){
12 EpsilonX = EpsX;
13 EpsilonF = EpsF;
14 Binf = A;
15 Bsup = B;
16 Itermax = NbIterations;
17 Done = Standard_False;
18 X = RealLast();
19 DFx = 0;
20 Fx = RealLast();
21 It = 0;
22 Perform(F, Guess);
23}
24
25
26math_NewtonFunctionRoot::math_NewtonFunctionRoot (const Standard_Real A ,
27 const Standard_Real B,
28 const Standard_Real EpsX ,
29 const Standard_Real EpsF ,
30 const Standard_Integer NbIterations ){
31
32 Binf = A;
33 Bsup = B;
34 EpsilonX = EpsX;
35 EpsilonF = EpsF;
36 Itermax = NbIterations;
37 Done = Standard_False;
38 X = RealLast();
39 DFx = 0;
40 Fx = RealLast();
41 It = 0;
42}
43
44
45math_NewtonFunctionRoot::math_NewtonFunctionRoot (math_FunctionWithDerivative& F,
46 const Standard_Real Guess,
47 const Standard_Real EpsX ,
48 const Standard_Real EpsF ,
49 const Standard_Integer NbIterations ){
50 EpsilonX = EpsX;
51 EpsilonF = EpsF;
52 Itermax = NbIterations;
53 Binf = RealFirst();
54 Bsup = RealLast();
55 Done = Standard_False;
56 X = RealLast();
57 DFx = 0;
58 Fx = RealLast();
59 It = 0;
60 Perform(F, Guess);
61}
62
63
64void math_NewtonFunctionRoot::Perform(math_FunctionWithDerivative& F,
65 const Standard_Real Guess) {
66
67 Standard_Real Dx;
68 Standard_Boolean Ok;
69 Standard_Real AA, BB;
70
71 //--------------------------------------------------
72 //-- lbr le 12 Nov 97
73 //-- la meilleure estimation n est pas sauvee et on
74 //-- renvoie une solution plus fausse que Guess
75 Standard_Real BestX=X,BestFx=RealLast();
76 //--
77
78 if ( Binf < Bsup) {
79 AA = Binf;
80 BB = Bsup;
81 }
82 else {
83 AA = Bsup;
84 BB = Binf;
85 }
86
87 Dx = RealLast();
88 Fx = RealLast();
89 X = Guess;
90 It = 1;
91 while ( (It <= Itermax) && ( (Abs(Dx) > EpsilonX) ||
92 (Abs(Fx) > EpsilonF) ) ) {
93 Ok = F.Values(X,Fx,DFx);
94
95 Standard_Real AbsFx = Fx; if(AbsFx<0) AbsFx=-AbsFx;
96 if(AbsFx<BestFx) {
97 BestFx=AbsFx;
98 BestX =X;
99 }
100
101 if (Ok) {
102 if (DFx == 0.) {
103 Done = Standard_False;
104 It = Itermax + 1;
105 }
106 else {
107 Dx = Fx/DFx;
108 X -= Dx;
109 // Limitation des variations de X:
110 if (X <= AA) X = AA;
111 if (X >= BB) X = BB;
112 It++;
113 }
114 }
115 else {
116 Done = Standard_False;
117 It = Itermax + 1;
118 }
119 }
120 X = BestX;
121
122 if (It <= Itermax) {
123 Done = Standard_True;
124 }
125 else
126 {
127 Done = Standard_False;
128 }
129}
130
131
132void math_NewtonFunctionRoot::Dump(Standard_OStream& o) const {
133
134 o <<"math_NewtonFunctionRoot ";
135 if (Done) {
136 o << " Status = Done \n";
137 o << " Location found = " << X <<"\n";
138 o << " function value at this minimum = " << Fx <<"\n";
139 o << " Number of iterations = " << It <<"\n";
140 }
141 else {
142 o << "Status = not Done \n";
143 }
144}
145
146
147