public static void Gauss2dTest() { // sample 2d normal distribution function from -10 to 10 with 201x201 samples var range = 10; var area = new Box2d(-range, -range, range, range); var sampleCount = 201; // uneven values with give symmetrical pdf var pdf = new Matrix <double>(sampleCount, sampleCount); pdf.SetByCoord((x, y) => { var px = x / (sampleCount - 1.0); var py = y / (sampleCount - 1.0); var p = area.Lerp(px, py); return(Fun.Gauss2d(p.X, p.Y, 1.0)); }); // integrate sampled gauss distribution var stepSize = range * 2.0 / (sampleCount - 1.0); var integral = pdf.Data.Sum() * stepSize * stepSize; // Gauss must integrate to 1.0 Assert.True(integral.ApproximateEquals(1.0, 1e-10)); }