public static final double correlation(double y1[],double y2[],int n){
  int i;
  double av1=0.0, av2=0.0, y11=0.0, y22=0.0, y12=0.0, c;
  if (n <= 1) {
    return 1.0;
  }
  for (i=0; i < n; i++) {
    av1+=y1[i];
    av2+=y2[i];
  }
  av1/=(double)n;
  av2/=(double)n;
  for (i=0; i < n; i++) {
    y11+=(y1[i] - av1) * (y1[i] - av1);
    y22+=(y2[i] - av2) * (y2[i] - av2);
    y12+=(y1[i] - av1) * (y2[i] - av2);
  }
  if (y11 * y22 == 0.0) {
    c=1.0;
  }
 else {
    c=y12 / Math.sqrt(Math.abs(y11 * y22));
  }
  return c;
}

public static final double correlation ( double y1 [ ] , double y2 [ ] , int n ) { int i ; double av1 = 0.0 , av2 = 0.0 , y11 = 0.0 , y22 = 0.0 , y12 = 0.0 , c ; if ( n <= 1 ) { return 1.0 ; } for ( i = 0 ; i < n ; i ++ ) { av1 += y1 [ i ] ; av2 += y2 [ i ] ; } av1 /= ( double ) n ; av2 /= ( double ) n ; for ( i = 0 ; i < n ; i ++ ) { y11 += ( y1 [ i ] - av1 ) * ( y1 [ i ] - av1 ) ; y22 += ( y2 [ i ] - av2 ) * ( y2 [ i ] - av2 ) ; y12 += ( y1 [ i ] - av1 ) * ( y2 [ i ] - av2 ) ; } if ( y11 * y22 == 0.0 ) { c = 1.0 ; } else { c = y12 / Math . sqrt ( Math . abs ( y11 * y22 ) ) ; } return c ; }
returns the correlation coefficient of two double vectors .
