1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <math_FunctionWithDerivative.hxx>
17 #include <math_NewtonFunctionRoot.hxx>
18 #include <StdFail_NotDone.hxx>
20 math_NewtonFunctionRoot::math_NewtonFunctionRoot (math_FunctionWithDerivative& F,
21 const Standard_Real Guess,
22 const Standard_Real EpsX ,
23 const Standard_Real EpsF ,
24 const Standard_Real A,
25 const Standard_Real B,
26 const Standard_Integer NbIterations ){
31 Itermax = NbIterations;
32 Done = Standard_False;
41 math_NewtonFunctionRoot::math_NewtonFunctionRoot (const Standard_Real A ,
42 const Standard_Real B,
43 const Standard_Real EpsX ,
44 const Standard_Real EpsF ,
45 const Standard_Integer NbIterations ){
51 Itermax = NbIterations;
52 Done = Standard_False;
60 math_NewtonFunctionRoot::math_NewtonFunctionRoot (math_FunctionWithDerivative& F,
61 const Standard_Real Guess,
62 const Standard_Real EpsX ,
63 const Standard_Real EpsF ,
64 const Standard_Integer NbIterations ){
67 Itermax = NbIterations;
70 Done = Standard_False;
79 void math_NewtonFunctionRoot::Perform(math_FunctionWithDerivative& F,
80 const Standard_Real Guess) {
86 //--------------------------------------------------
88 //-- la meilleure estimation n est pas sauvee et on
89 //-- renvoie une solution plus fausse que Guess
90 Standard_Real BestX=X,BestFx=RealLast();
106 while ( (It <= Itermax) && ( (Abs(Dx) > EpsilonX) ||
107 (Abs(Fx) > EpsilonF) ) ) {
108 Ok = F.Values(X,Fx,DFx);
110 Standard_Real AbsFx = Fx; if(AbsFx<0) AbsFx=-AbsFx;
118 Done = Standard_False;
124 // Limitation des variations de X:
131 Done = Standard_False;
138 Done = Standard_True;
142 Done = Standard_False;
147 void math_NewtonFunctionRoot::Dump(Standard_OStream& o) const {
149 o <<"math_NewtonFunctionRoot ";
151 o << " Status = Done \n";
152 o << " Location found = " << X <<"\n";
153 o << " function value at this minimum = " << Fx <<"\n";
154 o << " Number of iterations = " << It <<"\n";
157 o << "Status = not Done \n";