境界条件を変えてみた。 上辺以外の辺の電位を固定(ディリクレ型)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# Python 3.13.2, PyCharm 2024.3.5, numpy 2.2.4, matplotlib 3.10.1 import numpy as np import matplotlib.pyplot as plt fig = plt.figure() dl = 0.1 #微小長さ size = 10 #正方形の大きさ ll = int(size/dl) #分割数 volt = 10.0 #上辺の電位 c_err = 10**-3 #収束判定値 phi1 = np.zeros([ll+1, ll+1]) #電位(保存用) phi2 = np.empty([ll+1, ll+1]) #電位 err = 1.5 #誤差 n = 0 #収束条件モニタ用カウンタ while err > c_err: for i in range(ll+1): for j in range(ll+1): if j==0 or i==ll or j==ll: #上辺以外の境界条件 Φ=0 phi2[i,j] = 0 elif i==0: phi2[i,j] = volt #上辺の境界条件 Φ=10 else: phi2[i,j] = (phi1[i+1,j] + phi1[i-1,j] + phi1[i,j+1] + phi1[i,j-1])/4 err = np.max(abs(phi2-phi1)) phi1, phi2 = phi2, phi1 n += 1 if n % 100 == 0: # 収束状況のモニタリング print(n, err) im = plt.imshow(phi1, cmap='rainbow') plt.colorbar() plt.xlabel('X') plt.ylabel('Y') plt.show() |
ノイマン型の境界条件より簡単。
予想通りの結果。 あんまり面白くない。