From: jogloran Date: 2006-08-02T20:03:18+09:00 Subject: Re: Scientific calculation: get Std.Dev for a integer array class Array def sd(ar) n = length sum_sq = inject(0.0) {|accu, v| accu + v*v} sum = inject(0.0) {|accu, v| accu + v} Math.sqrt((sum_sq - sum*sum/n) / (n-1)) end end On 8/2/06, Sander Land wrote: > On 8/2/06, Wang Austin-W22255 wrote: > > Hi Ruby Gurus, > > > > Could you please point me how to do some scientific calculation in Ruby: > > > > 1) How to calculate std.dev for an integer array? > > 2) Is there a log() function in Ruby? > > > > Thank you! > > Austin > > 1) I don't think there's a builtin function for that, so you'll have > to create your own. > You'll probably want to add it to the Array class. > class Array > def stddev > # your function here > end > end > > You could also check rubyforge.org, maybe there's a statistics library > available there. > > 2) Math.log > >