waltermilner

Untitled

Aug 19th, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public class Test {
  2.  
  3.   // calculate product to 1000 terms
  4.   static double product(double x) {
  5.     double result = 1.0;
  6.     double pi2 = Math.PI * Math.PI; // pi squared
  7.     for (int n = 1; n < 1000; n++) {
  8.       result *= (1 - x * x / (n * n * pi2));
  9.     }
  10.     return result;
  11.   }
  12.  
  13.   public static void main(String[] args) {
  14.  
  15.     for (double x = 0.1; x<3; x+=0.1) // a range of x values, in radians
  16.     {
  17.     double lhs = Math.sin(x) / x;
  18.     double rhs = product(x);
  19.     System.out.printf("x = %8f, LHS = %8f, RHS = %8f \n",x,lhs,rhs);
  20.     }
  21.  
  22.   }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment