09-05-2018 11:37 AM
Hello all,
I am having the most peculiar behavior with an extremely simple VI that I do not understand.
I am writing a program to approximate Pi by randomly generating points within X: [0,1) Y:[0,1), calculating the ratio of points inside an inscribed circle and outside of it in a square. I understand the math and the theory perfectly fine.
What I don't understand.....:
This is my program. If i set "# of points" to 1 - ~40000, the program works fine and a relatively decent approximation of pi comes out (e.g. 3.1522). However, if I exceed ~40000 points, my program suddenly gives a clearly incorrect result, sometimes being ~0.5, sometimes being negative (which shouldn't be possible). I would like to know, why is this occurring and can it be rectified?
Solved! Go to Solution.
09-05-2018 12:19 PM
The function "Boolean To (0,1)" is outputting an I16. When the sum exceeds 32367, it wraps around.
Convert the output of "Boolean To (0,1)" to I32 inside the loop.
09-05-2018 12:28 PM
Wow what a simple reason.
Thank you very much!
09-05-2018 01:15 PM
Taking this a bit further, here are some tips for the future:
Here is a quick example:
(note that "re/im to complex" followed by "absolute value" would be more efficient because you don't care about the theta output. See also our NI week presentation form 2016.)