Platinum Partner

Standard Deviation


#!/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
{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}