Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:14

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 
0027 
0028 //! This class implements the calculation of a root of a function of
0029 //! a single variable starting from an initial near guess using the
0030 //! Newton algorithm. Knowledge of the derivative is required.
0031 class math_NewtonFunctionRoot 
0032 {
0033 public:
0034 
0035   DEFINE_STANDARD_ALLOC
0036 
0037   
0038 
0039   //! The Newton method is done to find the root of the function F
0040   //! from the initial guess Guess.
0041   //! The tolerance required on the root is given by Tolerance.
0042   //! The solution is found when :
0043   //! abs(Xi - Xi-1) <= EpsX and abs(F(Xi))<= EpsF
0044   //! The maximum number of iterations allowed is given by NbIterations.
0045   Standard_EXPORT math_NewtonFunctionRoot(math_FunctionWithDerivative& F, const Standard_Real Guess, const Standard_Real EpsX, const Standard_Real EpsF, const Standard_Integer NbIterations = 100);
0046   
0047 
0048   //! The Newton method is done to find the root of the function F
0049   //! from the initial guess Guess.
0050   //! The solution must be inside the interval [A, B].
0051   //! The tolerance required on the root is given by Tolerance.
0052   //! The solution is found when :
0053   //! abs(Xi - Xi-1) <= EpsX and abs(F(Xi))<= EpsF
0054   //! The maximum number of iterations allowed is given by NbIterations.
0055   Standard_EXPORT math_NewtonFunctionRoot(math_FunctionWithDerivative& F, const Standard_Real Guess, const Standard_Real EpsX, const Standard_Real EpsF, const Standard_Real A, const Standard_Real B, const Standard_Integer NbIterations = 100);
0056   
0057   //! is used in a sub-class to initialize correctly all the fields
0058   //! of this class.
0059   Standard_EXPORT math_NewtonFunctionRoot(const Standard_Real A, const Standard_Real B, const Standard_Real EpsX, const Standard_Real EpsF, const Standard_Integer NbIterations = 100);
0060   
0061   //! is used internally by the constructors.
0062   Standard_EXPORT void Perform (math_FunctionWithDerivative& F, const Standard_Real Guess);
0063   
0064   //! Returns true if the computations are successful, otherwise returns false.
0065     Standard_Boolean IsDone() const;
0066   
0067   //! Returns the value of the root of function <F>.
0068   //! Exception NotDone is raised if the root was not found.
0069     Standard_Real Root() const;
0070   
0071   //! returns the value of the derivative at the root.
0072   //! Exception NotDone is raised if the root was not found.
0073     Standard_Real Derivative() const;
0074   
0075   //! returns the value of the function at the root.
0076   //! Exception NotDone is raised if the root was not found.
0077     Standard_Real Value() const;
0078   
0079   //! Returns the number of iterations really done on the
0080   //! computation of the Root.
0081   //! Exception NotDone is raised if the root was not found.
0082     Standard_Integer NbIterations() const;
0083   
0084   //! Prints information on the current state of the object.
0085   Standard_EXPORT void Dump (Standard_OStream& o) const;
0086 
0087 
0088 
0089 
0090 protected:
0091 
0092 
0093 
0094 
0095 
0096 private:
0097 
0098 
0099 
0100   Standard_Boolean Done;
0101   Standard_Real X;
0102   Standard_Real Fx;
0103   Standard_Real DFx;
0104   Standard_Integer It;
0105   Standard_Real EpsilonX;
0106   Standard_Real EpsilonF;
0107   Standard_Integer Itermax;
0108   Standard_Real Binf;
0109   Standard_Real Bsup;
0110 
0111 
0112 };
0113 
0114 
0115 #include <math_NewtonFunctionRoot.lxx>
0116 
0117 
0118 
0119 
0120 
0121 #endif // _math_NewtonFunctionRoot_HeaderFile