1 //static const char* sccsid = "@(#)math_NewtonFunctionSetRoot.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
4 #define No_Standard_RangeError
5 #define No_Standard_OutOfRange
6 #define No_Standard_DimensionError
9 #include <math_NewtonFunctionSetRoot.ixx>
10 #include <math_Recipes.hxx>
11 #include <math_FunctionSetWithDerivatives.hxx>
13 Standard_Boolean math_NewtonFunctionSetRoot::IsSolutionReached
14 // (math_FunctionSetWithDerivatives& F)
15 (math_FunctionSetWithDerivatives& )
18 for(Standard_Integer i = DeltaX.Lower(); i <= DeltaX.Upper(); i++) {
19 if(Abs(DeltaX(i)) > TolX(i) || Abs(FValues(i)) > TolF) return Standard_False;
25 // Constructeurs d'initialisation des champs (pour utiliser Perform)
27 math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
28 math_FunctionSetWithDerivatives& F,
29 const math_Vector& XTol,
30 const Standard_Real FTol,
31 const Standard_Integer NbIterations):
32 TolX(1, F.NbVariables()),
34 Indx(1, F.NbVariables()),
35 Scratch(1, F.NbVariables()),
36 Sol(1, F.NbVariables()),
37 DeltaX(1, F.NbVariables()),
38 FValues(1, F.NbVariables()),
39 Jacobian(1, F.NbVariables(),
43 for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
49 math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
50 math_FunctionSetWithDerivatives& F,
51 const Standard_Real FTol,
52 const Standard_Integer NbIterations):
53 TolX(1, F.NbVariables()),
55 Indx(1, F.NbVariables()),
56 Scratch(1, F.NbVariables()),
57 Sol(1, F.NbVariables()),
58 DeltaX(1, F.NbVariables()),
59 FValues(1, F.NbVariables()),
60 Jacobian(1, F.NbVariables(),
67 math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot
68 (math_FunctionSetWithDerivatives& F,
69 const math_Vector& StartingPoint,
70 const math_Vector& XTol,
71 const Standard_Real FTol,
72 const Standard_Integer NbIterations) :
74 TolX(1, F.NbVariables()),
76 Indx (1, F.NbVariables()),
77 Scratch (1, F.NbVariables()),
78 Sol (1, F.NbVariables()),
79 DeltaX (1, F.NbVariables()),
80 FValues (1, F.NbVariables()),
81 Jacobian(1, F.NbVariables(),
85 for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
88 math_Vector UFirst(1, F.NbVariables()),
89 ULast(1, F.NbVariables());
90 UFirst.Init(RealFirst());
91 ULast.Init(RealLast());
92 Perform(F, StartingPoint, UFirst, ULast);
95 math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot
96 (math_FunctionSetWithDerivatives& F,
97 const math_Vector& StartingPoint,
98 const math_Vector& InfBound,
99 const math_Vector& SupBound,
100 const math_Vector& XTol,
101 const Standard_Real FTol,
102 const Standard_Integer NbIterations) :
104 TolX(1, F.NbVariables()),
106 Indx (1, F.NbVariables()),
107 Scratch (1, F.NbVariables()),
108 Sol (1, F.NbVariables()),
109 DeltaX (1, F.NbVariables()),
110 FValues (1, F.NbVariables()),
111 Jacobian(1, F.NbVariables(),
113 Itermax(NbIterations)
115 for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
118 Perform(F, StartingPoint, InfBound, SupBound);
121 void math_NewtonFunctionSetRoot::Delete()
124 void math_NewtonFunctionSetRoot::SetTolerance
125 (const math_Vector& XTol)
127 for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
134 void math_NewtonFunctionSetRoot::Perform(
135 math_FunctionSetWithDerivatives& F,
136 const math_Vector& StartingPoint,
137 const math_Vector& InfBound,
138 const math_Vector& SupBound)
143 Standard_Integer Error;
145 Done = Standard_False;
147 OK = F.Values(Sol, FValues, Jacobian);
149 for(Iter = 1; Iter <= Itermax; Iter++) {
150 for(Standard_Integer k = 1; k <= DeltaX.Length(); k++) {
151 DeltaX(k) = -FValues(k);
153 Error = LU_Decompose(Jacobian, Indx, d, Scratch, 1.0e-30);
155 LU_Solve(Jacobian, Indx, DeltaX);
156 for(Standard_Integer i = 1; i <= Sol.Length(); i++) {
159 // Limitation de Sol dans les bornes [InfBound, SupBound] :
160 if (Sol(i) <= InfBound(i)) Sol(i) = InfBound(i);
161 if (Sol(i) >= SupBound(i)) Sol(i) = SupBound(i);
164 OK = F.Values(Sol, FValues, Jacobian);
166 if(IsSolutionReached(F)) {
167 State = F.GetStateNumber();
168 Done = Standard_True;
174 void math_NewtonFunctionSetRoot::Dump(Standard_OStream& o) const
176 o <<"math_NewtonFunctionSetRoot ";
178 o << " Status = Done \n";
179 o << " Vector solution = " << Sol <<"\n";
180 o << " Value of the function at this solution = \n";
182 o << " Number of iterations = " << Iter <<"\n";
185 o << "Status = not Done \n";