LoginSignup
1
2

More than 1 year has passed since last update.

フィボナッチ数列の隣り合う2項の比率をグラフに表してみる

Last updated at Posted at 2021-05-13

フィボナッチ数列とは

フィボナッチ数列は数学Ⅲの漸化式でやりますよね。

$1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...$

という具合に、初項が $F_1 = 1, F_2 = 1$

そして $\quad F_{n+2} = F_{n+1} + F_n \quad (n \geq 1)\quad $ という漸化式であらわされる数列です。
(0から始める場合もある)

この数列はとても不思議な性質を持っていて、その一つに隣り合う2項の比
$\large \frac{F_n}{F_{n-1}}$ の極限が黄金比に収束するというもの。

つまり

$$ \lim_{n \to \infty}\frac{F_n}{F_{n-1}} = 1.6180339887498948482...$$

となることを示しています。

今回は、それを完全な形ではありませんが、視覚的に表現してみようと思います。

Pythonでのグラフの描画

Pythonのグラフ描画モジュールの扱いに慣れていないため、コードが汚いですが気にしないでください。

python
import matplotlib.pyplot as plt
import numpy as np

a = [1, 1]
x = []
ratio_list = []

for i in range(0, 10):
    x.append(i+3)
    a.append(a[i] + a[i+1])
    ratio = a[-1] / a[-2]
    ratio_list.append(ratio)

# 漸近線の表示
y1 = 1.6180339887
plt.axhline(y=y1, xmin=0, xmax=13, c='blue', ls='--')

# 比率のグラフ
plt.xlim([2, 13])
plt.ylim([1.45, 2.05])
plt.xlabel('x')
plt.ylabel('$\\frac{F_x}{F_{x-1}}$', rotation=0)
plt.xticks(x)
plt.grid(which="major", color="black", alpha=0.5)
plt.plot(x, ratio_list, c='red', marker="o")

# 表示
plt.show()

下図の青色の破線が黄金比の近似値 $y = 1.6180339887$ を表しています
隣り合う2項の比が早い段階で黄金比へ収束していることがわかります。
aa.png

追記

フィボナッチ数列関連の処理はこっちの方がスマートでよさそうです

import numpy as np
import matplotlib.pyplot as plt


def gen_fibonacci(num):
    a = 1
    b = 1
    x = []
    ratio_list = []
    for i in range(1, num):
        x.append(i + 1)
        ratio_list.append(b / a)
        (a, b) = (b, a + b)
    return x, ratio_list


# 漸近線の表示
y1 = 1.6180339887
plt.axhline(y=y1, c='blue', ls='--')

# 比率のグラフ
plt.xlim([1, 11])
plt.grid(which="major", color="black", alpha=0.5)
plt.title('Ratio of x items to x-1 items')
plt.xlabel('x')
plt.ylabel('$\\frac{F_x}{F_{x-1}}$', rotation=0)
plt.xticks(gen_fibonacci(10)[0])
plt.plot(gen_fibonacci(10)[0], gen_fibonacci(10)[1], c='red', marker="o")

# 表示
plt.show()

asd.png

1
2
4

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
1
2