質問編集履歴

1

コードを変更

2018/06/27 09:11

投稿

Fallout_18
Fallout_18

スコア124

test CHANGED
File without changes
test CHANGED
@@ -2,247 +2,7 @@
2
2
 
3
3
  ちなみに、調べてfig.tight_layout()としたらエラーがでました。
4
4
 
5
- ```python
6
5
 
7
- import numpy as np
8
-
9
- import matplotlib.pyplot as plt
10
-
11
- import math
12
-
13
- from mpl_toolkits.mplot3d import Axes3D
14
-
15
- from matplotlib import cm
16
-
17
- import matplotlib.colors as colors
18
-
19
- #まだちょっとおかしい
20
-
21
-
22
-
23
- #環境設定
24
-
25
- n=10 #tの範囲
26
-
27
- m=10 #xy
28
-
29
- r=2
30
-
31
-
32
-
33
- theta=3*(math.pi)/12
34
-
35
- #いろいろ準備
36
-
37
- t_list=[]
38
-
39
- x_list=[]
40
-
41
- y_list=[]
42
-
43
-
44
-
45
- phi_map =np.zeros((2*m+1,2*m+1,2),dtype="complex")
46
-
47
- phi_map[m,m]=[1j/math.sqrt(2),1j/math.sqrt(2)] #初期状態
48
-
49
- p_map=np.zeros([2*m+1,2*m+1])
50
-
51
-
52
-
53
- #量子コイン
54
-
55
- P = [[math.cos(theta),-1j*math.sin(theta)],
56
-
57
- [0,0]] #+xに進む
58
-
59
- Q = [[0,0],
60
-
61
- [-1j*math.sin(theta), math.cos(theta)]] #-xに進む
62
-
63
- #量子コイン
64
-
65
- R = [[1/math.sqrt(r), math.sqrt((r-1)/r)],
66
-
67
- [0,0]] #+yに進む
68
-
69
- S = [[0,0],
70
-
71
- [math.sqrt((r-1)/r), -1/math.sqrt(r)]] #留まる
72
-
73
-
74
-
75
- for i in range(0,2*m+1):
76
-
77
- p=np.inner(phi_map[i,i],np.conj(phi_map[i,i]))
78
-
79
- p_map[i,i]=np.real(p) #もしかして、2状態じゃおかしい?
80
-
81
- x_list.append(i)
82
-
83
- y_list.append(i)
84
-
85
-
86
-
87
- for t in range(0,n+1):
88
-
89
- t_list.append(t)
90
-
91
- if t == 0:
92
-
93
- phi_map
94
-
95
- p_map
96
-
97
- else:
98
-
99
- next_phi_map = np.zeros((2*m+1,2*m+1,2),dtype="complex") #x軸の変化
100
-
101
- final_phi_map= np.zeros((2*m+1,2*m+1,2),dtype="complex") #最終
102
-
103
- for x in range(0,2*m+1):
104
-
105
- if x == 0:
106
-
107
- for y in range(m,2*m+1):
108
-
109
- if y == m:
110
-
111
- next_phi_map[x,y] = np.array([np.dot(Q, phi_map[x+1,y])])
112
-
113
- #final_phi_map[x,y+1] = np.array([np.dot(R, next_phi_map[x,y])]) #この計算はelseの場所に含まれる
114
-
115
- final_phi_map[x,y] = np.array([np.dot(S, next_phi_map[x,y])])#+np.array([np.dot(R, next_phi_map[x,y-1])])
116
-
117
- elif y ==2*m:
118
-
119
- next_phi_map[x,y] = np.array([np.dot(Q,phi_map[x+1,y])])
120
-
121
- final_phi_map[x,y] = np.array([np.dot(S,next_phi_map[x,y])+np.dot(R,next_phi_map[x,y-1])])
122
-
123
- #final_phi_map[x,y+1]=np.array([np.dot(S,next_phi_map[x,y])])
124
-
125
- else:
126
-
127
- next_phi_map[x,y] = np.array([np.dot(Q, phi_map[x+1,y])])
128
-
129
- final_phi_map[x,y] = np.array([np.dot(R,next_phi_map[x,y-1])+np.dot(S,next_phi_map[x,y])])
130
-
131
- elif x == 2*m:
132
-
133
- for y in range(m,2*m+1):
134
-
135
- if y == m:
136
-
137
- next_phi_map[x,y] = np.array([np.dot(P, phi_map[x-1,y])])
138
-
139
- #final_phi_map[x,y+1] = np.array([np.dot(R,next_phi_map[x,y])])
140
-
141
- final_phi_map[x,y] = np.array([np.dot(S,next_phi_map[x,y])])
142
-
143
- elif y ==2*m:
144
-
145
- next_phi_map[x,y] = np.array([np.dot(P,phi_map[x-1,y])])
146
-
147
- final_phi_map[x,y] = np.array([np.dot(S,next_phi_map[x,y])+np.dot(R,next_phi_map[x,y-1])])
148
-
149
- #final_phi_map[x,y+1] = np.array([np.dot(S,next_phi_map[x,y])])
150
-
151
- else:
152
-
153
- next_phi_map[x,y] = np.array([np.dot(P, phi_map[x-1,y])])
154
-
155
- final_phi_map[x,y] = np.array([np.dot(R,next_phi_map[x,y-1])+np.dot(S,next_phi_map[x,y])])
156
-
157
- #final_phi_map[x,y] =np.array([np.dot(S,next_phi_map[x,y])])
158
-
159
- else:
160
-
161
- for y in range(m,2*m+1):
162
-
163
- if y == m:
164
-
165
- next_phi_map[x,y] = np.array([np.dot(P,phi_map[x-1,y])+np.dot(Q,phi_map[x+1,y])])
166
-
167
- #final_phi_map[x,y+1] = np.array([np.dot(R,next_phi_map[x,y])])
168
-
169
- final_phi_map[x,y] = np.array([np.dot(S,next_phi_map[x,y])])#+np.array([np.dot(R,next_phi_map[x,y-1])])
170
-
171
- elif y == 2*m:
172
-
173
- next_phi_map[x,y] = np.array([np.dot(P,phi_map[x-1,y])+np.dot(Q,phi_map[x+1,y])])
174
-
175
- final_phi_map[x,y]= np.array([np.dot(S,next_phi_map[x,y])+np.dot(R,next_phi_map[x,y-1])])
176
-
177
- else:
178
-
179
- next_phi_map[x,y] = np.array([np.dot(P,phi_map[x-1,y])+np.dot(Q,phi_map[x+1,y])])
180
-
181
- final_phi_map[x,y] = np.array([np.dot(R,next_phi_map[x,y-1])+np.dot(S,next_phi_map[x,y])])
182
-
183
- #final_phi_map[x,y] = np.array([np.dot(S,next_phi_map[x,y])])
184
-
185
-
186
-
187
-
188
-
189
- p_map[x,y]= np.real(np.inner(final_phi_map[x,y], np.conj(final_phi_map[x,y])))
190
-
191
- phi_map=final_phi_map
192
-
193
- #print(t,p_map)
194
-
195
-
196
-
197
- fig = plt.figure()
198
-
199
- ax = Axes3D(fig)
200
-
201
- X,Y = np.meshgrid(x_list, y_list)
202
-
203
-
204
-
205
- ax.set_xlabel("x",fontsize=24)
206
-
207
- ax.set_ylabel("y",fontsize=24)
208
-
209
- ax.set_zlabel("|φ^2|",fontsize=18)
210
-
211
-
212
-
213
- ax.set_xlim(2*m,0)
214
-
215
- ax.set_ylim(0,3*m)
216
-
217
- ax.set_zlim(0,0.006)
218
-
219
-
220
-
221
-
222
-
223
- offset = p_map.ravel() + np.abs(p_map.min())
224
-
225
- fracs = offset.astype(float)/offset.max()
226
-
227
- norm = colors.Normalize(fracs.min(), fracs.max())
228
-
229
- clrs = cm.bwr(norm(fracs))
230
-
231
-
232
-
233
- ax.bar3d(Y.ravel(), X.ravel(), p_map.ravel() ,0.3, 0.3, -p_map.ravel(),color =clrs)
234
-
235
- ax.w_xaxis.set_pane_color((0, 0, 0, 0))
236
-
237
- ax.w_yaxis.set_pane_color((0, 0, 0, 0))
238
-
239
- ax.w_zaxis.set_pane_color((0, 0, 0, 0))
240
-
241
- #fig.tight_layout(rect=[0, 0.03, 1, 0.95]) #ここです!!!
242
-
243
- plt.show()
244
-
245
- ```
246
6
 
247
7
  ![イメージ説明](21672a9199eaaadd2c650b1c10b0e88d.png)
248
8