球谐函数:
分离变量有:
其中,
满足连带勒让德方程:

![P_l(x)=\sum_{k=0}^{[l/2]}\frac{(-1)^k(2l-2k)!}{2^lk!(l-k)!(l-2k)!}x^{l-2k}](https://1000bd.com/contentImg/2024/04/13/f0fee933fed44dbc.png)


- ##Python 实现 legendre Polynomial
-
- import sympy as sym
-
- x = sym.Symbol("x")
-
- def Legendre_Polynomial(N,x):
- ##N:勒让德多项式的阶数
- ##x:自变量
-
- if N == 0:
- return 1
- elif N == 1:
- return x
-
- P0 = Legendre_Polynomial(0,x)
- P1 = Legendre_Polynomial(1,x)
-
- assert N>=2,"输入阶数N非正整数!!"
-
- for i in range(1,N):
- P = (2*i+1)/(i+1)*x*P1 - i/(i+1)*P0
- P0 = P1
- P1 = P
- return sym.simplify(P1)
-
- for i in range(10):
- print(Legendre_Polynomial(i,x))
- 1
- x
- 1.5*x**2 - 0.5
- x*(2.5*x**2 - 1.5)
- 4.375*x**4 - 3.75*x**2 + 0.375
- x*(7.875*x**4 - 8.75*x**2 + 1.875)
- 14.4375*x**6 - 19.6875*x**4 + 6.5625*x**2 - 0.3125
- x*(26.8125*x**6 - 43.3125*x**4 + 19.6875*x**2 - 2.1875)
- 50.2734375*x**8 - 93.84375*x**6 + 54.140625*x**4 - 9.84375*x**2 + 0.2734375
- x*(94.9609375*x**8 - 201.09375*x**6 + 140.765625*x**4 - 36.09375*x**2 + 2.4609375)
- X = np.linspace(-1,1,100)
- for i in range(0,11):
-
- if i == 0:
- Y = np.ones((X.shape))
- plt.plot(X,Y,label="orders:"+str(i))
- else:
- expression = Legendre_Polynomial(i,x)
- expression = sym.lambdify([x],expression,"numpy")
- Y = expression(X)
- plt.plot(X,Y,label="orders:"+str(i))
-
- plt.legend()
- plt.savefig("today.jpg")







本征值:
对应的本征函数:






球函数方程的解为球函数:



![f(\theta,\varphi)=\sum_{m=0}^{\infty}\sum_{l=m}^{\infty}[A_l^m\,cos\,m\varphi+B_l^m\,sin\,m\varphi]P_l^m(cos\,\theta)](https://1000bd.com/contentImg/2024/04/13/679d4f569a3ff117.png)








- import numpy as np
- import matplotlib.pyplot as plt
-
- tol = 1e-100000
- max_times = 100000
- a,b,t,p = 1,1/2**0.5,1/4,1
- ans = np.zeros(max_times,np.float64)
- ans[0] = (a+b)**2/4/t
- for i in range(1,max_times):
- an = (a+b)/2
- bn = (a*b)**0.5
- tn = t - p*(a-an)**2
- pn = 2*p
-
- a = an
- b = bn
- t = tn
- p = pn
-
- ans[i] = (a+b)**2/4/t
-
- if ans[i]-ans[i-1] <= tol:
- ans = ans[:i]
- break
-
- plt.plot(range(len(ans)),ans)
- plt.show()
- >>>ans
-
- array([2.91421356, 3.14057925, 3.14159265, 3.14159265])