[关闭]
@XF 2016-12-11T15:41:15.000000Z 字数 3600 阅读 124

第十二次作业

作业


problem5.4

背景

Electric potential
Classical mechanics explores concepts such as force, energy, potential etc. Force and potential energy are directly related. A net force acting on any object will cause it to accelerate. As an object moves in the direction in which the force accelerates it, its potential energy decreases: the gravitational potential energy of a cannonball at the top of a hill is greater than at the base of the hill. As it rolls downhill its potential energy decreases, being translated to motion, inertial (kinetic) energy.

It is possible to define the potential of certain force fields so that the potential energy of an object in that field depends only on the position of the object with respect to the field. Two such force fields are the gravitational field and an electric field (in the absence of time-varying magnetic fields). Such fields must affect objects due to the intrinsic properties of the object (e.g., mass or charge) and the position of the object.

Objects may possess a property known as electric charge and an electric field exerts a force on charged objects. If the charged object has a positive charge the force will be in the direction of the electric field vector at that point while if the charge is negative the force will be in the opposite direction. The magnitude of the force is given by the quantity of the charge multiplied by the magnitude of the electric field vector.

摘要

Exercise 5.4 :
Investigate how the magnitude of the fringing field of the capacitor,that is,the electric field outside the central region of the capcitor in Figure 5.6,varies as a function of plate separation.

正文

解:
假设在z方向上棱柱和金属块时无限延伸的,所以电势分布我们考察平行于x-y平面的某个面即可,电势分布应和z无关。对于中空的部分,因为其中没有电荷,所以描述电势分布用拉普拉斯方程:


由雅克比法,解为:

代码:

  1. import numpy as np
  2. from pylab import *
  3. from math import *
  4. import mpl_toolkits.mplot3d
  5. # initialize : i represents x, j represents y
  6. V0=[[0 for i in range(21)]for j in range(21)]
  7. for i in range(6,15):
  8. for j in range(6,15):
  9. V0[j][i]=1.0# j,i
  10. #check
  11. for j in range(len(V0)):
  12. for i in range(len(V0[1])):
  13. print V0[i][j],
  14. print
  15. """
  16. #capacitor initialization
  17. for i in [6]:
  18. for j in range(6,15):
  19. V0[j][i]=1.0
  20. for i in [-6]:
  21. for j in range(6,15):
  22. V0[j][i]=1.0
  23. """
  24. VV=[]
  25. VV.append(V0)
  26. s=0
  27. dx=0.1
  28. #calculate:update V and delta_V
  29. while 1:
  30. VV.append(V0)
  31. for i in range(1,len(V0)-1):
  32. for j in range(1,len(V0[1])-1):
  33. VV[s+1][i][j]=(VV[s][i+1][j]+VV[s][i-1][j]+\
  34. VV[s][i][j+1]+VV[s][i][j-1])/4.0
  35. for i in range(6,15):
  36. for j in range(6,15):
  37. VV[s+1][j][i]=1.0
  38. for i in [20]:
  39. for j in range(21):
  40. VV[s+1][j][i]=0.0
  41. for i in [-20]:
  42. for j in range(21):
  43. VV[s+1][j][i]=0.0
  44. for j in [20]:
  45. for i in range(21):
  46. VV[s+1][j][i]=0.0
  47. for j in [-20]:
  48. for i in range(21):
  49. VV[s+1][j][i]=0.0
  50. """
  51. #capacitor calculation
  52. for i in [6]:
  53. for j in range(6,15):
  54. V0[j][i]=1.0
  55. for i in [-6]:
  56. for j in range(6,15):
  57. V0[j][i]=1.0
  58. """
  59. #calculate delta_V
  60. VV[s]=np.array(VV[s])
  61. VV[s+1]=np.array(VV[s+1])
  62. dVV=VV[s+1]-VV[s]
  63. dV=0
  64. for i in range(1,len(V0)-1):
  65. for j in range(1,len(V0[1])-1):
  66. dV=dV+abs(dVV[i][j])
  67. #print dV
  68. s=s+1
  69. if dV<0.0001 and s>10:
  70. break
  71. print s
  72. #display final results
  73. #Equipotential lines
  74. figure(figsize=[8,8])
  75. x=np.arange(-1.0,1.01,dx)#-1.0,-0.9,...,1.0
  76. y=np.arange(-1.0,1.01,dx)
  77. X,Y=np.meshgrid(x,y)
  78. CS = contour(X,Y,V,15)
  79. clabel(CS, inline=1, fontsize=10)
  80. xlim(-1,1)
  81. xlabel('x')
  82. ylim(-1,1)
  83. ylabel('y')
  84. title('Equipotential lines of electric potential', fontsize=15)
  85. #3D plot
  86. fig = figure(figsize=[8,8])
  87. ax = fig.add_subplot(111, projection='3d')
  88. ax.plot_surface(X, Y, V,rstride=1, cstride=1,linewidth=0)
  89. ax.set_xlabel('X')
  90. ax.set_ylabel('Y')
  91. ax.set_zlabel('V')
  92. title('Electric potential', fontsize=15)
  93. #Electic field
  94. V=array(VV[-1])
  95. Ex=array(V0)
  96. Ey=array(V0)
  97. for j in range(1,len(V0)-1):
  98. for i in range(1,len(V0[1])-1):
  99. Ex[j][i]=-(V[j][i+1]-V[j][i-1])/(2*dx)
  100. Ey[j][i]=-(V[j+1][i]-V[j-1][i])/(2*dx)
  101. figure(figsize=[8,8])
  102. Q=quiver(X,Y,Ex,Ey,scale=100)
  103. xlim(-1,1)
  104. xlabel('x')
  105. ylim(-1,1)
  106. ylabel('y')
  107. title('Electric field', fontsize=15)
  108. show()



结论

用雅可比方法对拉普拉斯方程进行求解能得到较好的结果。

致谢

感谢《计算物理》课本,以及张同学!

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注