42cf5bc1 |
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 |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
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. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _math_BracketedRoot_HeaderFile |
18 | #define _math_BracketedRoot_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <Standard_Boolean.hxx> |
25 | #include <Standard_Real.hxx> |
26 | #include <Standard_Integer.hxx> |
27 | #include <Standard_OStream.hxx> |
28 | class StdFail_NotDone; |
29 | class math_Function; |
30 | |
31 | |
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 |
35 | { |
36 | public: |
37 | |
38 | DEFINE_STANDARD_ALLOC |
39 | |
40 | |
41 | |
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); |
50 | |
51 | //! Returns true if the computations are successful, otherwise returns false. |
52 | Standard_Boolean IsDone() const; |
53 | |
54 | //! returns the value of the root. |
55 | //! Exception NotDone is raised if the minimum was not found. |
56 | Standard_Real Root() const; |
57 | |
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; |
61 | |
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; |
66 | |
67 | //! Prints on the stream o information on the current state |
68 | //! of the object. |
69 | Standard_EXPORT void Dump (Standard_OStream& o) const; |
70 | |
71 | |
72 | |
73 | |
74 | protected: |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | private: |
81 | |
82 | |
83 | |
84 | Standard_Boolean Done; |
85 | Standard_Real TheRoot; |
86 | Standard_Real TheError; |
87 | Standard_Integer NbIter; |
88 | |
89 | |
90 | }; |
91 | |
92 | |
93 | #include <math_BracketedRoot.lxx> |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | #endif // _math_BracketedRoot_HeaderFile |