Rieman Zeta Function Program?

Hello All, I realize this problem in particular will be difficult to answer for anyone without a strong math backround, so if you're looking to help out someone, give it a try. This program is designed to take a complex input, and apply it to the Zeta Function, and output the result. (Obviously it doesnt take the infinite sum, so i set it to go to 1000000 and output to 10 decimal places)

Okay so Here is the problem: The function works perfectly well for value's a + bi where a is any number greater than 1 but as soon as a is less than 1 it gives me a completely wrong answer. Does anyone know how i might fix this? Or if not does anyone have a link to reimans analytic continuation of the function? I know its a vague question but anything helps!

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
#include <iostream>
#include <math.h>   //Logs and trig
#include <stdlib.h> 
#include <iomanip> //For cout precision
#include <complex> //Put it in before, but realized i dont need it (yet)

using namespace std;

int main(){
double real;  //Real Part
double realsum = 0;
double imag;  //Imaginary Part
double imagsum = 0;
double theta;  //Argument
double n;      //Loop
double mag;    //Magnitude
char PlusMinus;   //If negative
#define Pi 3.14159265 //Define PI
std::cout.precision(10);

cout << "Enter a complex number in the form of a + bi" << endl;
cin >> real;
cin >> PlusMinus;
cin >> imag;


theta = atan(imag/real);
mag = sqrt(((pow(imag, 2)) + (pow(real, 2))));

real = real * -1;

for (n = 1; n < 1000000; n++)
{realsum = realsum + (pow(n, real) * cos(imag*log(n)));
imagsum = imagsum + (pow(n, real) * sin(imag*log(n)));
}
//I know there are a few problems with angles at multiples of pi ill fix it later
cout << "Zeta(" << mag << "e^"<< theta << ") is: " << endl;
if (PlusMinus == '+')
cout << realsum << " + " << imagsum <<"i" << endl;
else 
cout << realsum << " - " << imagsum <<"i" << endl;


return 0;
}

(Sorry for sloppy commenting i just added it while posting this)
Topic archived. No new replies allowed.