Problem 44309. Pi Digit Probability
Assume that the next digit of pi constant is determined by the historical digit distribution. What is the probability of next digit (N) being (n).
For example if we consider the first 100 digits of pi, we will see that the digit '3' is occured 12 times. So the probability of the being '3' the 101th digit will be 12/100 = 0.12.
Round the results to four decimals.
Solution Stats
Problem Comments
-
20 Comments
% I used Machin's Formula: pi = 4[4arctan(1/5) - arctan(1/239)] because it was used for speed. But it will not go no more than 16 digits. How can I go beyond 16 digits?
function [PI] = pidigit(N,n)
A = 0;
F = 10^300;
% Machin's Formula: pi = 4[4arctan(1/5) - arctan(1/239)]
x1 = 1/5;
x2 = 1/239;
for K = 0:1000000000
A1 = 4*((-1)^K*x1^(2*K+1)/(2*K+1));
A2 = (-1)^K*x2^(2*K+1)/(2*K+1);
A = A + 4*(A1 - A2)*F;
end
E = abs(pi*F-A)/(pi*F);
PI = sprintf('%.f',A) -'0';
sum(PI(1:N-1) == n)
sum(PI(1:N-1) == n)/(N-1)
end
can't use vpa, so thats annoying. just find online the first bunch of digits of pi, paste them into a character variable, and work from there. I found the digits here :https://www.angio.net/pi/digits/10000.txt
good
Solution Comments
Show commentsProblem Recent Solvers647
Suggested Problems
-
475 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
483 Solvers
-
523 Solvers
-
1548 Solvers
-
905 Solvers
More from this Author92
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!