From 9b122387d59f762f8d15c0c714d74dcfe4b707a9 Mon Sep 17 00:00:00 2001 From: Parric007 Date: Thu, 16 May 2024 12:27:29 +0200 Subject: [PATCH] Multiple Runs --- MonteCarloMatlab.m | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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