Menu

[r31]: / trunk / test / zhematrix / zhematrix-lapack / zheev_check.cpp  Maximize  Restore  History

Download this file

112 lines (91 with data), 2.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
//=============================================================================
void zheev_check_value()
{
cout << "############ check zheev value ############" << endl;
srand(time(NULL));
int N(3);
//// make zhematrix A ////
CPPL::zhematrix A(N);
for(int i=0; i<A.n; i++){
for(int j=0; j<i; j++){
A(i,j) =complex<double>(rand()/(RAND_MAX/10), rand()/(RAND_MAX/10));
}
A(i,i) =complex<double>(rand()/(RAND_MAX/10), 0.0);
}
//// make w ////
vector<double> w;
//// make A_original ////
CPPL::zhematrix A_original(A);
//// zheev ////
A.zheev(w);
//A.zheev(w,1);
//// print ////
cout << "A=\n" << A << endl;
cout << "A_original=\n" << A_original << endl;
for(int i=0; i<N; i++){
cout << "#### " << i << "th eigen ####" << endl;
cout << "w=" << w[i] <<endl;
}
}
//=============================================================================
void zheev_check_right()
{
cout << "############ check zheev right ############" << endl;
srand(time(NULL));
int N(3);
//// make zhematrix A ////
CPPL::zhematrix A(N);
for(int i=0; i<A.n; i++){
for(int j=0; j<i; j++){
A(i,j) =complex<double>(rand()/(RAND_MAX/10), rand()/(RAND_MAX/10));
}
A(i,i) =complex<double>(rand()/(RAND_MAX/10), 0.0);
}
//// make wr wi vr ////
vector<double> w;
vector<CPPL::zcovector> v;
//// make A_original ////
CPPL::zhematrix A_original(A);
//// zheev ////
A.zheev(w,v);
//// print ////
cout << "A_original=\n" << A_original << endl;
for(int i=0; i<A.n; i++){
cout << "#### " << i << "th eigen ####" << endl;
cout << "w=" << w[i] <<endl;
cout << "v=\n" << v[i] <<endl;
cout << "[A]*{x} -lambda*{x} = (Should be zeros)\n"
<< A_original*v[i] -w[i]*v[i] << endl;
}
}
//=============================================================================
void zheev_check_left()
{
cout << "############ check zheev left ############" << endl;
srand(time(NULL));
int N(3);
//// make zhematrix A ////
CPPL::zhematrix A(N);
for(int i=0; i<A.n; i++){
for(int j=0; j<i; j++){
A(i,j) =complex<double>(rand()/(RAND_MAX/10), rand()/(RAND_MAX/10));
}
A(i,i) =complex<double>(rand()/(RAND_MAX/10), 0.0);
}
//// make wr wi vl ////
vector<double> w;
vector<CPPL::zrovector> v;
//// make A_original ////
CPPL::zhematrix A_original(A);
//// zheev ////
A.zheev(w, v);
//// print ////
cout << "A_original=\n" << A_original << endl;
for(int i=0; i<A.n; i++){
cout << "#### " << i << "th eigen ####" << endl;
cout << "w = " << w[i] << endl;
cout << "v = " << v[i] << endl;
cout << "{x}*[A] -{x}*lambda = (Should be zeros)\n"
<< v[i]*A_original -v[i]*w[i] << endl;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.