diff --git a/MonteCarloMatlab.m b/MonteCarloMatlab.m index c964a7c..5a51c3d 100644 --- a/MonteCarloMatlab.m +++ b/MonteCarloMatlab.m @@ -1,24 +1,31 @@ tic; -samples = 10000000; +samples = 100000; xBounds = LinearBounds(0,20); yBounds = LinearBounds(-10,150000); bounds = Bounds(xBounds,yBounds); pointsInside = 0; realValue = realIntegral(bounds.x); +listOfErrors = []; +listOfIntegrals = []; -for i = 0:samples - toTestPoint = bounds.getRandomPoint; - if getIsInside(toTestPoint) - pointsInside = pointsInside+1; +for i = 1:20 + for ii = 0:samples + toTestPoint = bounds.getRandomPoint; + if getIsInside(toTestPoint) + pointsInside = pointsInside+1; + end end + listOfIntegrals(i) = pointsInside/samples*bounds.area; + listOfErrors(i) = abs(listOfIntegrals(i) - realValue); + pointsInside = 0; end - format longG integral = (pointsInside/samples)*bounds.area realValue error = abs(realValue-integral) -samples +listOfErrors +listOfIntegrals toc