Main Page | Namespace List | Class List | File List | Class Members | File Members

testlapack.cpp

Go to the documentation of this file.
00001 #include<iostream>
00002 #include"SMatrix.h"
00003 #include"SVector.h"
00004 #include"MyBlas.h"
00005 #include"MyLapack.h"
00006 #include"ZVector.h"
00007 #include"ZMatrix.h"
00008 #include<cmath>
00009 #include<stdlib.h>
00010 
00011 using namespace std;
00012 
00013 int main()
00014 {
00015 int ndim=3,lwork;
00016 int info;
00017 
00018 SVector V2;
00019 SMatrix M3;
00020 
00021 V2.allocate(ndim);
00022 M3.allocate(ndim,ndim);
00023 
00024 float sum,*work;
00025 int ipiv[3],ldx;
00026 
00027 srand(1);
00028 
00029 
00030 for(int i=0;i<ndim;i++) 
00031    for(int j=0;j<ndim;j++) 
00032         M3(j,i)=rand()/(float)RAND_MAX;
00033 
00034 ldx=1;
00035 lwork=ndim*ndim*ndim;
00036 work= new float[lwork];
00037 
00038 M3(0,0)=1;
00039 M3(1,1)=5;
00040 M3(2,2)=10;
00041 
00042 info=SSYEV('n','u',M3,V2,work,lwork);
00043 
00044 cout << " Eigenvalues " << V2 << endl;
00045 
00046 cout << " * * * TEST COMPLEX VECTOR * * * " << endl;
00047 
00048 ZVector Z1;
00049 Z1.allocate(3);
00050 Z1(0)=dcmplx(1,3);
00051 Z1(1)=dcmplx(2.5,1.1);
00052 Z1(2)=dcmplx(1.11,0.13);
00053 
00054 cout << " Vector Z1: " << endl;
00055 cout << Z1 << endl;
00056 
00057 cout << " Norm " << Z1.Norm() << endl;
00058 
00059 cout << " AbsoluteSum " << Z1.AbsoluteSum() << endl;
00060 
00061 complex<double> zsum;
00062 zsum=Z1.Sum();
00063 cout << " Sum of the vector elements " << zsum << endl;
00064 
00065 cout << " Element with the largest absolute value " <<  Z1.iMax() << endl;
00066 
00067 ZVector Z2;
00068 Z2.allocate(3);
00069 cout << "\n Test ZCOPY " << endl;
00070 cout << " Vector Z2: " << endl;
00071 Z2=Z1;
00072 cout << Z2 << endl;
00073 
00074 
00075 double rconst=10;
00076 cout << " Set all elements of Z2 to real " << rconst << endl;
00077 Z2=rconst;
00078 cout << Z2 << endl;
00079 complex<double> cconst(10.5,4.5);
00080 cout << " Set all elements  of Z2 to complex value " << cconst << endl;
00081 Z2=cconst;
00082 cout << Z2 << endl;
00083 
00084 cout << " Z1 " << Z1 << endl;
00085 cout << " Z2 " << Z2 << endl;
00086 cout << " Z1 dotu Z2 " << Z1.zdotu(Z2) << endl;
00087 cout << " Z1 dotc Z2 " << Z1.zdotc(Z2) << endl;
00088 
00089 ZVector Z3(3);
00090 
00091 Z3=Z1+Z2;
00092 cout << " Z1 + Z2 = " << Z3 << endl;
00093 
00094 Z3=Z1-Z2;
00095 cout << " Z1 - Z2 = " << Z3 << endl;
00096 
00097 cout << " Test Dscal for  " << cconst << endl;
00098 Z1*=cconst;
00099 
00100 cout << " new Z1 " << Z1 << endl;
00101 
00102 cout << " * * * TEST COMPLEX MATRIX * * * " << endl;
00103 
00104 ZMatrix M1(3,3);
00105 
00106 for(int i=0;i<3;i++)
00107  for(int j=0;j<3;j++)   
00108          M1(i,j)=dcmplx(i*2,j+i/(j+1));
00109 
00110 cout << " M1 :\n" << M1 << endl;
00111 
00112 ZMatrix M2(3,3);
00113 cout << "\n Test ZCOPY " << endl;
00114 M2=M1;
00115 cout << " Matrix M2:\n"<< M2 << endl;
00116 
00117 cout << " Set all elements  of M2 to real value " << rconst << endl;
00118 M2=rconst;
00119 cout << " Matrix M2:\n"<< M2 << endl;
00120 
00121 cout << " Set all elements  of M2 to complex value " << cconst << endl;
00122 M2=cconst;
00123 cout << " Matrix M2:\n"<< M2 << endl;
00124 
00125 cout << " Test Zscal for  " << cconst << endl;
00126 M1*=cconst;
00127 cout << " M1 :\n" << M1 << endl;
00128 
00129 zsum=M1.SumAll();
00130 cout << " Sum all matrix elements " << zsum << endl;
00131 
00132 zsum=M1.Trace();
00133 cout << " Trace of the matrix " << zsum << endl;
00134 
00135 cout << "\n * * * Operation on rows and coloumns * * *" << endl;
00136 cout << " Copy an 1D array into the 3rd row " <<  endl;
00137 cout << " M1 Before :\n" << M1 << endl;
00138 cout << " Vector  :\n" << Z1 << endl;
00139 M1.setrow(2,Z1);
00140 cout << " M1 After :\n" << M1 << endl;
00141 
00142 cout << " Copy an 1D array into the 2nd col " <<  endl;
00143 cout << " M1 Before :\n" << M1 << endl;
00144 cout << " Vector  :\n" << Z1 << endl;
00145 M1.setcol(1,Z1);
00146 cout << " M1 After :\n" << M1 << endl;
00147 
00148 cout << " Rescale a 2nd row for a given complex constant " <<  endl;
00149 cout << " Constant  :\n" << cconst << endl;
00150 M1.row_scale(1,cconst);
00151 cout << " M1 After :\n" << M1 << endl;
00152 
00153 cout << " ZDOT product between the 2nd row and a Vector Z1 " <<  endl;
00154 cout << " M1.rowdotu :" << M1.rowdotu(1,Z1) << endl;
00155 
00156 cout << " Copy  the first row in a vector " <<  endl;
00157 Z1=M1.row(0);
00158 cout << " Vector = :" << Z1 << endl;
00159 
00160 cout << " Sum all elements of a row " <<  endl;
00161 cout << " Sum row 1 = :" << M1.SumRow(0) << endl;
00162 
00163 cout << " Sum of two matricex " <<  endl;
00164 cout << " M1 + M2:\n" << M1+M2 << endl;
00165 
00166 return(0);
00167 }

Generated on Wed Aug 16 19:03:50 2006 for MyLapack by  doxygen 1.4.4