This example shows how to use variable-precision arithmetic to investigate the decimal digits of pi using Symbolic Math Toolbox™.
Joke: What do you get when you take the sun and divide its circumference by its diameter?
Answer: in the sky!
It is an old game to search for one's birthday or telephone number in the decimal digits of . The precision of the built-in datatypes suffices to obtain a few digits only:
ans = '3.141592653589793115997963468544185161590576171875'
vpa uses variable-precision to convert symbolic expressions into symbolic floating-point numbers. Convert
pi to a floating-point number using
vpa. Increase the precision of
digits(5000); a = vpa(pi)
To convert a variable-precision number into a string, use the function
c = char(a);
Search for your phone number in the digits of
ans = 447
It is common belief that all digits occur asymptotically equally often in the decimal expansion of , but no proof exists yet. Find the decimal point:
pos = strfind(c, '.')
pos = 2
Convert the decimal digits to numbers, and plot a histogram of their frequency:
d = arrayfun(@str2num, c(pos+1:end)); histogram(d, 10); title('Frequency of the decimal digits of \pi');