CommitLineData
42cf5bc1 1// Created on: 1991-03-14
2// Created by: Laurent PAINNOT
3// Copyright (c) 1991-1999 Matra Datavision
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
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
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>
29class StdFail_NotDone;
30class math_FunctionWithDerivative;
31
32
33
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.
37class math_BissecNewton
38{
39public:
40
41 DEFINE_STANDARD_ALLOC
42
43
44 //! Constructor.
45 //! @param theXTolerance - algorithm tolerance.
46 Standard_EXPORT math_BissecNewton(const Standard_Real theXTolerance);
47
48
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);
57
58
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);
64
65 //! Tests is the root has been successfully found.
66 Standard_Boolean IsDone() const;
67
68 //! returns the value of the root.
69 //! Exception NotDone is raised if the minimum was not found.
70 Standard_Real Root() const;
71
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;
75
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;
79
80 //! Prints on the stream o information on the current state
81 //! of the object.
82 //! Is used to redifine the operator <<.
83 Standard_EXPORT void Dump (Standard_OStream& o) const;
84
e6f550da 85 //! Destructor
42cf5bc1 86 Standard_EXPORT virtual ~math_BissecNewton();
87
88
89
90
91protected:
92
93
94
95 math_Status TheStatus;
96 Standard_Real XTol;
97 Standard_Real x;
98 Standard_Real dx;
99 Standard_Real f;
100 Standard_Real df;
101
102
103private:
104
105
106
107 Standard_Boolean Done;
108
109
110};
111
112
113#include <math_BissecNewton.lxx>
114
115
116
117
118