sandeshMC

CSM EXP 7

Apr 10th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. class ACT {
  5.  
  6.     static double[] LCR(int n) {
  7.         double x[] = new double[n];
  8.         int a = 25678;
  9.         int m = 25671;
  10.         int c = 24123;
  11.         int seed = 4;
  12.         x[0] = seed;
  13.         for (int i = 1; i < n; i++) {
  14.             x[i] = ((a * x[i - 1] + c) % m) / 100000.0;
  15.         }
  16.         return x;
  17.  
  18.     }
  19.  
  20.     public static void main(String args[]) {
  21.         Scanner sc = new Scanner(System.in);
  22.         double rn[] = LCR(100);
  23.         System.out.println("hello");
  24.         int length_rn = 100;
  25.         System.out.println("Enter i");
  26.         int a = sc.nextInt();
  27.         System.out.println("Enter l");
  28.         int l = sc.nextInt();
  29.  
  30.         System.out.println("Enter Zcrit");
  31.         double zcrit = sc.nextDouble();
  32.         int i;
  33.         for (i = 0; i <= length_rn; i++) {
  34.             int leq = a + (i + 1) * l;
  35.             if (leq > length_rn) {
  36.                 break;
  37.             }
  38.         }
  39.         int M = i - 1;
  40.  
  41.         double sum_act = 0;
  42.         for (i = a; i < (a + M); i++) {
  43.             //System.out.println(rn[i]+"at"+i+"  "+rn[i+1]);
  44.             sum_act += rn[i] * rn[i + 1];
  45.         }
  46.         double p = (sum_act / (M + 1)) - 0.25;
  47.  
  48.         double sigma = Math.sqrt(13 * M + 7) / (12 * (M + 1));
  49.  
  50.         double z0 = p / sigma;
  51.         if (zcrit >= z0) {
  52.             System.out.println("It passes auto correlation test");
  53.         } else {
  54.             System.out.println("It fails auto correlation test");
  55.         }
  56.     }
  57.  
  58. }
  59.  
  60. /*OUTPUT
  61. Enter i
  62. 3
  63. Enter l
  64. 19
  65. Enter Zcrit
  66. 0.25
  67. -1.8741290699558104
  68. It passes correlation test
  69.  
  70. */
Add Comment
Please, Sign In to add comment