-
Notifications
You must be signed in to change notification settings - Fork 0
/
RealZeta.cpp
41 lines (29 loc) · 927 Bytes
/
RealZeta.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
#include<iostream>
#include<cmath>
#define TYPE double
using namespace std;
int main(int argc, char *argv[]){
int NMAX = 1e6; //max number of terms to include
int a = 1;
int m = 0;
TYPE s;
TYPE q;
TYPE sum =1.0;
TYPE negsum =1.0;
TYPE oldsum = 0.0;
TYPE negoldsum = 0.0;
TYPE tol = 1e-16;
cout<<"Give me the value of s (greater than 1)";
cin>>s;
cout<<"Give me the value of q (greater than 0)";
cin>>q; //NOTE: since we do the negative summation here too if q is an integer it'll go to infinity, but converges for numbers such as 4.2
while( (abs(sum - oldsum)>tol) && (a<NMAX) && (m>(-NMAX)) ){
sum = sum + pow((a + (q - 1)),-s); //(q-1) done in these lines because it's reading the input q as +1 of the intended input
negsum = negsum + pow((m + (q - 1)),-s);
a++;
m--;
}
cout<<"Number of terms used = "<<NMAX<<endl;
cout<<"RealZeta("<<s<<","<<q<<") = "<<(sum - 1) + (negsum - 1)<<endl;
return 0;
}