1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
22 #define No_Standard_RangeError
23 #define No_Standard_OutOfRange
24 #define No_Standard_DimensionError
27 #include <math_Crout.ixx>
28 #include <math_NotSquare.hxx>
29 #include <StdFail_NotDone.hxx>
30 #include <math_Vector.hxx>
32 math_Crout::math_Crout(const math_Matrix& A, const Standard_Real MinPivot):
33 InvA(1, A.RowNumber(), 1, A.ColNumber())
35 Standard_Integer i,j,k;
36 Standard_Integer Nctl = A.RowNumber();
37 Standard_Integer lowr = A.LowerRow(), lowc = A.LowerCol();
40 math_Matrix L(1, Nctl, 1, Nctl);
41 math_Vector Diag(1, Nctl);
45 math_NotSquare_Raise_if(Nctl != A.ColNumber(), " ");
48 for (i =1; i <= Nctl; i++) {
49 for (j = 1; j <= i -1; j++) {
51 for (k = 1; k <= j-1; k++) {
52 scale += L(i,k)*L(j,k)*Diag(k);
54 L(i,j) = (A(i+lowr-1,j+lowc-1)-scale)/Diag(j);
57 for (k = 1; k <= i-1; k++) {
58 scale += L(i,k)*L(i,k)*Diag(k);
60 Diag(i) = A(i+lowr-1,i+lowc-1)-scale;
62 if (Abs(Diag(i)) <= MinPivot) {
63 Done = Standard_False;
69 // Calcul de l inverse de L:
70 //==========================
73 for (i = 2; i <= Nctl; i++) {
74 for (k = 1; k <= i-1; k++) {
76 for (j = k; j <= i-1; j++) {
77 scale += L(i,j)*L(j,k);
79 L(i,k) = -scale/L(i,i);
84 // Calcul de l inverse de Mat:
85 //============================
87 for (j = 1; j <= Nctl; j++) {
88 scale = L(j,j)*L(j,j)/Diag(j);
89 for (k = j+1; k <= Nctl; k++) {
90 scale += L(k,j) *L(k,j)/Diag(k);
93 for (i = j+1; i <= Nctl; i++) {
94 scale = L(i,j) *L(i,i)/Diag(i);
95 for (k = i+1; k <= Nctl; k++) {
96 scale += L(k,j)*L(k,i)/Diag(k);
101 Done = Standard_True;
106 void math_Crout::Solve(const math_Vector& B, math_Vector& X) const
108 StdFail_NotDone_Raise_if(!Done, " ");
109 Standard_DimensionError_Raise_if((B.Length() != InvA.RowNumber()) ||
110 (X.Length() != B.Length()), " ");
112 Standard_Integer n = InvA.RowNumber();
113 Standard_Integer lowb = B.Lower(), lowx = X.Lower();
114 Standard_Integer i, j;
116 for (i = 1; i <= n; i++) {
117 X(i+lowx-1) = InvA(i, 1)*B(1+lowb-1);
118 for ( j = 2; j <= i; j++) {
119 X(i+lowx-1) += InvA(i, j)*B(j+lowb-1);
121 for (j = i+1; j <= n; j++) {
122 X(i+lowx-1) += InvA(j,i)*B(j+lowb-1);
127 void math_Crout::Dump(Standard_OStream& o) const
131 o << " Status = Done \n";
134 o << " Status = not Done \n";