/// <summary>
/// 平方差
/// s^2=∑(x-x̅)^2/(n-1)
/// </summary>
/// <param name="dataList"></param>
private void sdCalculate2(List<double> dataList)
{
try
{
#region 方法一
double sdValue = dataList.Sum(m => Math.Pow(m - dataList.Average(), 2)) / (double)(dataList.Count - 1);
SDresult.Add(sdValue);
#endregion
#region 方法二
for (int i = 0; i < dataList.Count; i++)
{
sdValue += Math.Pow(dataList[i] - dataList.Average(), 2);
}
sdValue = sdValue / (double)(dataList.Count - 1);
SDresult.Add(sdValue);
#endregion
#region 方法三
double uValue = 0, sum = 0;
List<double> xValue = new List<double>();
for (int i = 0; i < dataList.Count; i++)
{
uValue += dataList[i];
}
uValue = uValue / (dataList.Count);
for (int i = 0; i < dataList.Count; i++)
{
xValue.Add(Math.Pow(dataList[i] - uValue, 2));
}
double EValue = 0;
for (int i = 0; i < xValue.Count; i++)
{
EValue += xValue[i];
}
sum = ((double)1 / (double)(dataList.Count - 1)) * EValue;
SDresult.Add(sum);
#endregion
}
catch (Exception)
{
throw;
}
}