1 //static const char* sccsid = "@(#)math_FunctionRoot.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
4 #define No_Standard_RangeError
5 #define No_Standard_OutOfRange
6 #define No_Standard_DimensionError
9 #include <Standard_Failure.hxx>
10 #include <math_FunctionRoot.ixx>
11 #include <math_FunctionSetRoot.hxx>
13 #include <math_FunctionSetWithDerivatives.hxx>
14 #include <math_FunctionWithDerivative.hxx>
17 class math_MyFunctionSetWithDerivatives : public math_FunctionSetWithDerivatives {
20 math_FunctionWithDerivative *Ff;
24 math_MyFunctionSetWithDerivatives (math_FunctionWithDerivative& F );
26 Standard_Integer NbVariables () const;
27 Standard_Integer NbEquations () const;
28 Standard_Boolean Value (const math_Vector& X, math_Vector& F) ;
29 Standard_Boolean Derivatives (const math_Vector& X, math_Matrix& D) ;
30 Standard_Boolean Values (const math_Vector& X, math_Vector& F, math_Matrix& D) ;
34 math_MyFunctionSetWithDerivatives::math_MyFunctionSetWithDerivatives
35 (math_FunctionWithDerivative& F ) {
40 Standard_Integer math_MyFunctionSetWithDerivatives::NbVariables () const {
43 Standard_Integer math_MyFunctionSetWithDerivatives::NbEquations () const {
46 Standard_Boolean math_MyFunctionSetWithDerivatives::Value (const math_Vector& X, math_Vector& Fs) {
47 return Ff->Value(X(1),Fs(1));
49 Standard_Boolean math_MyFunctionSetWithDerivatives::Derivatives (const math_Vector& X, math_Matrix& D) {
50 return Ff->Derivative(X(1),D(1,1));
52 Standard_Boolean math_MyFunctionSetWithDerivatives::Values (const math_Vector& X, math_Vector& F, math_Matrix& D) {
53 return Ff->Values(X(1),F(1),D(1,1));
59 math_FunctionRoot::math_FunctionRoot(math_FunctionWithDerivative& F,
60 const Standard_Real Guess,
61 const Standard_Real Tolerance,
62 const Standard_Integer NbIterations ){
64 math_Vector V(1,1), Tol(1,1);
65 math_MyFunctionSetWithDerivatives Ff(F);
68 math_FunctionSetRoot Sol(Ff,V,Tol,NbIterations);
72 Standard_Integer Ier=F.GetStateNumber();
76 TheRoot = Sol.Root()(1);
77 TheDerivative = Sol.Derivative()(1,1);
78 Ok = F.Value(TheRoot,TheError);
79 NbIter = Sol.NbIterations();
82 math_FunctionRoot::math_FunctionRoot(math_FunctionWithDerivative& F,
83 const Standard_Real Guess,
84 const Standard_Real Tolerance,
85 const Standard_Real A,
86 const Standard_Real B,
87 const Standard_Integer NbIterations ){
89 math_Vector V(1,1),Aa(1,1),Bb(1,1), Tol(1,1);
90 math_MyFunctionSetWithDerivatives Ff(F);
95 math_FunctionSetRoot Sol(Ff,V,Tol,Aa,Bb,NbIterations);
99 Standard_Integer Ier =F.GetStateNumber();
103 TheRoot = Sol.Root()(1);
104 TheDerivative = Sol.Derivative()(1,1);
105 Ok = F.Value(TheRoot,TheError);
106 NbIter = Sol.NbIterations();
110 void math_FunctionRoot::Dump(Standard_OStream& o) const {
112 o<< "math_FunctionRoot ";
114 o<< " Status = Done \n";
115 o << " Number of iterations = " << NbIter << endl;
116 o << " The Root is: " << TheRoot << endl;
117 o << "The value at the root is: " << TheError << endl;
120 o<< " Status = not Done \n";