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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <iostream>
#include <cmath>
#include <string>
#include <stdlib.h>
void tred2(double **a, int n, double *d, double *e);
void tqli(double *d, double *e, int n, double **z);
// defintions of matrices (C/C++ style -- null determined)
template <class T> T** matrix(long nrow, long ncol);
template <class T> void free_matrix(T **m);
double *energies;
int comp (const void *p1, const void *p2);
// **************************** Glavni program ********************************
#include <iomanip>
#include <fstream>
#include <array>
int main(){
using namespace std;
double lambda=0.5;
int NN=0;
ofstream output("A_LV2_convergence_lambda_" + std::to_string(lambda) + ".txt");
streambuf* saved_buffer=cout.rdbuf();
cout.rdbuf(output.rdbuf());
cout.setf(ios::scientific,ios::floatfield);
cout << scientific << setprecision(8);
for (NN=4; NN<100; NN=NN+1)
{
long n = NN, i, j;
double **A = matrix <double> (n,n), // 3x3
*d = new double [n],
*e = new double [n],
*eigsorted = new double [n];
long double H0[NN][NN];
for(int z3 = 0; z3<NN; z3++)
{for (int w3 = 0; w3<NN; w3++){
double delta=0;
if(w3==z3){delta=1.0;}
H0[z3][w3]= (0.5+w3)*delta;
}
}
////////////////////////////////////////////////////////////////////////////////
long double qij[NN][NN];
for(int z1=0;z1<NN;z1++)
{for (int w1=0;w1<NN;w1++){
qij[z1][w1]=0;
if(w1==z1+1){ if (z1==0){qij[z1][w1]=0;}
else {qij[z1][w1] = 0.5*sqrt(w1*2.0); }
}
if(w1==z1-1){ qij[z1][w1] = 0.5*sqrt(2.0*w1+2.0); }
}
}
/////////////////////////////////////////////////////////
long double H[NN][NN];
for(int i1=0; i1<NN; i1++)
{for (int j1=0; j1<NN; j1++)
{H[i1][j1] = H0[i1][j1] + lambda*pow(qij[i1][j1], 4.0);
}
}
for(int i1=0; i1<NN; i1++)
{for (int j1=0; j1<NN; j1++)
{A[i1][j1] = H[i1][j1];}
}
tred2(A, n, d, e);
tqli (d, e, n, A);
int index[NN];
for (int u=0; u<NN;u++)
{index[u]=u;}
energies=d;
qsort(index,NN,sizeof(index[0]), comp);
for (int i=0; i<NN; i++)
{ eigsorted[i]=d[index[i]];
}
cout << NN << " "<< setw(8) <<eigsorted[1] << endl;
delete [] d;
delete [] e;
delete [] lastvr;
free_matrix <double> (A);
}
return EXIT_SUCCESS;
}
// ******************************* Rutines **********************************
template <class T> T** matrix (long nrow, long ncol) {
T **m = new T* [nrow];
m[0] = (T *) new char [nrow*ncol*sizeof(T)];
for( long i = 1; i < nrow; i++) m[i] = m[i-1] + ncol;
return m;
}
template <class T> void free_matrix(T **m) {
delete [] (char*) m[0];
delete [] m;
}
inline double sqr(double f){ return f*f; }
inline double pythag(double a, double b) {
double absa = std::abs(a), absb = std::abs(b);
if (absa > absb) return absa*sqrt(1.0 + sqr(absb/absa));
return (absb == 0.0 ? 0.0 : absb*sqrt(1.0 + sqr(absa/absb)));
}
int comp (const void *p1, const void *p2)
{
int *a, *b;
a = (int*) p1;
b = (int*) p2;
if (energies[*a] > energies[*b])
return 1;
return -1;
}
void tred2(double **a, int n, double *d, double *e) {
...
}
#define sign_(a,b) ((b) >= 0.0 ? std::abs(a) : -std::abs(a))
void tqli(double *d, double *e, int n, double **z) {
...
}
#undef sign_
|