From: rashworth Date: 2001-03-17T13:34:07+09:00 Subject: [ruby-talk:12761] Re: Sum of Squares Thanks for your code. ERA ---------- Original Message ---------------------------------- From: Mathieu Bouchard Reply-To: ruby-talk@ruby-lang.org Date: Fri, 16 Mar 2001 02:14:51 +0900 >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 > >