-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
81 lines (63 loc) · 1.86 KB
/
example.cpp
File metadata and controls
81 lines (63 loc) · 1.86 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
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <time.h>
#include "matrix.h"
using namespace std;
int nspin;
Matrix< complex<double> > sigmaX(2,2);
Matrix< complex<double> > sigmaY(2,2);
Matrix< complex<double> > sigmaZ(2,2);
Matrix< complex<double> > eye(2,2);
Matrix< complex<double> > *interaction12=new Matrix< complex<double> >;
Matrix< complex<double> > *interaction23=new Matrix< complex<double> >;
Matrix< complex<double> > *Ham=new Matrix< complex<double> >;
double J;
int main(int argc, char *argv[])
{
// Define the Pauli matrices
sigmaX[0][0]=0;
sigmaX[0][1]=1;
sigmaX[1][0]=1;
sigmaX[1][1]=0;
sigmaY[0][0]=0;
sigmaY[0][1]=(0,-1);
sigmaY[1][0]=(0,1);
sigmaY[1][1]=0;
sigmaZ[0][0]=1;
sigmaZ[0][1]=0;
sigmaZ[1][0]=0;
sigmaZ[1][1]=-1;
eye[0][0]=1;
eye[0][1]=0;
eye[1][0]=0;
eye[1][1]=1;
cout<<"SigmaX\n";
cout<<sigmaX<<'\n';
cout<<"SigmaY\n";
cout<<sigmaY<<'\n';
cout<<"SigmaZ\n";
cout<<sigmaZ<<'\n';
// The product of sigmaX and sigmaY is sigmaZ
cout<<"The product of sigmaX and sigmaY is sigmaZ\n";
cout<<sigmaX*sigmaY<<'\n';
// Form a three-spin Heisenberg chain with coupling constant J
// interaction term between spins 1 and 2
*interaction12 = KroneckerProduct(KroneckerProduct(sigmaX, sigmaX), eye);
// interaction term between spins 2 and 3
*interaction23 = KroneckerProduct(eye, KroneckerProduct(sigmaX, sigmaX));
// total Hamiltonian
J=0.5;
*Ham = J*(*interaction12 + *interaction23);
cout<<"Hamiltonian:\n";
cout<<*Ham<<'\n';
complex<double>* e = new complex<double>[(*Ham).columnsize()];
EigHValues(*Ham, e, "hermitian");
cout<<"Eigenvalues of the Hamiltonian:\n";
for(int ei=0; ei<(*Ham).columnsize(); ei++)
cout<<e[ei]<<'\n';
}