-
Notifications
You must be signed in to change notification settings - Fork 0
/
zeta.h
97 lines (97 loc) · 2.69 KB
/
zeta.h
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
#ifndef __ZETA__
#define __ZETA__
#include <cmath>
typedef struct complex{
double re;
double im;
}complex;
class Zeta{
public:
Zeta(){
temp.im=0;
temp.re=0;
temp2.im=0;
temp.re=0;
zeta_output.re=0;
zeta_output.im=0;
}
Zeta(complex input){
zeta_input=input;
temp.im=0;
temp.re=0;
temp2.im=0;
temp.re=0;
zeta_output.re=0;
zeta_output.im=0;
}
void set_n(int n_term){
if (n_term<1000)
n_term=1000;
n=n_term;
return;
}
void init(complex input){
zeta_input=input;
temp.im=0;
temp.re=0;
temp2.im=0;
temp.re=0;
zeta_output.re=0;
zeta_output.im=0;
}
void make(){
make_zeta();
return;
}
complex get_value(){
return zeta_output;
}
private:
complex zeta_input;
complex temp;
complex temp2;
complex zeta_output;
int n=5000; //5000 terminos
void make_zeta(){
temp=factor(zeta_input);
temp2=eta_sum(zeta_input);
zeta_output.im= temp.re*temp2.re-temp.im*temp2.im;
zeta_output.re= temp.re*temp2.im+temp.im*temp2.re;
return;
}
complex factor(complex input){
complex out;
double den=cos(input.im * log(2.0));
den*=pow(2.0, 1.0-input.re);
den=1.0-den;
den*=den;
double den2=sin(input.im*log(2.0));
den2*=den2;
den2*=pow(2.0,2.0-2.0*input.re);
out.re=(1.0-pow(2.0,1.0-input.re)*cos(input.im*log(2.0)))/(den+den2);
out.im=-(pow(2.0,1.0-input.re)*sin(input.im*log(2.0)))/(den+den2);
return out;
}
double cast_d(unsigned int i){
return static_cast<double>(i);
}
complex eta_sum(complex input){
double temp=0.0;
double temp2=0.0;
double uno_t=1.0;
double theta;
double bottom;
for (size_t i=1; i<=n; i++){
theta=input.im*log(cast_d(i));
bottom=pow(cast_d(i),input.re);
temp+=(uno_t*cos( theta ))/bottom;
temp2+=(uno_t*sin( theta ))/bottom;
uno_t*=(-1.0);
}
complex out;
out.re=temp;
out.im=-temp2;
return out;
}
};
#endif