ラゲルの多項式
モジュールのインポート
import numpy as np
import matplotlib.pyplot as plt
plt.style.use(['science', 'notebook'])
再帰関数
def dfactorial(n): # 再帰関数による階乗
if n == 0:
k = 1
else:
k = n*dfactorial(n-1)
return k
def dfactorial2(n,m): # n!/m! (n>m)
if n==0 or n==m:
k = 1
else:
k = n*dfactorial2(n-1,m)
return k
階乗について計算すると,
nx = 7 # 計算点数
print(f"{'i':>10s} {'i!':>10s} {'i!/(i-2)!':>10s}")
for i in range(nx):
k = dfactorial(i+2)
k2 = dfactorial2(i+2,i)
print(f"{i+2:10.0f} {k:10.0f} {k2:10.0f}")
i i! i!/(i-2)!
2 2 2
3 6 6
4 24 12
5 120 20
6 720 30
7 5040 42
8 40320 56
ラゲルの多項式
# n, m: 次数(整数)
# x: 変数(実数)
def lague(n, m, x): # ラゲルの多項式
f1 = 1.0
fla = f1
if n != 0:
f2 = float(1+m)-x
fla = f2
if n != 1:
je = n-1
for j in range(je):
n1 = (j+1)+1
c2 = x-float(2*n1+m-1)
c1 = float(n1+m-1)
f3 = (-c2*f2-c1*f1)/float(n1)
f1 = f2
f2 = f3
fla = f3
return fla
計算値は,例えば,
x_min, x_max, n_x = 0.0, 4.0, 101
xx = np.linspace(x_min, x_max, n_x)
print(f"{'x':>8s} {'L1,0':>8s} {'L1,1':>8s} {'L1,2':>8s}")
for x in xx:
print(f"{x:8.3f} {lague(1,0,x):8.3f} {lague(1,1,x):8.3f} {lague(1,2,x):8.3f}")
x L1,0 L1,1 L1,2
0.000 1.000 2.000 3.000
0.040 0.960 1.960 2.960
0.080 0.920 1.920 2.920
0.120 0.880 1.880 2.880
0.160 0.840 1.840 2.840
0.200 0.800 1.800 2.800
0.240 0.760 1.760 2.760
0.280 0.720 1.720 2.720
0.320 0.680 1.680 2.680
0.360 0.640 1.640 2.640
0.400 0.600 1.600 2.600
0.440 0.560 1.560 2.560
0.480 0.520 1.520 2.520
0.520 0.480 1.480 2.480
0.560 0.440 1.440 2.440
0.600 0.400 1.400 2.400
0.640 0.360 1.360 2.360
0.680 0.320 1.320 2.320
0.720 0.280 1.280 2.280
0.760 0.240 1.240 2.240
0.800 0.200 1.200 2.200
0.840 0.160 1.160 2.160
0.880 0.120 1.120 2.120
0.920 0.080 1.080 2.080
0.960 0.040 1.040 2.040
1.000 0.000 1.000 2.000
1.040 -0.040 0.960 1.960
1.080 -0.080 0.920 1.920
1.120 -0.120 0.880 1.880
1.160 -0.160 0.840 1.840
1.200 -0.200 0.800 1.800
1.240 -0.240 0.760 1.760
1.280 -0.280 0.720 1.720
1.320 -0.320 0.680 1.680
1.360 -0.360 0.640 1.640
1.400 -0.400 0.600 1.600
1.440 -0.440 0.560 1.560
1.480 -0.480 0.520 1.520
1.520 -0.520 0.480 1.480
1.560 -0.560 0.440 1.440
1.600 -0.600 0.400 1.400
1.640 -0.640 0.360 1.360
1.680 -0.680 0.320 1.320
1.720 -0.720 0.280 1.280
1.760 -0.760 0.240 1.240
1.800 -0.800 0.200 1.200
1.840 -0.840 0.160 1.160
1.880 -0.880 0.120 1.120
1.920 -0.920 0.080 1.080
1.960 -0.960 0.040 1.040
2.000 -1.000 0.000 1.000
2.040 -1.040 -0.040 0.960
2.080 -1.080 -0.080 0.920
2.120 -1.120 -0.120 0.880
2.160 -1.160 -0.160 0.840
2.200 -1.200 -0.200 0.800
2.240 -1.240 -0.240 0.760
2.280 -1.280 -0.280 0.720
2.320 -1.320 -0.320 0.680
2.360 -1.360 -0.360 0.640
2.400 -1.400 -0.400 0.600
2.440 -1.440 -0.440 0.560
2.480 -1.480 -0.480 0.520
2.520 -1.520 -0.520 0.480
2.560 -1.560 -0.560 0.440
2.600 -1.600 -0.600 0.400
2.640 -1.640 -0.640 0.360
2.680 -1.680 -0.680 0.320
2.720 -1.720 -0.720 0.280
2.760 -1.760 -0.760 0.240
2.800 -1.800 -0.800 0.200
2.840 -1.840 -0.840 0.160
2.880 -1.880 -0.880 0.120
2.920 -1.920 -0.920 0.080
2.960 -1.960 -0.960 0.040
3.000 -2.000 -1.000 0.000
3.040 -2.040 -1.040 -0.040
3.080 -2.080 -1.080 -0.080
3.120 -2.120 -1.120 -0.120
3.160 -2.160 -1.160 -0.160
3.200 -2.200 -1.200 -0.200
3.240 -2.240 -1.240 -0.240
3.280 -2.280 -1.280 -0.280
3.320 -2.320 -1.320 -0.320
3.360 -2.360 -1.360 -0.360
3.400 -2.400 -1.400 -0.400
3.440 -2.440 -1.440 -0.440
3.480 -2.480 -1.480 -0.480
3.520 -2.520 -1.520 -0.520
3.560 -2.560 -1.560 -0.560
3.600 -2.600 -1.600 -0.600
3.640 -2.640 -1.640 -0.640
3.680 -2.680 -1.680 -0.680
3.720 -2.720 -1.720 -0.720
3.760 -2.760 -1.760 -0.760
3.800 -2.800 -1.800 -0.800
3.840 -2.840 -1.840 -0.840
3.880 -2.880 -1.880 -0.880
3.920 -2.920 -1.920 -0.920
3.960 -2.960 -1.960 -0.960
4.000 -3.000 -2.000 -1.000