Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/array.rb

Instance Method Summary collapse

Instance Method Details

#covarianceObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/array.rb', line 3

def covariance
  sx, sy, sp = 0.0, 0.0, 0.0
  return sx if empty?
target = first.respond_to?(:to_ary) ? self :
self.class.new(size) { |i| [i + 1, at(i)] }
target.each { |x, y|
  sx += x
  sy += y
  sp += x * y
}
(sp - sx * sy / size) / size
end