1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License 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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #define No_Standard_RangeError
17 #define No_Standard_OutOfRange
18 #define No_Standard_DimensionError
22 #include <math_Gauss.hxx>
23 #include <math_Matrix.hxx>
24 #include <math_NotSquare.hxx>
25 #include <math_Recipes.hxx>
26 #include <Standard_DimensionError.hxx>
27 #include <Standard_NotImplemented.hxx>
28 #include <StdFail_NotDone.hxx>
30 math_Gauss::math_Gauss(const math_Matrix& A,
31 const Standard_Real MinPivot,
32 const Handle(Message_ProgressIndicator) & aProgress)
33 : LU (1, A.RowNumber(), 1, A.ColNumber()),
34 Index(1, A.RowNumber()) {
36 math_NotSquare_Raise_if(A.RowNumber() != A.ColNumber(), " ");
38 Standard_Integer Error = LU_Decompose(LU,
47 Done = Standard_False;
51 void math_Gauss::Solve(const math_Vector& B, math_Vector& X) const{
53 StdFail_NotDone_Raise_if(!Done, " ");
61 void math_Gauss::Solve (math_Vector& X) const{
63 StdFail_NotDone_Raise_if(!Done, " ");
65 if(X.Length() != LU.RowNumber()) {
66 throw Standard_DimensionError();
73 Standard_Real math_Gauss::Determinant() const{
75 StdFail_NotDone_Raise_if(!Done, " ");
77 Standard_Real Result = D;
78 for(Standard_Integer J = 1; J <= LU.UpperRow(); J++) {
84 void math_Gauss::Invert(math_Matrix& Inv) const{
86 StdFail_NotDone_Raise_if(!Done, " ");
88 Standard_DimensionError_Raise_if((Inv.RowNumber() != LU.RowNumber()) ||
89 (Inv.ColNumber() != LU.ColNumber()),
92 Standard_Integer LowerRow = Inv.LowerRow();
93 Standard_Integer LowerCol = Inv.LowerCol();
94 math_Vector Column(1, LU.UpperRow());
96 Standard_Integer I, J;
97 for(J = 1; J <= LU.UpperRow(); J++) {
98 for(I = 1; I <= LU.UpperRow(); I++) {
102 LU_Solve(LU, Index, Column);
103 for(I = 1; I <= LU.RowNumber(); I++) {
104 Inv(I+LowerRow-1,J+LowerCol-1) = Column(I);
111 void math_Gauss::Dump(Standard_OStream& o) const {
114 o<< " Status = Done \n";
115 o << " Determinant of A = " << D << endl;
118 o << " Status = not Done \n";