0024510: Remove unused local variables
[occt.git] / src / math / math_FunctionRoot.cxx
CommitLineData
b311480e 1// Copyright (c) 1997-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15//#ifndef DEB
16#define No_Standard_RangeError
17#define No_Standard_OutOfRange
18#define No_Standard_DimensionError
19//#endif
20
21#include <Standard_Failure.hxx>
22#include <math_FunctionRoot.ixx>
23#include <math_FunctionSetRoot.hxx>
24
25#include <math_FunctionSetWithDerivatives.hxx>
26#include <math_FunctionWithDerivative.hxx>
27
28
29class math_MyFunctionSetWithDerivatives : public math_FunctionSetWithDerivatives {
30
31 private:
32 math_FunctionWithDerivative *Ff;
33
34 public :
35
36 math_MyFunctionSetWithDerivatives (math_FunctionWithDerivative& F );
37
38 Standard_Integer NbVariables () const;
39 Standard_Integer NbEquations () const;
40 Standard_Boolean Value (const math_Vector& X, math_Vector& F) ;
41 Standard_Boolean Derivatives (const math_Vector& X, math_Matrix& D) ;
42 Standard_Boolean Values (const math_Vector& X, math_Vector& F, math_Matrix& D) ;
43};
44
45
46 math_MyFunctionSetWithDerivatives::math_MyFunctionSetWithDerivatives
47 (math_FunctionWithDerivative& F ) {
48 Ff = &F ;
49
50 }
51
52 Standard_Integer math_MyFunctionSetWithDerivatives::NbVariables () const {
53 return 1;
54 }
55 Standard_Integer math_MyFunctionSetWithDerivatives::NbEquations () const {
56 return 1;
57 }
58 Standard_Boolean math_MyFunctionSetWithDerivatives::Value (const math_Vector& X, math_Vector& Fs) {
59 return Ff->Value(X(1),Fs(1));
60 }
61 Standard_Boolean math_MyFunctionSetWithDerivatives::Derivatives (const math_Vector& X, math_Matrix& D) {
62 return Ff->Derivative(X(1),D(1,1));
63 }
64 Standard_Boolean math_MyFunctionSetWithDerivatives::Values (const math_Vector& X, math_Vector& F, math_Matrix& D) {
65 return Ff->Values(X(1),F(1),D(1,1));
66 }
67
68
69
70
71 math_FunctionRoot::math_FunctionRoot(math_FunctionWithDerivative& F,
72 const Standard_Real Guess,
73 const Standard_Real Tolerance,
74 const Standard_Integer NbIterations ){
7fd59977 75 math_Vector V(1,1), Tol(1,1);
76 math_MyFunctionSetWithDerivatives Ff(F);
77 V(1)=Guess;
78 Tol(1) = Tolerance;
79 math_FunctionSetRoot Sol(Ff,V,Tol,NbIterations);
80 Done = Sol.IsDone();
81 if (Done) {
7fd59977 82 F.GetStateNumber();
7fd59977 83 TheRoot = Sol.Root()(1);
84 TheDerivative = Sol.Derivative()(1,1);
96a95605 85 F.Value(TheRoot,TheError);
7fd59977 86 NbIter = Sol.NbIterations();
87 }
88 }
89 math_FunctionRoot::math_FunctionRoot(math_FunctionWithDerivative& F,
90 const Standard_Real Guess,
91 const Standard_Real Tolerance,
92 const Standard_Real A,
93 const Standard_Real B,
94 const Standard_Integer NbIterations ){
7fd59977 95 math_Vector V(1,1),Aa(1,1),Bb(1,1), Tol(1,1);
96 math_MyFunctionSetWithDerivatives Ff(F);
97 V(1)=Guess;
98 Tol(1) = Tolerance;
99 Aa(1)=A;
100 Bb(1)=B;
101 math_FunctionSetRoot Sol(Ff,V,Tol,Aa,Bb,NbIterations);
102 Done = Sol.IsDone();
103 if (Done) {
7fd59977 104 F.GetStateNumber();
7fd59977 105 TheRoot = Sol.Root()(1);
106 TheDerivative = Sol.Derivative()(1,1);
96a95605 107 F.Value(TheRoot,TheError);
7fd59977 108 NbIter = Sol.NbIterations();
109 }
110 }
111
112 void math_FunctionRoot::Dump(Standard_OStream& o) const {
113
114 o<< "math_FunctionRoot ";
115 if(Done) {
116 o<< " Status = Done \n";
117 o << " Number of iterations = " << NbIter << endl;
118 o << " The Root is: " << TheRoot << endl;
119 o << "The value at the root is: " << TheError << endl;
120 }
121 else {
122 o<< " Status = not Done \n";
123 }
124 }