[关闭]
@Xc-liu 2016-05-23T19:54:13.000000Z 字数 1475 阅读 761

homework_13计算程序

程序1

  1. from mpl_toolkits.mplot3d import Axes3D
  2. from matplotlib import cm
  3. from matplotlib.ticker import LinearLocator, FormatStrFormatter
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. import math
  7. #######
  8. da=2.0*math.pi/1000.0
  9. dr=0.01
  10. ######
  11. l_1=[]
  12. l_2=[]
  13. B_x=[]
  14. B_y=[]
  15. B_z=[]
  16. B=[]
  17. theta=[0]
  18. x=[0]
  19. y=[0]
  20. z=[]
  21. r=[-1]
  22. ######
  23. #for k in range(int(2.0*math.pi/da)):
  24. for j in range(300):
  25. s_x=0
  26. s_y=0
  27. s_z=0
  28. l_1=[]
  29. l_2=[]
  30. z.append(r[j])
  31. #x.append(r[j]*math.cos(k*da))
  32. #y.append(r[j]*math.sin(k*da))
  33. for i in range(int(2.0*math.pi/da)):
  34. l_1.append(((x[0]-math.cos(i*da))**2+(y[0]-math.sin(i*da))**2+z[j]**2)**1.5)
  35. l_2.append(((x[0]-math.cos(i*da))**2+(y[0]-math.sin(i*da))**2+(z[j]-1)**2)**1.5)
  36. By=(z[j]*math.sin(i*da)/l_1[i]+(z[j]-1)*math.sin(i*da)/l_2[i])*da
  37. Bx=(z[j]*math.cos(i*da)/l_1[i]+(z[j]-1)*math.cos(i*da)/l_2[i])*da
  38. Bz=(-math.sin(i*da)*(y[0]-math.sin(i*da))-math.cos(i*da)*(x[0]-math.cos(i*da)))*(1.0/l_1[i]+1.0/l_2[i])*da
  39. s_x=s_x+Bx
  40. s_y=s_y+By
  41. s_z=s_z+Bz
  42. s=(s_z**2+s_x**2+s_y**2)**0.5
  43. B_x.append(s_x)
  44. B_y.append(s_y)
  45. B_z.append(s_z)
  46. B.append(s)
  47. print s
  48. r.append(r[j]+dr)
  49. ##################
  50. #fig = plt.figure()
  51. #ax = fig.gca(projection='3d')
  52. #X=x
  53. #Y=y
  54. #X,Y=np.meshgrid(X,Y)
  55. #Z=B
  56. #surf=ax.plot_surface(X,Y,Z,rstride=1,cstride=1,cmap=cm.jet,linewidth=0,antialiased=False)
  57. ##ax.set_zlim(-1.01, 1.01)
  58. #ax.zaxis.set_major_locator(LinearLocator(10))
  59. #ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
  60. #fig.colorbar(surf, shrink=0.5, aspect=5)
  61. #plt.show()
  62. ##########
  63. plt.plot(z,B)
  64. plt.ylabel(u'B')
  65. plt.xlabel(u'z')
  66. plt.title(u"")
  67. plt.show()
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注