Standard Deviation

This algorithm calculates the standard deviation of the given set of numbers.



									Public Shared Function StandardDeviation(data As Double()) As Double
	Dim mean As Double = 0.0
	Dim sumDeviation As Double = 0.0
	Dim dataSize As Integer = data.Length

	For i As Integer = 0 To dataSize - 1
		mean += data(i)
	Next

	mean = mean / dataSize

	For i As Integer = 0 To dataSize - 1
		sumDeviation += (data(i) - mean) * (data(i) - mean)
	Next

	Return Math.Sqrt(sumDeviation / dataSize)
End Function
								


Example

									Dim data As Double() = {13, 23, 12, 44, 55}
Dim standardDeviationVal As Double = StandardDeviation(data)
								


Output

									17.21162397916013