0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / math / math_FunctionRoot.hxx
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_FunctionRoot_HeaderFile
18 #define _math_FunctionRoot_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_FunctionWithDerivative;
30
31
32
33 //! This class implements the computation of a root of a function of
34 //! a single variable which is near an initial guess using a minimization
35 //! algorithm.Knowledge of the derivative is required. The
36 //! algorithm used is the same as in
37 class math_FunctionRoot 
38 {
39 public:
40
41   DEFINE_STANDARD_ALLOC
42
43   
44
45   //! The Newton-Raphson method is done to find the root of the function F
46   //! from the initial guess Guess.The tolerance required on
47   //! the root is given by Tolerance. Iterations are stopped if
48   //! the expected solution does not stay in the range A..B.
49   //! The solution is found when abs(Xi - Xi-1) <= Tolerance;
50   //! The maximum number of iterations allowed is given by NbIterations.
51   Standard_EXPORT math_FunctionRoot(math_FunctionWithDerivative& F, const Standard_Real Guess, const Standard_Real Tolerance, const Standard_Integer NbIterations = 100);
52   
53
54   //! The Newton-Raphson method is done to find the root of the function F
55   //! from the initial guess Guess.
56   //! The tolerance required on the root is given by Tolerance.
57   //! Iterations are stopped if the expected solution does not stay in the
58   //! range A..B
59   //! The solution is found when abs(Xi - Xi-1) <= Tolerance;
60   //! The maximum number of iterations allowed is given by NbIterations.
61   Standard_EXPORT math_FunctionRoot(math_FunctionWithDerivative& F, const Standard_Real Guess, const Standard_Real Tolerance, const Standard_Real A, const Standard_Real B, const Standard_Integer NbIterations = 100);
62   
63   //! Returns true if the computations are successful, otherwise returns false.
64     Standard_Boolean IsDone() const;
65   
66   //! returns the value of the root.
67   //! Exception NotDone is raised if the root was not found.
68     Standard_Real Root() const;
69   
70   //! returns the value of the derivative at the root.
71   //! Exception NotDone is raised if the root was not found.
72     Standard_Real Derivative() const;
73   
74   //! returns the value of the function at the root.
75   //! Exception NotDone is raised if the root was not found.
76     Standard_Real Value() const;
77   
78   //! returns the number of iterations really done on the
79   //! computation of the Root.
80   //! Exception NotDone is raised if the root was not found.
81     Standard_Integer NbIterations() const;
82   
83   //! Prints on the stream o information on the current state
84   //! of the object.
85   //! Is used to redefine the operator <<.
86   Standard_EXPORT void Dump (Standard_OStream& o) const;
87
88
89
90
91 protected:
92
93
94
95
96
97 private:
98
99
100
101   Standard_Boolean Done;
102   Standard_Real TheRoot;
103   Standard_Real TheError;
104   Standard_Real TheDerivative;
105   Standard_Integer NbIter;
106
107
108 };
109
110
111 #include <math_FunctionRoot.lxx>
112
113
114
115
116
117 #endif // _math_FunctionRoot_HeaderFile