電子在帶正電的點電荷電場中運動
一個帶負電的電子在一個正電荷的作用下,其運動的方式就像行星在太陽的重力吸引下進行軌道運動,因為靜電力(就是所謂的庫倫力)與重力一樣,都是一種向心力並且其大小與距離的平方成反比。下面的程式中有一個點電荷所產生電場的副程式(EF_point),在主程式中我們把電子的電荷量乘上電場的大小就是庫倫力(F=qe*E, a=F/m),再利用差分近似我們可以更新電子的速度和電子的位置。
GlowScript 3.0 VPython
def EF_point(q,rq,r):
ke=1.
rrq=r-rq
rrq0=mag(rrq)
E=ke*q*rrq/rrq0**3
return E
q=1.; rq=vec(0,3,0)
scene = display(width=800, height=800, center=vec(0, 4, 0),
background=vec(0.2,0.5,0.2))
Xaxis=arrow(pos=vec(-6,0,0),axis=vec(12,0,0),shaftwidth=0.01,headwidth=0.02)
Yaxis=arrow(pos=vec(0,0,0),axis=vec(0,8,0),shaftwidth=0.01,headwidth=0.02)
charge = sphere(pos=rq, radius=0.2, color=color.red)
qe=-1.; me=1.; xe=-2; ve=0.5
e = sphere(pos=vec(xe,0,0), radius=0.1, color=color.blue, make_trail=True)
e.v=vec(ve,0,0)
t=0.; dt=0.01; NR=int(1/dt)
while t < 100:
rate(NR*2)
E=EF_point(q,rq,e.pos)
e.v+=qe*E/me*dt
e.pos+=e.v*dt
t+=dt
電子在帶正電的圓環中進行簡諧運動
帶正電的圓環在通過圓心的中垂線上所產生的電場,是向著圓心的方向並且其大小與距離圓心的大小約略是正比關係,因此電力對電子的作用就像彈力(F=-kx)的作用一樣,因此電子在圓環上的正電荷的作用下進行簡諧運動。
GlowScript 3.0 VPython
def EF_ring_q(Nq,q,rq,R,r):
k=1.
E=vec(0.,0.,0.)
for i in range(Nq):
t=2.*pi/Nq*i
rrp=r-rq[i]
rrp0=mag(rrp)
E=E+k*q*rrp/rrp0**3
return E
Nq=16; q=1.; R=1.
scene=display(width=800,height=800,center=vec(0,0,0),background=vec(0.2,0.5,0.2))
arr=arrow(pos=vec(-2,0,0),axis=vec(4,0,0),shaftwidth=0.01, headwidth=0.02)
rq=[]
for i in range(Nq):
t=2.*pi/Nq*i
rq.append(vec(0,R*cos(t),R*sin(t)))
ball = sphere(pos=rq[i], radius=0.1, color=color.red)
qe=-1.; me=1.; h=1.
e = sphere(pos=vec(h,0,0), radius=0.1, color=color.blue)
E=EF_ring_q(Nq,q,rq,R,e.pos)
e.v=vec(0,0,0)
t=0.; dt=0.01; NR=int(1/dt)
while t < 20:
rate(NR)
E=EF_ring_q(Nq,q,rq,R,e.pos)
e.v+=qe*E/me*dt
e.pos+=e.v*dt
t+=dt