Problem 953. Pi Estimate 1
Solution Stats
Problem Comments
-
17 Comments
I'll have to say that the checking algorithm is very poorly written. Using isequal instead of an absolute difference with a permitted tolerance check is straight out flawed for me. And after repeating the calculations with both Python and MATLAB. I get an estimate of 3.2323.. for a series of 10 elements (nMax = 10). I wonder how the problem setters arrived at an estimate of 3.04... something. I can't remember the exact value that was used for that test.
So in running this summation through my ti-nspire for 10 iterations, I get an estimate of 3.232323... However, test 1 asserts that this should actually be 3.041840. The code I wrote also returns 3.232323, because it uses the Leibniz formula to estimate pi using the specified number of iterations "nMax". Either I am completely missing something or the author is unaware of what values a correct solution should actually be returning.
Like Sam, my code does not match the 'correct solutions.' As some previous comments suggested, I set my format to long and rounded to six digits.
nMax = 10, my estimate is 3.232316000000000
nMax = 1000, my estimate is 3.142592000000000
nMax = 1e6, my estimate is 3.141594000000000
Solution Comments
Show commentsProblem Recent Solvers1266
Suggested Problems
-
Find the sum of all the numbers of the input vector
50800 Solvers
-
Find the longest sequence of 1's in a binary sequence.
6390 Solvers
-
19511 Solvers
-
3442 Solvers
-
Side of an equilateral triangle
6432 Solvers
More from this Author4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!