00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define _NMBFMT std::setw(12) <<
00023
00024 #include <iostream>
00025 #include <cmath>
00026 #include <cassert>
00027
00028 #include "linalg/lawrap.h"
00029 #include "linalg/matrix.h"
00030 #include "linalg/vector.h"
00031 #include "linalg/jacobirot.h"
00032
00033 using namespace std;
00034 using namespace LinAlg;
00035
00036 void FillEigenProjs(Matrix<REAL> const & Q, int N, Matrix<REAL> P[])
00037 {
00038 assert(Q.Rows()==N);
00039 assert(Q.Cols()==N);
00040 for (int k=0; k<N; ++k)
00041 for (int i=0; i<N; ++i)
00042 for (int j=0; j<N; ++j)
00043 P[k](i,j) = Q(i,k) * Q(j,k);
00044 }
00045
00046 int main()
00047 {
00048
00049 Matrix<REAL> A(3,3,"4 5 6 5 8 7 6 7 9");
00050 Matrix<REAL> Q(3,3);
00051 Vector<REAL> v(3);
00052 Matrix<REAL> TMP(3,3);
00053 Matrix<REAL> * P = new Matrix<REAL> [3];
00054 for (int i=0; i<3; ++i) P[i].Set(3,3);
00055
00056 cout << "A = \n" << A << std::endl;
00057
00058 cout << "\n=========================================== JacobiRot Function\n";
00059
00060 Matrix<REAL> AA(3,3); AA=A;
00061 int itrs = Sym::JacobiRot(A,Q,v);
00062 cout << "Iterations = " << itrs << endl;
00063 cout << "A = \n" << A << endl;
00064 cout << "Q = \n" << Q << endl;
00065 cout << "v = \n" << v << endl;
00066
00067 FillEigenProjs(Q,3,P);
00068 TMP.SetValues(0.0);
00069 for (int i=0; i<3; ++i)
00070 for (int j=0; j<3; ++j)
00071 TMP(i,j) = TMP(i,j) + v(0)*P[0](i,j)
00072 + v(1)*P[1](i,j)
00073 + v(2)*P[2](i,j);
00074 cout << "Sum{eigenvals * eigenprojs} = \n" << TMP << endl;
00075
00076 #ifdef USE_LAPACK
00077 cout << "\n=========================================== using LAPACK\n";
00078
00079 A=AA;
00080 Syevr(A,v,Q);
00081 cout << "A = \n" << A << endl;
00082 cout << "v = \n" << v << endl;
00083 cout << "Q = \n" << Q << endl;
00084
00085 FillEigenProjs(Q,3,P);
00086 TMP.SetValues(0.0);
00087 for (int i=0; i<3; ++i)
00088 for (int j=0; j<3; ++j)
00089 TMP(i,j) = TMP(i,j) + v(0)*P[0](i,j)
00090 + v(1)*P[1](i,j)
00091 + v(2)*P[2](i,j);
00092 cout << "Sum{eigenvals * eigenprojs} = \n" << TMP << endl;
00093 #endif
00094
00095 delete [] P;
00096 return 0;
00097 }