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.
18 #define No_Standard_RangeError
19 #define No_Standard_OutOfRange
20 #define No_Standard_DimensionError
23 #include <math_Crout.ixx>
24 #include <math_NotSquare.hxx>
25 #include <StdFail_NotDone.hxx>
26 #include <math_Vector.hxx>
28 math_Crout::math_Crout(const math_Matrix& A, const Standard_Real MinPivot):
29 InvA(1, A.RowNumber(), 1, A.ColNumber())
31 Standard_Integer i,j,k;
32 Standard_Integer Nctl = A.RowNumber();
33 Standard_Integer lowr = A.LowerRow(), lowc = A.LowerCol();
36 math_Matrix L(1, Nctl, 1, Nctl);
37 math_Vector Diag(1, Nctl);
41 math_NotSquare_Raise_if(Nctl != A.ColNumber(), " ");
44 for (i =1; i <= Nctl; i++) {
45 for (j = 1; j <= i -1; j++) {
47 for (k = 1; k <= j-1; k++) {
48 scale += L(i,k)*L(j,k)*Diag(k);
50 L(i,j) = (A(i+lowr-1,j+lowc-1)-scale)/Diag(j);
53 for (k = 1; k <= i-1; k++) {
54 scale += L(i,k)*L(i,k)*Diag(k);
56 Diag(i) = A(i+lowr-1,i+lowc-1)-scale;
58 if (Abs(Diag(i)) <= MinPivot) {
59 Done = Standard_False;
65 // Calcul de l inverse de L:
66 //==========================
69 for (i = 2; i <= Nctl; i++) {
70 for (k = 1; k <= i-1; k++) {
72 for (j = k; j <= i-1; j++) {
73 scale += L(i,j)*L(j,k);
75 L(i,k) = -scale/L(i,i);
80 // Calcul de l inverse de Mat:
81 //============================
83 for (j = 1; j <= Nctl; j++) {
84 scale = L(j,j)*L(j,j)/Diag(j);
85 for (k = j+1; k <= Nctl; k++) {
86 scale += L(k,j) *L(k,j)/Diag(k);
89 for (i = j+1; i <= Nctl; i++) {
90 scale = L(i,j) *L(i,i)/Diag(i);
91 for (k = i+1; k <= Nctl; k++) {
92 scale += L(k,j)*L(k,i)/Diag(k);
102 void math_Crout::Solve(const math_Vector& B, math_Vector& X) const
104 StdFail_NotDone_Raise_if(!Done, " ");
105 Standard_DimensionError_Raise_if((B.Length() != InvA.RowNumber()) ||
106 (X.Length() != B.Length()), " ");
108 Standard_Integer n = InvA.RowNumber();
109 Standard_Integer lowb = B.Lower(), lowx = X.Lower();
110 Standard_Integer i, j;
112 for (i = 1; i <= n; i++) {
113 X(i+lowx-1) = InvA(i, 1)*B(1+lowb-1);
114 for ( j = 2; j <= i; j++) {
115 X(i+lowx-1) += InvA(i, j)*B(j+lowb-1);
117 for (j = i+1; j <= n; j++) {
118 X(i+lowx-1) += InvA(j,i)*B(j+lowb-1);
123 void math_Crout::Dump(Standard_OStream& o) const
127 o << " Status = Done \n";
130 o << " Status = not Done \n";