.NET ez 2012-11-11
只需將數字存入 List 帶入 Function 即可計算出結果。
/// <summary> /// 標準差(StandardDifference) /// </summary> /// <param name="val"></param> /// <returns></returns> public double SD(List<double> val) { if (val.Count > 1) { double avg = AVG(val); double _result = (from a in val select Math.Pow(a - avg, 2)).Sum(); if (avg > 0 && _result > 0) { double _sum = _result / (double)(val.Count - 1); double _Sqrt = Math.Sqrt(_sum); return _Sqrt; } else return 0; } else if (val.Count == 1) { return 0; } else { return 0; } }
標籤: .NET