Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Standard Deviation

DZone's Guide to

Standard Deviation

·
Free Resource

#!/usr/bin/ruby -w

include Math

# werte, für die die standardabweichung berechnet werden soll
arrValues = [ 4.58, 4.53, 4.1, 4.05 ]

# mittelwert der werte
fMedian = 0
arrValues.each do |fValue|
fMedian += fValue
end
fMedian /= arrValues.size.to_f
puts "Mittelwert = " + fMedian.to_s

# summieren
fStandardDeviation = 0
arrValues.each do |fValue|
fStandardDeviation += (fValue - fMedian)**2
end
puts "Zwischensumme = " + fStandardDeviation.to_s

# durch anzahl teilen
fStandardDeviation /= arrValues.size.to_f
puts fStandardDeviation

# wurzel ziehen
fStandardDeviation = Math.sqrt(fStandardDeviation)

# auf 3 stellen runden
fStandardDeviation = "%.3f" % fStandardDeviation

puts "rating = " + fStandardDeviation.to_s

Resources: blog.cadego.de
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}