## 2020年7月7日火曜日

### 数学 - Pytyhon - 線型代数学 - 将来はどうなる？ - 人口移動モデル、都市と農村、人口増加の想定、出生、行列、固有値、固有ベクトル、行列式、将来の比率、増加率

$A=\left[\begin{array}{cc}0.92& 0.12\\ 0.08& 0.9\end{array}\right]$
$\mathrm{det}\left[\begin{array}{cc}\lambda -0.92& -0.12\\ -0.08& \lambda -0.9\end{array}\right]=0$
${\lambda }^{2}-1.82\lambda +0.8184=0$
$\lambda =0.91±\sqrt{0.0097}$
$\lambda \approx 0.91±0.098=1.008,0.812$
$A\left[\begin{array}{c}x\\ y\end{array}\right]=1.008\left[\begin{array}{c}x\\ y\end{array}\right]$
$\left\{\begin{array}{l}0.92x+0.12y=1.008x\\ 0.08x+0.9y=1.008y\end{array}$
$\begin{array}{l}0.08x+0.9=1.008\\ x=1.35\end{array}$

よって、 将来の都市と農村の人口の比率は

$1:1.35$

になり、 また、その名人口増加率は1.008% に近づいていく。

コード

#!/usr/bin/env python3
from sympy import Matrix

A = Matrix([[0.92, 0.12],
[0.08, 0.9]])

X = Matrix([[80.0],
[20.0]])
PREV = X
print(f'経過年数,都市,農村,比率,都市増加率,農村増加率')
for i in range(100):
a, b = X
prev_a, prev_b = PREV
print(f'{i: 3d},{a: 10.5f},{b: 10.5f},{(a / b):10.5f},{a/prev_a:10.5f},{b/prev_b:10.5f}')
PREV = X
X = A * X


% ./sample1.py

0,  80.00000,  20.00000,   4.00000,   1.00000,   1.00000
1,  76.00000,  24.40000,   3.11475,   0.95000,   1.22000
2,  72.84800,  28.04000,   2.59800,   0.95853,   1.14918
3,  70.38496,  31.06384,   2.26582,   0.96619,   1.10784
4,  68.48182,  33.58825,   2.03886,   0.97296,   1.08127
5,  67.03387,  35.70797,   1.87728,   0.97886,   1.06311
6,  65.95612,  37.49989,   1.75884,   0.98392,   1.05018
7,  65.17961,  39.02639,   1.67014,   0.98823,   1.04071
8,  64.64841,  40.33812,   1.60266,   0.99185,   1.03361
9,  64.31711,  41.47618,   1.55070,   0.99488,   1.02821
10,  64.14888,  42.47393,   1.51031,   0.99738,   1.02406
11,  64.11384,  43.35845,   1.47869,   0.99945,   1.02082
12,  64.18775,  44.15171,   1.45380,   1.00115,   1.01830
13,  64.35094,  44.87156,   1.43411,   1.00254,   1.01630
14,  64.58745,  45.53248,   1.41849,   1.00368,   1.01473
15,  64.88435,  46.14623,   1.40606,   1.00460,   1.01348
16,  65.23115,  46.72235,   1.39614,   1.00534,   1.01248
17,  65.61934,  47.26861,   1.38822,   1.00595,   1.01169
18,  66.04202,  47.79129,   1.38188,   1.00644,   1.01106
19,  66.49362,  48.29553,   1.37681,   1.00684,   1.01055
20,  66.96959,  48.78546,   1.37274,   1.00716,   1.01014
21,  67.46628,  49.26448,   1.36947,   1.00742,   1.00982
22,  67.98072,  49.73534,   1.36685,   1.00763,   1.00956
23,  68.51050,  50.20026,   1.36474,   1.00779,   1.00935
24,  69.05369,  50.66108,   1.36305,   1.00793,   1.00918
25,  69.60872,  51.11926,   1.36169,   1.00804,   1.00904
26,  70.17434,  51.57603,   1.36060,   1.00813,   1.00894
27,  70.74952,  52.03238,   1.35972,   1.00820,   1.00885
28,  71.33344,  52.48910,   1.35901,   1.00825,   1.00878
29,  71.92546,  52.94687,   1.35845,   1.00830,   1.00872
30,  72.52504,  53.40622,   1.35799,   1.00834,   1.00868
31,  73.13179,  53.86760,   1.35762,   1.00837,   1.00864
32,  73.74536,  54.33138,   1.35733,   1.00839,   1.00861
33,  74.36549,  54.79787,   1.35709,   1.00841,   1.00859
34,  74.99200,  55.26732,   1.35690,   1.00842,   1.00857
35,  75.62472,  55.73995,   1.35674,   1.00844,   1.00855
36,  76.26353,  56.21593,   1.35662,   1.00845,   1.00854
37,  76.90836,  56.69542,   1.35652,   1.00846,   1.00853
38,  77.55914,  57.17855,   1.35644,   1.00846,   1.00852
39,  78.21584,  57.66543,   1.35637,   1.00847,   1.00852
40,  78.87842,  58.15615,   1.35632,   1.00847,   1.00851
41,  79.54689,  58.65081,   1.35628,   1.00847,   1.00851
42,  80.22123,  59.14948,   1.35625,   1.00848,   1.00850
43,  80.90147,  59.65223,   1.35622,   1.00848,   1.00850
44,  81.58762,  60.15913,   1.35620,   1.00848,   1.00850
45,  82.27971,  60.67022,   1.35618,   1.00848,   1.00850
46,  82.97776,  61.18558,   1.35617,   1.00848,   1.00849
47,  83.68181,  61.70524,   1.35615,   1.00848,   1.00849
48,  84.39189,  62.22926,   1.35614,   1.00849,   1.00849
49,  85.10805,  62.75769,   1.35614,   1.00849,   1.00849
50,  85.83033,  63.29056,   1.35613,   1.00849,   1.00849
51,  86.55877,  63.82793,   1.35613,   1.00849,   1.00849
52,  87.29342,  64.36984,   1.35612,   1.00849,   1.00849
53,  88.03433,  64.91633,   1.35612,   1.00849,   1.00849
54,  88.78154,  65.46744,   1.35612,   1.00849,   1.00849
55,  89.53511,  66.02322,   1.35612,   1.00849,   1.00849
56,  90.29509,  66.58371,   1.35611,   1.00849,   1.00849
57,  91.06153,  67.14894,   1.35611,   1.00849,   1.00849
58,  91.83448,  67.71897,   1.35611,   1.00849,   1.00849
59,  92.61400,  68.29383,   1.35611,   1.00849,   1.00849
60,  93.40014,  68.87357,   1.35611,   1.00849,   1.00849
61,  94.19295,  69.45822,   1.35611,   1.00849,   1.00849
62,  94.99250,  70.04784,   1.35611,   1.00849,   1.00849
63,  95.79884,  70.64245,   1.35611,   1.00849,   1.00849
64,  96.61203,  71.24212,   1.35611,   1.00849,   1.00849
65,  97.43212,  71.84687,   1.35611,   1.00849,   1.00849
66,  98.25918,  72.45675,   1.35611,   1.00849,   1.00849
67,  99.09325,  73.07181,   1.35611,   1.00849,   1.00849
68,  99.93441,  73.69209,   1.35611,   1.00849,   1.00849
69, 100.78271,  74.31763,   1.35611,   1.00849,   1.00849
70, 101.63821,  74.94849,   1.35611,   1.00849,   1.00849
71, 102.50097,  75.58469,   1.35611,   1.00849,   1.00849
72, 103.37105,  76.22630,   1.35611,   1.00849,   1.00849
73, 104.24853,  76.87336,   1.35611,   1.00849,   1.00849
74, 105.13345,  77.52590,   1.35611,   1.00849,   1.00849
75, 106.02588,  78.18399,   1.35611,   1.00849,   1.00849
76, 106.92589,  78.84766,   1.35611,   1.00849,   1.00849
77, 107.83354,  79.51696,   1.35611,   1.00849,   1.00849
78, 108.74889,  80.19195,   1.35611,   1.00849,   1.00849
79, 109.67201,  80.87267,   1.35611,   1.00849,   1.00849
80, 110.60297,  81.55916,   1.35611,   1.00849,   1.00849
81, 111.54183,  82.25148,   1.35611,   1.00849,   1.00849
82, 112.48866,  82.94968,   1.35611,   1.00849,   1.00849
83, 113.44353,  83.65381,   1.35611,   1.00849,   1.00849
84, 114.40651,  84.36391,   1.35611,   1.00849,   1.00849
85, 115.37765,  85.08004,   1.35611,   1.00849,   1.00849
86, 116.35705,  85.80225,   1.35611,   1.00849,   1.00849
87, 117.34475,  86.53059,   1.35611,   1.00849,   1.00849
88, 118.34084,  87.26511,   1.35611,   1.00849,   1.00849
89, 119.34539,  88.00586,   1.35611,   1.00849,   1.00849
90, 120.35846,  88.75291,   1.35611,   1.00849,   1.00849
91, 121.38013,  89.50629,   1.35611,   1.00849,   1.00849
92, 122.41048,  90.26608,   1.35611,   1.00849,   1.00849
93, 123.44957,  91.03231,   1.35611,   1.00849,   1.00849
94, 124.49748,  91.80504,   1.35611,   1.00849,   1.00849
95, 125.55429,  92.58434,   1.35611,   1.00849,   1.00849
96, 126.62006,  93.37024,   1.35611,   1.00849,   1.00849
97, 127.69489,  94.16283,   1.35611,   1.00849,   1.00849
98, 128.77884,  94.96213,   1.35611,   1.00849,   1.00849
99, 129.87199,  95.76823,   1.35611,   1.00849,   1.00849
%