5 #ifndef _SQUAREMATRIX_H_
6 #define _SQUAREMATRIX_H_
47 for(
int i=1;i<
_order+1;i++)
50 s[i-1]=
fabs((*
this)(i,1));
51 for(
int j=2;j<_order+1;j++)
53 if(s[i-1]<
fabs((*
this)(i,j)))
54 s[i-1]=
fabs((*
this)(i,j));
58 cout<<
"Row: "<<i<<endl;
73 T rmax=
fabs((*
this)(l[i-1],i)/s[l[i-1]-1]);
76 for(
int j=i+1;j<_order+1;j++)
78 T r=
fabs((*
this)(l[j-1],i)/s[l[j-1]-1]);
96 for(
int j=i+1;j<_order+1;j++)
98 T factor=LU(l[j-1],i)/LU(l[i-1],i);
100 bVec[l[j-1]-1]-=factor*bVec[l[i-1]-1];
101 for(
int k=i+1;k<_order+1;k++)
103 LU(l[j-1],k)-=LU(l[i-1],k)*factor;
105 if(isnan(test)||isinf(test))
107 cout<<
"Denom: "<<LU(l[i-1],i)<<endl;
108 cout<<
"Num: "<<LU(l[j-1],i)<<endl;
109 cout<<
"first: "<<LU(l[j-1],k)<<endl;
110 cout<<
"second: "<<LU(l[i-1],k)<<endl;
111 cout<<
"factor: "<<factor<<endl;
112 cout<<
"test: "<<test<<endl;
129 for(
int j=i+1;j<_order+1;j++)
133 bVec[
_pivotRows[j-1]-1]-=factor*bVec[_pivotRows[i-1]-1];
134 for(
int k=i+1;k<_order+1;k++)
136 LU(_pivotRows[j-1],k)=LU(_pivotRows[j-1],k)
137 -LU(_pivotRows[i-1],k)*factor;
148 for(
int i=
_order-1;i>0;i--)
151 for(
int j=i+1;j<
_order+1;j++)
152 sum-=LU(_pivotRows[i-1],j)*bVec[_pivotRows[j-1]-1];
153 bVec[_pivotRows[i-1]-1]+=sum;
154 bVec[_pivotRows[i-1]-1]=bVec[_pivotRows[i-1]-1]/LU(_pivotRows[i-1],i);
160 bVec[i]=bCpy[_pivotRows[i]-1];
166 if(o.
_order!=this->_order)
167 throw CException(
"Cannot copy matrices of different sizes!");
177 for(
int i=1;i<
_order+1;i++)
179 for(
int j=1;j<_order+1;j++)
180 cout<<(*
this)(i,j)<<
" ";
189 for(
int i=1;i<
_order+1;i++)
190 trace+=
fabs((*
this)(i,i));
201 for(
int i=1;i<
_order+1;i++)
202 for(
int j=1;j<_order+1;j++)
203 b[i-1]+=(*
this)(i,j)*x[j-1];
206 throw CException(
"Array length does not match matrix order!");
214 cout<<
"Correct Solution:"<<endl;
218 cout<<
"x["<<i<<
"]="<<x[i]<<endl;
223 cout<<
"Before"<<endl;
225 cout<<
"b["<<i<<
"]="<<b[i]<<endl;
231 cout<<
"b["<<i<<
"]="<<b[i]<<endl;
236 cout<<
"b["<<i<<
"]="<<b[i]-x[i]<<endl;
void multiply(const TArray &x, TArray &b)
void makeCopy(SquareMatrix< T > &o)
NumTypeTraits< T >::T_Scalar T_Scalar
shared_ptr< TArray > TArrPtr
T & operator()(const int i, const int j)
T & getElement(const int i, const int j)
Tangent fabs(const Tangent &a)
SquareMatrix(const int N)