Skip to content

Commit

Permalink
Added StandardDeviation() method in Stats (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Jun 30, 2023
1 parent 38264e3 commit bee237a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions PeyrSharp.Core/Maths/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,20 @@ public static double Variance(List<double> values)
int n = values.Count;
return variance / (n - 1);
}

/// <summary>
/// Calculates the standard deviation of a list of double numbers.
/// </summary>
/// <param name="values">The list of double numbers.</param>
/// <returns>The standard deviation of the list of double numbers.</returns>
/// <exception cref="ArgumentException">Thrown when the list is null or empty.</exception>
public static double StandardDeviation(List<double> values)
{
if (values == null || values.Count == 0)
{
throw new ArgumentException("The list cannot be null or empty.", nameof(values));
}
return Math.Sqrt(Variance(values));
}
}
}

0 comments on commit bee237a

Please sign in to comment.