-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirichlet.cpp
60 lines (50 loc) · 1.45 KB
/
dirichlet.cpp
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
#include <iostream>
#include <iomanip>
#include <complex>
#include <cmath>
using std::complex;
complex<double> dirichlet(complex<double> s, int terms)
{
complex<double> z = 0;
for (int n = 1; n < terms; n++)
{
double d = (double)n;
z += d / pow(d + 1.0, s);
z -= (d - s) / pow(d, s);
}
z /= (s - 1.0);
return z;
}
int main()
{
using namespace std;
cout << fixed << setprecision(14);
complex<double> z(1, 2);
cout << "(1,2)^2 = " << pow(z, 2) << '\n';
complex<double> z2(-1, 0); // square root of -1
cout << "-1^0.5 = " << pow(z2, 0.5) << '\n';
complex<double> z3(-1, -0.0); // other side of the cut
cout << "(-1, -0)^0.5 = " << pow(z3, 0.5) << '\n';
complex<double> i(0, 1); // i^i = exp(-pi/2)
cout << "i^i = " << pow(i, i) << '\n';
double step = 0.0001d;
double multiplier = 10000.0;
int lastSign = true;
for (double t = 14.134; t < 50.0; t += step)
{
t = ceil(t * multiplier) / multiplier;
complex<double> z4(0.5, t);
complex<double> zeta = dirichlet(z4, 100000000);
cout << "zeta" << z4 << " = " << zeta << "\tphase: " << arg(zeta) << endl;
int _sign = signbit(arg(zeta));
if (_sign != lastSign)
{
t -= step;
step /= 10.0d;
multiplier *= 10.0;
lastSign = !_sign;
cout << "-------------------" << endl;
}
}
return 0;
}