Repository navigation
Expand file tree
/
Copy pathcdw_infinite.cpp
More file actions
146 lines (133 loc) · 3.22 KB
/
Copy pathcdw_infinite.cpp
File metadata and controls
146 lines (133 loc) · 3.22 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#define PI acos(-1.0)
using namespace std;
struct Parameters
{
double g, K, V;
Parameters(double g, double K, double V)
{
this->g = g;
this->K = K;
this->V = V;
}
};
double square(double a)
{
return a*a;
}
double Gaussian(double epsilon)
{
return exp(-epsilon*epsilon)/sqrt(PI);
}
double integrand(const Parameters &p, double beta, double epsilon, double Delta)
{
double g, K, V;
g = p.g;
K = p.K;
V = p.V;
double one, two;
double result;
one = (1/sqrt(epsilon*epsilon + Delta*Delta) - 1/sqrt(epsilon*epsilon + Delta*Delta + 4*V*V))*tanh(0.25*beta*(sqrt(epsilon*epsilon + Delta*Delta) - sqrt(epsilon*epsilon + Delta*Delta + 4*V*V)));
two = (1/sqrt(epsilon*epsilon + Delta*Delta) + 1/sqrt(epsilon*epsilon + Delta*Delta + 4*V*V))*tanh(0.25*beta*(sqrt(epsilon*epsilon + Delta*Delta) + sqrt(epsilon*epsilon + Delta*Delta + 4*V*V)));
result = 2*g*g/K*(one + two)*Gaussian(epsilon);
return result;
}
double f(const Parameters &p, double beta, double Delta)
{
double s;
double upper;
double lower;
double denergy;
int Nenergy, ienergy;
double energy;
upper = 8;
lower = -upper;
Nenergy = 800;
denergy = (upper - lower)/Nenergy;
s = 0;
for (ienergy = 0; ienergy <= Nenergy; ++ienergy)
{
energy = lower + ienergy*denergy;
s = s + denergy*integrand(p, beta, energy, Delta);
}
s = s - 1;
return s;
}
double fprime(const Parameters &p, double beta, double Delta)
{
double dDelta = 0.00001;
return (f(p, beta, Delta + dDelta) - f(p, beta, Delta))/dDelta;
}
double newton(double (*f)(const Parameters &p, double beta, double Delta), const Parameters &p, double beta)
{
double x0 = 3.0;
double x1 = x0 - f(p, beta, x0)/fprime(p, beta, x0);
int count = 0;
int iterationMax = 8;
while(fabs(x0 - x1) > 0.001)
{
count++;
x0 = x1;
x1 = x0 - f(p, beta, x0)/fprime(p, beta, x0);
if (count > iterationMax)
{
cout << "No solution found. " << endl;
return -1;
}
}
return x1;
}
int main(int argc, char **argv)
{
double g, K, V;
double beta;
g = 1;
K = 1;
V = 1;
if (false)
{
double Delta;
double x0, x1;
int N = 100;
x0 = 0;
x1 = 6;
double dx = (x1 - x0)/N;
Parameters p(g,K,V);
beta = 1000;
ofstream ofile;
ofile.open("f.txt");
for (int i = 0; i <= N; ++i)
{
Delta = x0 + (i+0.5)*dx;
ofile << Delta << " " << f(p, beta, Delta) << endl;
}
ofile.close();
return 0;
}
if (true)
{
V = 2.366;
double T0, T1;
double dT;
int NT;
vector<double> T;
T0 = 0.951;
T1 = 1.03;
NT = 40;
dT = (T1 - T0)/NT;
for (int i = 0; i <= NT; ++i)
{
T.push_back(T0 + (i+0.5)*dT);
}
Parameters p(g, K, V);
for (int i = 0; i <= NT; ++i)
{
beta = 1.0/T[i];
cout << T[i] << " " << newton(f, p, beta) << endl;
}
}
return 0;
}