CSharp examples for System:Math Statistics
Calculate Mean And Std Dev
using System.Diagnostics.Contracts; using System.Collections; using System.Text; using System.Linq; using System.Collections.Generic; using System;/*from ww w . java2s .co m*/ public class Main{ public static void CalculateMeanAndStdDev(this IEnumerable<double> numbers, out double mean, out double stdDev) { Contract.Requires(numbers != null); mean = 0.0; double sumOfDerivation = 0.0; double count = 0.0; foreach (double value in numbers) { sumOfDerivation += (value) * (value); mean += value; count++; } mean /= count; double sumOfDerivationAverage = sumOfDerivation / count; stdDev = Math.Sqrt(sumOfDerivationAverage - (mean * mean)); } }