Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Decimal Digits of PI

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:

num2str(pi, 100000)
ans = 
'3.141592653589793115997963468544185161590576171875'

The function 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 vpa using digits.

digits(5000);
a = vpa(pi)
a = 

To convert a variable-precision number into a string, use the function char.

c = char(a);

Search for your phone number in the digits of pi.

strfind(c, '1185480')
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');

Was this topic helpful?