1 -- Created on: 2014-03-15
2 -- Created by: Laurent PAINNOT
3 -- Copyright (c) 1997-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
23 class BissecNewton from math
25 -- This class implements a combination of Newton-Raphson and bissection
26 -- methods to find the root of the function between two bounds.
27 -- Knowledge of the derivative is required.
29 uses Vector from math,
31 FunctionWithDerivative from math,
35 raises NotDone from StdFail
40 Perform(me: in out; F: out FunctionWithDerivative;
42 NbIterations: Integer)
47 Create(F: in out FunctionWithDerivative;
48 Bound1, Bound2, TolX: Real;
49 NbIterations: Integer = 100)
51 -- A combination of Newton-Raphson and bissection methods is done to find
52 -- the root of the function F between the bounds Bound1 and Bound2.
54 -- The tolerance required on the root is given by TolX.
55 -- The solution is found when :
56 -- abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0
57 -- The maximum number of iterations allowed is given by NbIterations.
62 IsSolutionReached(me: in out; F: out FunctionWithDerivative)
64 -- This method is called at the end of each iteration to check if the
65 -- solution has been found.
66 -- It can be redefined in a sub-class to implement a specific test to
67 -- stop the iterations.
74 ---Purpose: Tests is the root has been successfully found.
81 ---Purpose: returns the value of the root.
82 -- Exception NotDone is raised if the minimum was not found.
89 ---Purpose: returns the value of the derivative at the root.
90 -- Exception NotDone is raised if the minimum was not found.
99 ---Purpose: returns the value of the function at the root.
100 -- Exception NotDone is raised if the minimum was not found.
108 Dump(me; o: in out OStream)
109 ---Purpose: Prints on the stream o information on the current state
111 -- Is used to redifine the operator <<.
119 TheStatus: Status is protected;
120 XTol: Real is protected;
121 x: Real is protected;
122 dx: Real is protected;
123 f: Real is protected;
124 df: Real is protected;