import numpy as np
import matplotlib.pyolot as plt
np.ix_ ; plt.spy 函数
np.ix_([0, 1], [1,2])
plt.spy(M, color='r')
Legendre 多项式相关的函数
from scipy.special.orthogonal import roots_sh_legendre,eval_sh_legendre
quadpts, weights = roots_sh_legendre(3)
eval_sh_legendre(n, x)
def my_eval_legendre(n, m, x):
L = np.zeros((n+1, m+1))
if n == 0:
return 1 if m == 0 else 0
else:
L[0, 0], L[1, 0] = 1, x
if m == 0:
for i in range(2, n+1):
L[i, m] = \
((2 * i - 1) * x * L[i-1, m] - (i - 1) * L[i-2, m]) / i
else:
L[0, 0], L[0, 1] = 1, 0
L[1, 0], L[1, 1] = x, 1
for i in range(2, n+1):
for j in range(0, i+1):
if j > m: break
L[i, j] = \
( j * (2 * i - 1) * L[i-1, j-1] \
+ x * L[i-1, j] * (2 * i - 1) \
- (i - 1) * L[i-2, j] ) / i
return L[-1, -1]
.