1 // Created on: 1991-05-14
2 // Created by: Laurent Painnot
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _math_BracketedRoot_HeaderFile
18 #define _math_BracketedRoot_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Real.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_OStream.hxx>
28 class StdFail_NotDone;
32 //! This class implements the Brent method to find the root of a function
33 //! located within two bounds. No knowledge of the derivative is required.
34 class math_BracketedRoot
42 //! The Brent method is used to find the root of the function F between
43 //! the bounds Bound1 and Bound2 on the function F.
44 //! If F(Bound1)*F(Bound2) >0 the Brent method fails.
45 //! The tolerance required for the root is given by Tolerance.
46 //! The solution is found when :
47 //! abs(Xi - Xi-1) <= Tolerance;
48 //! The maximum number of iterations allowed is given by NbIterations.
49 Standard_EXPORT math_BracketedRoot(math_Function& F, const Standard_Real Bound1, const Standard_Real Bound2, const Standard_Real Tolerance, const Standard_Integer NbIterations = 100, const Standard_Real ZEPS = 1.0e-12);
51 //! Returns true if the computations are successful, otherwise returns false.
52 Standard_Boolean IsDone() const;
54 //! returns the value of the root.
55 //! Exception NotDone is raised if the minimum was not found.
56 Standard_Real Root() const;
58 //! returns the value of the function at the root.
59 //! Exception NotDone is raised if the minimum was not found.
60 Standard_Real Value() const;
62 //! returns the number of iterations really done during the
63 //! computation of the Root.
64 //! Exception NotDone is raised if the minimum was not found.
65 Standard_Integer NbIterations() const;
67 //! Prints on the stream o information on the current state
69 Standard_EXPORT void Dump (Standard_OStream& o) const;
84 Standard_Boolean Done;
85 Standard_Real TheRoot;
86 Standard_Real TheError;
87 Standard_Integer NbIter;
93 #include <math_BracketedRoot.lxx>
99 #endif // _math_BracketedRoot_HeaderFile