b311480e |
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 |
5 | -- |
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. |
10 | -- |
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. |
13 | -- |
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. |
20 | |
7fd59977 |
21 | |
22 | class FunctionRoot from math |
23 | ---Purpose: |
24 | -- This class implements the computation of a root of a function of |
25 | -- a single variable which is near an initial guess using a minimization |
26 | -- algorithm.Knowledge of the derivative is required. The |
27 | -- algorithm used is the same as in |
28 | |
29 | uses Vector from math, Matrix from math, |
30 | FunctionWithDerivative from math, |
31 | OStream from Standard |
32 | |
33 | raises NotDone from StdFail |
34 | |
35 | is |
36 | |
37 | Create(F: in out FunctionWithDerivative; |
38 | Guess, Tolerance: Real; |
39 | NbIterations: Integer = 100) |
40 | ---Purpose: |
41 | -- The Newton-Raphson method is done to find the root of the function F |
42 | -- from the initial guess Guess.The tolerance required on |
43 | -- the root is given by Tolerance. Iterations are stopped if |
44 | -- the expected solution does not stay in the range A..B. |
45 | -- The solution is found when abs(Xi - Xi-1) <= Tolerance; |
46 | -- The maximum number of iterations allowed is given by NbIterations. |
47 | |
48 | returns FunctionRoot; |
49 | |
50 | |
51 | Create(F: in out FunctionWithDerivative; |
52 | Guess, Tolerance,A,B: Real; |
53 | NbIterations: Integer = 100) |
54 | ---Purpose: |
55 | -- The Newton-Raphson method is done to find the root of the function F |
56 | -- from the initial guess Guess. |
57 | -- The tolerance required on the root is given by Tolerance. |
58 | -- Iterations are stopped if the expected solution does not stay in the |
59 | -- range A..B |
60 | -- The solution is found when abs(Xi - Xi-1) <= Tolerance; |
61 | -- The maximum number of iterations allowed is given by NbIterations. |
62 | |
63 | returns FunctionRoot; |
64 | |
65 | |
66 | IsDone(me) |
67 | ---Purpose: Returns true if the computations are successful, otherwise returns false. |
68 | ---C++: inline |
69 | returns Boolean |
70 | is static; |
71 | |
72 | |
73 | Root(me) |
74 | ---Purpose: returns the value of the root. |
75 | -- Exception NotDone is raised if the root was not found. |
76 | ---C++: inline |
77 | |
78 | returns Real |
79 | raises NotDone |
80 | is static; |
81 | |
82 | |
83 | Derivative(me) |
84 | ---Purpose: returns the value of the derivative at the root. |
85 | -- Exception NotDone is raised if the root was not found. |
86 | ---C++: inline |
87 | |
88 | returns Real |
89 | raises NotDone |
90 | is static; |
91 | |
92 | |
93 | Value(me) |
94 | ---Purpose: returns the value of the function at the root. |
95 | -- Exception NotDone is raised if the root was not found. |
96 | ---C++: inline |
97 | |
98 | returns Real |
99 | raises NotDone |
100 | is static; |
101 | |
102 | |
103 | NbIterations(me) |
104 | ---Purpose: returns the number of iterations really done on the |
105 | -- computation of the Root. |
106 | -- Exception NotDone is raised if the root was not found. |
107 | ---C++: inline |
108 | |
109 | returns Integer |
110 | raises NotDone |
111 | is static; |
112 | |
113 | |
114 | Dump(me; o: in out OStream) |
115 | ---Purpose: Prints on the stream o information on the current state |
116 | -- of the object. |
117 | -- Is used to redefine the operator <<. |
118 | |
119 | is static; |
120 | |
121 | |
122 | fields |
123 | |
124 | Done: Boolean; |
125 | TheRoot: Real ; |
126 | TheError: Real ; |
127 | TheDerivative: Real ; |
128 | NbIter: Integer; |
129 | |
130 | end FunctionRoot; |