Commit 998a5713 authored by 潘栩锋's avatar 潘栩锋 🚴

MyMath 添加 double Sigma(IEnumerable<double> buf, int first, int last)

parent 854d1a38
......@@ -274,7 +274,35 @@ namespace Misc
else
return 0;
}
/// <summary>
/// 排除 NULL_VALUE, 求Sigma
/// </summary>
/// <param name="buf"></param>
/// <param name="first">开始序号</param>
/// <param name="last">结束序号</param>
/// <returns></returns>
public static double Sigma(IEnumerable<double> buf, int first, int last)
{
double avg = Avg(buf, first, last);
if (double.IsNaN(avg))
return double.NaN;
double sum = 0;
int cnt = 0;
for (int i = first; i <= last; i++)
{
if (!double.IsNaN(buf.ElementAt(i)))
{
sum += (buf.ElementAt(i) - avg) * (buf.ElementAt(i) - avg);
cnt++;
}
}
if (cnt >= 3)
return (Math.Sqrt(sum / (cnt - 1)));
else
return 0;
}
/// <summary>
/// 排除 NULL_VALUE, 求Sigma
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment