00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "StGlobals.hh"
00024
00025 #define MATRIX_BOUND_CHECK
00026 #define WITH_ST_THREEVECTOR
00027 #include "StMatrix.hh"
00028
00029 #define SYMMETRIC
00030 #ifndef SYMMETRIC
00031 # define ASYMMETRIC
00032 #endif
00033
00034 #if !defined(ST_NO_NAMESPACES) && !defined(ST_NO_EXCEPTIONS)
00035 using std::logic_error;
00036 #endif
00037
00038 template <class X>
00039 X hold1(X a, unsigned int r, unsigned int q)
00040 {
00041 return a*a;
00042 }
00043
00044
00045 int main()
00046 {
00047 #ifdef SYMMETRIC
00048 StMatrix<StDouble> A(2,2,1);
00049
00050 A(1,1) = 2;
00051 A(1,2) = 1;
00052 A(2,1) = 0;
00053 A(2,2) = 5;
00054
00055 cout << "A=" << A << endl;
00056
00057 StMatrix<StFloat> B(2,2);
00058
00059 B(1,1) = 0;
00060 B(1,2) = 1;
00061 B(2,1) = 1;
00062 B(2,2) = 0;
00063
00064 cout << "-B=" << -B;
00065
00066 StMatrix<StFloat> C(A);
00067
00068 cout << "C=" << C;
00069 cout << "A=" << C;
00070
00071 C+=C;
00072 cout << "C+=C =>" << C << endl;
00073
00074 cout << "C " << C;
00075
00076 C = B+A;
00077 cout << "C=B+A:" << C << endl;
00078
00079 unsigned int ierr;
00080 cout << "B.inverse(ierr)" << B.inverse(ierr) << endl;
00081
00082 StMatrix<StDouble> IDENTITY(2,2,1);
00083
00084 C = B*B.inverse(ierr);
00085
00086 if(C == IDENTITY)
00087 cout << "C=B*B.inverse(ierr) == IDENTITY" << endl;
00088 else
00089 cout << "oops.." << endl;
00090
00091 cout << "1st row of C" << endl;
00092 cout << C.sub(1,1,1,2) << endl;
00093
00094 StMatrix<StDouble> K(3,3,1);
00095 K(1,3) = 2;
00096 K(2,1) = -2;
00097 K(1,3) = -1;
00098
00099 cout << "K=" << K << endl;
00100
00101 StMatrix<double> X(3,3);
00102 for(int ii=1; ii<=3; ii++)
00103 for(int jj=1; jj<=3; jj++)
00104 X(ii,jj) = 1;
00105
00106 StMatrix<float> Y(X);
00107
00108 cout << "X" << X << endl;
00109
00110 cout << "Y+X" << (Y+X) << endl;
00111 cout << "Y*X" << (Y*X) << endl;
00112
00113 #ifdef ST_NO_TEMPLATE_DEF_ARGS
00114 StMatrix<double> TT;
00115 #else
00116 StMatrix<> TT;
00117 #endif
00118 TT = K.apply(hold1);
00119 cout << "square each element of K:=" << TT << endl;
00120
00121 #ifdef ST_NO_TEMPLATE_DEF_ARGS
00122 StThreeVector<double> a(1,1,1);
00123 #else
00124 StThreeVector<> a(1,1,1);
00125 #endif
00126 cout << "StThreeVector a= " << a << endl;
00127 cout << "a*K=" << a*K << endl;
00128 cout << "K*a=" << K*a << endl;
00129
00130 cout << "Testing exception handling." << endl;
00131 cout << "Note that depending on your platform" << endl;
00132 cout << "the resulting actions might differ." << endl;
00133 StMatrix<StDouble> Z(3,3,1);
00134 #ifndef ST_NO_EXCEPTIONS
00135 try {
00136 Z = K*A;
00137 }
00138 catch(logic_error &e){
00139 cout << "Caught exception: " << e.what() << endl;
00140 }
00141 #else
00142 Z = K*A;
00143 #endif
00144
00145 #endif // SYMMETRIC
00146
00147 #ifdef ASYMMETRIC
00148 cout << "TESTING ANTI-SYMMETRIC MATRICES" << endl;
00149 StMatrix<StDouble> A(2,3);
00150
00151 A(1,1) = 2;
00152 A(1,2) = 1;
00153 A(2,1) = 0;
00154 A(2,2) = 5;
00155
00156 cout << "A=" << A << endl;
00157
00158 StMatrix<StFloat> B(3,2);
00159
00160 B(1,1) = 0;
00161 B(1,2) = 1;
00162 B(2,1) = 1;
00163 B(2,2) = 0;
00164
00165 cout << "-B=" << -B;
00166
00167 StMatrix<StFloat> C(A);
00168
00169 cout << "C=" << C;
00170
00171 C+=C;
00172 cout << "C+=C =>" << C << endl;
00173
00174 A*B;
00175 cout << "A*B:" << (A*B) << endl;
00176
00177 cout << "B*A:" << (B*A) << endl;
00178
00179 unsigned int ierr;
00180 cout << "B.inverse(ierr)" << B.inverse(ierr) << endl;
00181
00182 cout << "C=" << C << endl;
00183 cout << "1st row of C" << endl;
00184 cout << C.sub(1,1,1,3) << endl;
00185
00186
00187 #ifdef ST_NO_TEMPLATE_DEF_ARGS
00188 StMatrix<double> TT;
00189 #else
00190 StMatrix<> TT;
00191 #endif
00192 TT = A.apply(hold1);
00193 cout << "square all elements in B:" << B << endl;
00194 #endif
00195 return(0);
00196 }
00197
00198