public bool Compute() { RayQuantities.Length[] sample = new RayQuantities.Length[NumberOfParameters]; for (int j = 0; j < Iterations; j++) { for (int i = 0; i < sample.Length; i++) { sample[i] = RayQuantities.Length.FromCentimeters(Random.NextDouble() * Range[i].Length.GetValueInCentimeters() + Range[i].Min.GetValueInCentimeters()); } RayQuantities.Length f = Function(sample); count++; sum += f; sum2 += f * f; } double volume = 1; for (int i = 0; i < Range.Length; i++) { volume *= Range[i].Length.GetValueInCentimeters(); } double avg = sum.GetValueInCentimeters() / count; double avg2 = sum2.GetValueInCentimeterSqrs() / count; Area = RayQuantities.Area.FromCentimeterSqrs(volume * avg); Error = RayQuantities.Area.FromCentimeterSqrs(volume * Math.Sqrt((avg2 - avg * avg) / count)); return(true); }
public void Reset() { this.sum = RayQuantities.Length.FromCentimeters(0); this.sum2 = RayQuantities.Area.FromCentimeterSqrs(0); this.count = 0; this.Area = RayQuantities.Area.FromCentimeterSqrs(0); this.Error = RayQuantities.Area.FromCentimeterSqrs(Double.MaxValue); }