Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:17:48

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_FunctionRoot_HeaderFile
0018 #define _math_FunctionRoot_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_Real.hxx>
0025 #include <Standard_OStream.hxx>
0026 class math_FunctionWithDerivative;
0027 
0028 //! This class implements the computation of a root of a function of
0029 //! a single variable which is near an initial guess using a minimization
0030 //! algorithm.Knowledge of the derivative is required. The
0031 //! algorithm used is the same as in
0032 class math_FunctionRoot
0033 {
0034 public:
0035   DEFINE_STANDARD_ALLOC
0036 
0037   //! The Newton-Raphson method is done to find the root of the function F
0038   //! from the initial guess Guess.The tolerance required on
0039   //! the root is given by Tolerance. Iterations are stopped if
0040   //! the expected solution does not stay in the range A..B.
0041   //! The solution is found when abs(Xi - Xi-1) <= Tolerance;
0042   //! The maximum number of iterations allowed is given by NbIterations.
0043   Standard_EXPORT math_FunctionRoot(math_FunctionWithDerivative& F,
0044                                     const double                 Guess,
0045                                     const double                 Tolerance,
0046                                     const int                    NbIterations = 100);
0047 
0048   //! The Newton-Raphson method is done to find the root of the function F
0049   //! from the initial guess Guess.
0050   //! The tolerance required on the root is given by Tolerance.
0051   //! Iterations are stopped if the expected solution does not stay in the
0052   //! range A..B
0053   //! The solution is found when abs(Xi - Xi-1) <= Tolerance;
0054   //! The maximum number of iterations allowed is given by NbIterations.
0055   Standard_EXPORT math_FunctionRoot(math_FunctionWithDerivative& F,
0056                                     const double                 Guess,
0057                                     const double                 Tolerance,
0058                                     const double                 A,
0059                                     const double                 B,
0060                                     const int                    NbIterations = 100);
0061 
0062   //! Returns true if the computations are successful, otherwise returns false.
0063   bool IsDone() const;
0064 
0065   //! returns the value of the root.
0066   //! Exception NotDone is raised if the root was not found.
0067   double Root() const;
0068 
0069   //! returns the value of the derivative at the root.
0070   //! Exception NotDone is raised if the root was not found.
0071   double Derivative() const;
0072 
0073   //! returns the value of the function at the root.
0074   //! Exception NotDone is raised if the root was not found.
0075   double Value() const;
0076 
0077   //! returns the number of iterations really done on the
0078   //! computation of the Root.
0079   //! Exception NotDone is raised if the root was not found.
0080   int NbIterations() const;
0081 
0082   //! Prints on the stream o information on the current state
0083   //! of the object.
0084   //! Is used to redefine the operator <<.
0085   Standard_EXPORT void Dump(Standard_OStream& o) const;
0086 
0087 private:
0088   bool   Done;
0089   double TheRoot;
0090   double TheError{};
0091   double TheDerivative;
0092   int    NbIter;
0093 };
0094 
0095 #include <math_FunctionRoot.lxx>
0096 
0097 #endif // _math_FunctionRoot_HeaderFile