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
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_BissecNewton_HeaderFile
18 #define _math_BissecNewton_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <math_Status.hxx>
26 #include <Standard_Real.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_OStream.hxx>
29 class StdFail_NotDone;
30 class math_FunctionWithDerivative;
34 //! This class implements a combination of Newton-Raphson and bissection
35 //! methods to find the root of the function between two bounds.
36 //! Knowledge of the derivative is required.
37 class math_BissecNewton
45 //! @param theXTolerance - algorithm tolerance.
46 Standard_EXPORT math_BissecNewton(const Standard_Real theXTolerance);
49 //! A combination of Newton-Raphson and bissection methods is done to find
50 //! the root of the function F between the bounds Bound1 and Bound2
51 //! on the function F.
52 //! The tolerance required on the root is given by TolX.
53 //! The solution is found when:
54 //! abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0
55 //! The maximum number of iterations allowed is given by NbIterations.
56 Standard_EXPORT void Perform (math_FunctionWithDerivative& F, const Standard_Real Bound1, const Standard_Real Bound2, const Standard_Integer NbIterations = 100);
59 //! This method is called at the end of each iteration to check if the
60 //! solution has been found.
61 //! It can be redefined in a sub-class to implement a specific test to
62 //! stop the iterations.
63 virtual Standard_Boolean IsSolutionReached (math_FunctionWithDerivative& theFunction);
65 //! Tests is the root has been successfully found.
66 Standard_Boolean IsDone() const;
68 //! returns the value of the root.
69 //! Exception NotDone is raised if the minimum was not found.
70 Standard_Real Root() const;
72 //! returns the value of the derivative at the root.
73 //! Exception NotDone is raised if the minimum was not found.
74 Standard_Real Derivative() const;
76 //! returns the value of the function at the root.
77 //! Exception NotDone is raised if the minimum was not found.
78 Standard_Real Value() const;
80 //! Prints on the stream o information on the current state
82 //! Is used to redifine the operator <<.
83 Standard_EXPORT void Dump (Standard_OStream& o) const;
86 Standard_EXPORT virtual ~math_BissecNewton();
95 math_Status TheStatus;
107 Standard_Boolean Done;
113 #include <math_BissecNewton.lxx>
119 #endif // _math_BissecNewton_HeaderFile