Commit 7f77ea04 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 sigma函数没有检测数据范围

parent 7df48248
......@@ -283,6 +283,7 @@ namespace Misc
/// <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;
......@@ -292,10 +293,13 @@ namespace Misc
for (int i = first; i <= last; i++)
{
if (!double.IsNaN(buf.ElementAt(i)))
if ((i >= 0) && (i < buf.Count()))
{
sum += (buf.ElementAt(i) - avg) * (buf.ElementAt(i) - avg);
cnt++;
if (!double.IsNaN(buf.ElementAt(i)))
{
sum += (buf.ElementAt(i) - avg) * (buf.ElementAt(i) - avg);
cnt++;
}
}
}
if (cnt >= 3)
......
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