42cf5bc1 |
1 | // Created on: 1991-03-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_BissecNewton_HeaderFile |
18 | #define _math_BissecNewton_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
42cf5bc1 |
24 | #include <math_Status.hxx> |
25 | #include <Standard_Real.hxx> |
42cf5bc1 |
26 | #include <Standard_OStream.hxx> |
42cf5bc1 |
27 | class math_FunctionWithDerivative; |
28 | |
29 | |
30 | |
31 | //! This class implements a combination of Newton-Raphson and bissection |
32 | //! methods to find the root of the function between two bounds. |
33 | //! Knowledge of the derivative is required. |
34 | class math_BissecNewton |
35 | { |
36 | public: |
37 | |
38 | DEFINE_STANDARD_ALLOC |
39 | |
40 | |
41 | //! Constructor. |
42 | //! @param theXTolerance - algorithm tolerance. |
43 | Standard_EXPORT math_BissecNewton(const Standard_Real theXTolerance); |
44 | |
45 | |
46 | //! A combination of Newton-Raphson and bissection methods is done to find |
47 | //! the root of the function F between the bounds Bound1 and Bound2 |
48 | //! on the function F. |
49 | //! The tolerance required on the root is given by TolX. |
50 | //! The solution is found when: |
51 | //! abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0 |
52 | //! The maximum number of iterations allowed is given by NbIterations. |
53 | Standard_EXPORT void Perform (math_FunctionWithDerivative& F, const Standard_Real Bound1, const Standard_Real Bound2, const Standard_Integer NbIterations = 100); |
54 | |
55 | |
56 | //! This method is called at the end of each iteration to check if the |
57 | //! solution has been found. |
58 | //! It can be redefined in a sub-class to implement a specific test to |
59 | //! stop the iterations. |
60 | virtual Standard_Boolean IsSolutionReached (math_FunctionWithDerivative& theFunction); |
61 | |
62 | //! Tests is the root has been successfully found. |
63 | Standard_Boolean IsDone() const; |
64 | |
65 | //! returns the value of the root. |
66 | //! Exception NotDone is raised if the minimum was not found. |
67 | Standard_Real Root() const; |
68 | |
69 | //! returns the value of the derivative at the root. |
70 | //! Exception NotDone is raised if the minimum was not found. |
71 | Standard_Real Derivative() const; |
72 | |
73 | //! returns the value of the function at the root. |
74 | //! Exception NotDone is raised if the minimum was not found. |
75 | Standard_Real Value() const; |
76 | |
77 | //! Prints on the stream o information on the current state |
78 | //! of the object. |
79 | //! Is used to redifine the operator <<. |
80 | Standard_EXPORT void Dump (Standard_OStream& o) const; |
81 | |
e6f550da |
82 | //! Destructor |
42cf5bc1 |
83 | Standard_EXPORT virtual ~math_BissecNewton(); |
84 | |
85 | |
86 | |
87 | |
88 | protected: |
89 | |
90 | |
91 | |
92 | math_Status TheStatus; |
93 | Standard_Real XTol; |
94 | Standard_Real x; |
95 | Standard_Real dx; |
96 | Standard_Real f; |
97 | Standard_Real df; |
98 | |
99 | |
100 | private: |
101 | |
102 | |
103 | |
104 | Standard_Boolean Done; |
105 | |
106 | |
107 | }; |
108 | |
109 | |
110 | #include <math_BissecNewton.lxx> |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | #endif // _math_BissecNewton_HeaderFile |