結果から言うと、
ある場所に依存した確率を自分で算出することができました。
ただ、3次元プロットをしようとして、躓いています。
コード自体は、正直汚いと思われ、これから改良していく予定です。
python
1import numpy as np 2import matplotlib.pyplot as plt 3import math 4from mpl_toolkits.mplot3d import Axes3D 5 6#環境設定 7n=2 #tの範囲 8m=4 #xの範囲 9 10P = [[-1/2, 1/2, 1/2, 1/2],[0,0,0,0],[0,0,0,0],[0,0,0,0]] 11Q = [[0,0,0,0],[1/2, -1/2, 1/2, 1/2],[0,0,0,0],[0,0,0,0]] 12R = [[0,0,0,0],[0,0,0,0],[1/2, 1/2, -1/2, 1/2],[0,0,0,0]] 13S = [[0,0,0,0],[0,0,0,0],[0, 0, 0, 0],[1/2, 1/2, 1/2, -1/2]] 14 15x_list=[]#xline 16y_list=[]#yline 17t_list=[]#time 18p_list=[]#probability 19s_list=[]#state 20a = 1#1/math.sqrt(2) 21b = 0#1j/math.sqrt(2) 22c = 0 23d = 0 24 25for i in range(0,2*m+1): 26 if i == m: 27 phi = [a ,b, c, d] 28 else: 29 phi = [0, 0, 0, 0] 30 p = np.dot(phi,np.conj(phi)) 31 32 x_list.append(i) #xの座標 33 y_list.append(i) #yの座標 34 35 s_list.append(phi) 36 p_list.append(p) 37 38for t in range(0, n+1): 39 t_list.append(t) 40 if t == 0: 41 s_list 42 p_list 43 else: 44 next_s_list = [0]*len(s_list) 45 for x in range(0,2*m+1): 46 if x == 0: 47 for y in range(0,2*m+1): #x=0, 0<= y =<2*m 48 if y == 0: 49 next_s_list[y] = np.inner(P, s_list[x+1]) + np.inner(R, s_list[y+1]) 50 elif y == 2*m: 51 next_s_list[y] = np.inner(P, s_list[x+1]) + np.inner(S, s_list[y-1]) 52 else: 53 next_s_list[y] = np.inner(P, s_list[x+1]) + np.inner(R,s_list[y+1]) +np.inner(S, s_list[y-1]) 54 elif x == 2*m: #x=2*m, 0<=y<=2*m 55 for y in range(0, 2*m+1): 56 if y == 0: 57 next_s_list[y] = np.inner(Q, s_list[x-1]) + np.inner(R, s_list[y+1]) 58 elif y == 2*m: 59 next_s_list[y] = np.inner(Q, s_list[x-1]) + np.inner(S, s_list[y-1]) 60 else: 61 next_s_list[y] = np.inner(Q, s_list[x-1]) + np.inner(R,s_list[y+1]) +np.inner(S, s_list[y-1]) 62 else: 63 if y == 0: 64 next_s_list[y] = np.inner(Q,s_list[x-1]) + np.inner(P,s_list[x+1]) 65 elif y == 2*m: 66 next_s_list[y] = np.inner(Q,s_list[x-1]) + np.inner(P,s_list[x+1]) + np.inner(S,s_list[y-1]) 67 else: 68 next_s_list[y] = np.inner(P, s_list[x+1]) + np.inner(Q, s_list[x-1]) + np.inner(R, s_list[y+1]) + np.inner(S,s_list[y-1]) 69 p_list[x] = np.dot(next_s_list[y], np.conj(next_s_list[y])) 70 s_list = next_s_list 71 72 print(t,p_list) 73 74 75#3Dplot 76 77fig = plt.figure() 78ax = Axes3D(fig) 79 80ax.set_xlabel("x") 81ax.set_ylabel("y") 82ax.set_zlabel("probability") 83 84ax.set_xlim(3*m,-m) 85ax.set_ylim(-m,3*m) 86ax.set_zlim(0,1) 87ax.plot(x_list, y_list, p_list, color ="red", linewidth=1) 88plt.show()
今回はコード自体はあまり関係ないと思われますが、一応掲載しときます。確率は
t=0 x_list=y_list=[0,1,2,3,4,5,6,7,8] p_list=[0, 0, 0, 0, 1, 0, 0, 0, 0] t=1 x_list=y_list=[0,1,2,3,4,5,6,7,8] p_list=[0.0, 0.0, 0.0, 0.25, 0.0, 0.25, 0.0, 0.0, 0.0] t=2 x_list=y_list=[0,1,2,3,4,5,6,7,8] p_list=[0.0, 0.0, 0.0625, 0.0, 0.125, 0.0, 0.0625, 0.0, 0.0]
となり、計算結果は間違えていません。
このとき、x_list=y_list=[0, 1, 2, 3, 4, 5, 6, 7, 8]に対応しており、
t=1(空白は確率0)のとき
|y/x|0|1|2|3|4|5|6|7|8|
|--|--:|
|0
|1
|2
|3|||||1/4|
|4||||1/4||1/4
|5|||||1/4|
|6
|7
|8
のように、x_list,y_listの中の座標を確率と対応させると、確かに上図のようなプロットが出来るはずなのですが、
x_list,y_listの中の順番とp_listの順番が1:1対応してしまい以下のような図になってしまいました。
原因はわかっているのですが、どのように修正すれば上図のようなプロットに到達できるのか、アドバイス等お願いします。
すこしわかりにくい説明になってしまいました。
状況が理解できない場合、説明します。
よろしくお願い致します。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/10 02:37
2018/05/10 03:04
2018/05/10 14:06
2018/05/10 14:25
2018/05/10 15:19
2018/05/10 15:26
2018/05/10 16:08 編集
2018/05/11 10:18