From: Mathieu Bouchard Date: 2001-03-16T02:14:51+09:00 Subject: [ruby-talk:12690] Re: Sum of Squares On Tue, 13 Mar 2001, rashworth wrote: > Thank you for your note. The new coding worked just fine. > Do you have some code for the Sum of the Cross-Products? > Sumxy = (x1 * y1) + (x2 * y2) + .... That is called a dot product, not a "sum of cross-products". Unfortunately you can't run two iterators at once easily, but you can still write: class Array def dot(other) # other.type == Array # other.length == self.length sum = 0 length.times {|i| sum += self[i]*other[i] } sum end end (not tested) matju