0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

円周率の小数点以下の各桁の数字の分布

Posted at

円周率の小数点以下の各桁の数字の分布

Julia では,円周率は任意の精度 $k$ として,BigFloat(π, k) で簡単に求めることができる。小数点以下 $n$ 桁必要な場合,$k > \frac{n}{ \log_{10}2}$ とする。末尾の計算誤差を考慮すれば $k$ より少し大きめの整数を指定する方がよいだろう。

小数点以下 10000 桁までならば,

k = 10000 / log10(2)
33219.280948873624

$k = 33240$ とすれば十分であろう。

33240 * log10(2)
10006.237055870735

BigFloat(π, 33240) で整数部を含む円周率が求められ,string(x) で文字列に変換し,[3:10002] で小数点以下 10000 桁を取り出し,Char[y...] で各桁に分解し,parse.(Int, z) で整数ベクトルに変換する。

d = parse.(Int, Char[string(BigFloat(π, 33240))[3:10002]...]);
# データベクトルの長さ(データの個数)
length(d)
10000
# 度数分布
using FreqTables
freq = freqtable(d)
10-element Named Vector{Int64}
Dim1  │ 
──────┼─────
0     │  968
1     │ 1026
2     │ 1021
3     │  974
4     │ 1012
5     │ 1046
6     │ 1021
7     │  970
8     │  948
9     │ 1014

各数字がほぼ均等に出現している。

# 結果を棒グラフで表示
using Plots
bar(freq, ylabel="frequency", xlabel="digit", xticks=(1:10, string.(0:9)), label="")

fig1.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?