Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-09 10:27:21

0001 // Created on: 1991-03-14
0002 // Created by: Laurent PAINNOT
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _math_NewtonFunctionRoot_HeaderFile
0018 #define _math_NewtonFunctionRoot_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 
0023 #include <Standard_OStream.hxx>
0024 class math_FunctionWithDerivative;
0025 
0026 //! This class implements the calculation of a root of a function of
0027 //! a single variable starting from an initial near guess using the
0028 //! Newton algorithm. Knowledge of the derivative is required.
0029 class math_NewtonFunctionRoot
0030 {
0031 public:
0032   DEFINE_STANDARD_ALLOC
0033 
0034   //! The Newton method is done to find the root of the function F
0035   //! from the initial guess Guess.
0036   //! The tolerance required on the root is given by Tolerance.
0037   //! The solution is found when :
0038   //! abs(Xi - Xi-1) <= EpsX and abs(F(Xi))<= EpsF
0039   //! The maximum number of iterations allowed is given by NbIterations.
0040   Standard_EXPORT math_NewtonFunctionRoot(math_FunctionWithDerivative& F,
0041                                           const double                 Guess,
0042                                           const double                 EpsX,
0043                                           const double                 EpsF,
0044                                           const int                    NbIterations = 100);
0045 
0046   //! The Newton method is done to find the root of the function F
0047   //! from the initial guess Guess.
0048   //! The solution must be inside the interval [A, B].
0049   //! The tolerance required on the root is given by Tolerance.
0050   //! The solution is found when :
0051   //! abs(Xi - Xi-1) <= EpsX and abs(F(Xi))<= EpsF
0052   //! The maximum number of iterations allowed is given by NbIterations.
0053   Standard_EXPORT math_NewtonFunctionRoot(math_FunctionWithDerivative& F,
0054                                           const double                 Guess,
0055                                           const double                 EpsX,
0056                                           const double                 EpsF,
0057                                           const double                 A,
0058                                           const double                 B,
0059                                           const int                    NbIterations = 100);
0060 
0061   //! is used in a sub-class to initialize correctly all the fields
0062   //! of this class.
0063   Standard_EXPORT math_NewtonFunctionRoot(const double A,
0064                                           const double B,
0065                                           const double EpsX,
0066                                           const double EpsF,
0067                                           const int    NbIterations = 100);
0068 
0069   //! is used internally by the constructors.
0070   Standard_EXPORT void Perform(math_FunctionWithDerivative& F, const double Guess);
0071 
0072   //! Returns true if the computations are successful, otherwise returns false.
0073   bool IsDone() const;
0074 
0075   //! Returns the value of the root of function <F>.
0076   //! Exception NotDone is raised if the root was not found.
0077   double Root() const;
0078 
0079   //! returns the value of the derivative at the root.
0080   //! Exception NotDone is raised if the root was not found.
0081   double Derivative() const;
0082 
0083   //! returns the value of the function at the root.
0084   //! Exception NotDone is raised if the root was not found.
0085   double Value() const;
0086 
0087   //! Returns the number of iterations really done on the
0088   //! computation of the Root.
0089   //! Exception NotDone is raised if the root was not found.
0090   int NbIterations() const;
0091 
0092   //! Prints information on the current state of the object.
0093   Standard_EXPORT void Dump(Standard_OStream& o) const;
0094 
0095 private:
0096   bool   Done;
0097   double X;
0098   double Fx;
0099   double DFx;
0100   int    It;
0101   double EpsilonX;
0102   double EpsilonF;
0103   int    Itermax;
0104   double Binf;
0105   double Bsup;
0106 };
0107 
0108 #include <math_NewtonFunctionRoot.lxx>
0109 
0110 #endif // _math_NewtonFunctionRoot_HeaderFile