Advertisement
apexsquirt

[C++] Riemann zeta function (first real C++ program)

Sep 18th, 2019
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <bits/stdc++.h>
  4.  
  5. double reZeta (double s, double t = 0, int lim = 1000) {
  6.     double re; int i;
  7.     for (i = 1; i <= lim; i++) {
  8.         re += pow(i,-s)*cos(t*log(i));
  9.     }
  10.     re += ((s-1)*cos(t*log(lim))+(-t)*sin(t*log(lim)))*pow(lim,1-s)/((1-s)*(1-s)+t*t);
  11.     return re;
  12. }
  13.  
  14. double imZeta (double s, double t = 0, int lim = 1000) {
  15.     double im; int i;
  16.     for (i = 1; i <= lim; i++) {
  17.         im -= pow(i,-s)*sin(t*log(i));
  18.     }
  19.     im += ((-t)*cos(t*log(lim))-(s-1)*sin(t*log(lim)))*pow(lim,1-s)/((1-s)*(1-s)+t*t);
  20.     return im;
  21. }
  22.  
  23. int main () {
  24.     double s; double t;
  25.     std::cout << "ΞΆ(z)" << std::endl;
  26.     while (s != 1 or t != 0) {
  27.         std::cout << "Input consecutively the real and imaginary parts" << std::endl;
  28.         std::cin >> s >> t;
  29.         if (s == 1 and t == 0) {
  30.             break;
  31.         }
  32.         std::cout << "ΞΆ(" << s << "+" << t << "i" << ") β‰ˆ " << reZeta(s,t) << "+" << imZeta(s,t) << "i" << std::endl;
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement