1 -- Created on: 1991-05-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 class NewtonFunctionSetRoot from math
19 -- This class computes the root of a set of N functions of N variables,
20 -- knowing an initial guess at the solution and using the
21 -- Newton Raphson algorithm. Knowledge of all the partial
22 -- derivatives (Jacobian) is required.
24 uses Vector from math, Matrix from math, IntegerVector from math,
25 FunctionSetWithDerivatives from math,
28 raises NotDone from StdFail,
29 DimensionError from Standard
33 Create(F: in out FunctionSetWithDerivatives;
34 XTol: Vector; FTol: Real;
35 NbIterations: Integer = 100)
37 -- This constructor should be used in a sub-class to initialize
38 -- correctly all the fields of this class.
39 -- The range (1, F.NbVariables()) must be especially respected for
40 -- all vectors and matrix declarations.
42 returns NewtonFunctionSetRoot;
45 Create(F: in out FunctionSetWithDerivatives;
46 FTol: Real; NbIterations: Integer = 100)
48 -- This constructor should be used in a sub-class to initialize
49 -- correctly all the fields of this class.
50 -- The range (1, F.NbVariables()) must be especially respected for
51 -- all vectors and matrix declarations.
52 -- The method SetTolerance must be called before performing the
55 returns NewtonFunctionSetRoot;
59 Create(F: in out FunctionSetWithDerivatives;
60 StartingPoint: Vector;
61 XTol: Vector; FTol: Real;
62 NbIterations: Integer = 100)
64 -- The Newton method is done to improve the root of the function F
65 -- from the initial guess StartingPoint.
66 -- The tolerance required on the root is given by Tolerance.
67 -- The solution is found when :
68 -- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
69 -- The maximum number of iterations allowed is given by NbIterations.
71 returns NewtonFunctionSetRoot;
75 Create(F: in out FunctionSetWithDerivatives;
76 StartingPoint: Vector;
77 InfBound, SupBound: Vector;
78 XTol: Vector; FTol: Real;
79 NbIterations: Integer = 100)
81 -- The Newton method is done to improve the root of the function F
82 -- from the initial guess StartingPoint.
83 -- The tolerance required on the root is given by Tolerance.
84 -- The solution is found when :
85 -- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
86 -- The maximum number of iterations allowed is given by NbIterations.
88 returns NewtonFunctionSetRoot;
91 Delete(me:out) is virtual;
92 ---C++: alias "Standard_EXPORT virtual ~math_NewtonFunctionSetRoot(){Delete();}"
94 SetTolerance(me: in out; XTol: Vector)
95 ---Purpose: Initializes the tolerance values for the unknowns.
100 Perform(me: in out; F:in out FunctionSetWithDerivatives;
101 StartingPoint: Vector;
102 InfBound, SupBound: Vector)
103 ---Purpose: Improves the root of function F from the initial guess
104 -- StartingPoint. infBound and supBound may be given, to constrain the solution.
106 -- This method must be called when the solution is not computed by the constructors.
112 IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
114 -- This method is called at the end of each iteration to check if the
115 -- solution is found.
116 -- Vectors DeltaX, Fvalues and Jacobian Matrix are consistent with the
117 -- possible solution Vector Sol and can be inspected to decide whether
118 -- the solution is reached or not.
125 ---Purpose: Returns true if the computations are successful, otherwise returns false.
132 ---Purpose: Returns the value of the root of function F.
134 -- StdFail_NotDone if the algorithm fails (and IsDone returns false).
136 ---C++: return const&
142 Root(me; Root: out Vector)
143 ---Purpose: outputs the root vector in Root.
144 -- Exception NotDone is raised if the root was not found.
145 -- Exception DimensionError is raised if the range of Root is
146 -- not equal to the range of the StartingPoint.
155 ---Purpose: Outputs the state number associated with the solution
164 ---Purpose: Returns the matrix value of the derivative at the root.
165 -- Exception NotDone is raised if the root was not found.
167 ---C++: return const&
173 Derivative(me; Der: out Matrix)
174 ---Purpose: Outputs the matrix value of the derivative at the root in
176 -- Exception NotDone is raised if the root was not found.
177 -- Exception DimensionError is raised if the range of Der is
178 -- not equal to the range of the StartingPoint.
185 FunctionSetErrors(me)
186 ---Purpose: Returns the vector value of the error done on the
187 -- functions at the root.
188 -- Exception NotDone is raised if the root was not found.
190 ---C++: return const&
196 FunctionSetErrors(me; Err: out Vector)
197 ---Purpose: Outputs the vector value of the error done on the
198 -- functions at the root in Err.
199 -- Exception NotDone is raised if the root was not found.
200 -- Exception DimensionError is raised if the range of Err is
201 -- not equal to the range of the StartingPoint.
209 ---Purpose: Returns the number of iterations really done
210 -- during the computation of the Root.
211 -- Exception NotDone is raised if the root was not found.
218 Dump(me; o: in out OStream)
219 ---Purpose: Prints information on the current state of the object.
220 -- Is used to redefine the operator <<.
229 TolX: Vector is protected;
230 TolF: Real is protected;
232 Indx: IntegerVector is protected;
233 Scratch: Vector is protected;
234 Sol: Vector is protected;
235 DeltaX: Vector is protected;
236 FValues: Vector is protected;
237 Jacobian: Matrix is protected;
240 end NewtonFunctionSetRoot;