In this problem, I plot the electric field of a moving charge for different speeds $\beta = v/c$. The charge is moving along the x-axis.
In [6]:
import numpy as np
import matplotlib.pylab as plt
#Import 3-dimensional plotting package.
from mpl_toolkits.mplot3d import axes3d
In [7]:
#Define constants - charge of an electron, permittivity of free space, velocity relative to speed of light.
q = 1.602 * 10**(-19)
e_0 = 8.854 * 10**(-12)
beta = 0.95
c = 2.997925 * 10**8
v = beta * c
By drawing the vectors in the problem, and relevant triangles, calculate the magnitude of the electric field $E(x, y, z, t)$ at a point $(x, y, z)$ for a certain time $t$. Define a function that will do this calculation for any point in space and at any time.
In [8]:
#Define magnitude of electric field as a function.
def E(x, y, z, t):
r = np.sqrt(x**2 + y**2 + z**2)
R = np.sqrt(r**2 + (v*t)**2 - 2 * r * (v*t) * x/np.sqrt(x**2 + y**2 + z**2))
sin_theta = np.sqrt(y**2 + z**2) / R
return q/(4*np.pi*e_0) * ((1 - beta**2)/(R**2 * (1 - beta**2 * sin_theta**2)**(3/2)))
In [9]:
#Define magnitude of electric field in x, y, and z directions.
def E_x(x, y, z, t):
return E(x, y, z, t) * (x - v*t)/np.sqrt((x - v*t)**2 + y**2 + z**2)
def E_y(x, y, z, t):
return E(x, y, z, t) * (y)/np.sqrt((x - v*t)**2 + y**2 + z**2)
def E_z(x, y, z, t):
return E(x, y, z, t) * (z)/np.sqrt((x - v*t)**2 + y**2 + z**2)
In [10]:
#Make a three-dimensional plot of the electric field.
fig = plt.figure(figsize = (8, 8))
ax = fig.gca(projection = '3d')
#Make a grid of points where vectors of the vector field are placed.
x_lim = 20
y_lim = 20
z_lim = 20
n = 5
X, Y, Z = np.meshgrid(np.arange(-x_lim, x_lim, n),
np.arange(-y_lim, y_lim, n),
np.arange(-z_lim, z_lim, n))
#Choose a time (in seconds) to plot the electric field of the charge, where the charge is at the origin for t = 0.
t = 0.000000005
#Write the vector components. Multiply by 10^11 so that the vectors are visible.
U = E_x(X, Y, Z, t) * 10**11
V = E_y(X, Y, Z, t) * 10**11
W = E_z(X, Y, Z, t) * 10**11
#Plot the vector field.
ax.quiver(X, Y, Z, U, V, W)
#Plot the x-axis, y-axis, and z-axis
X_0 = 1000*[0]
Y_0 = 1000*[0]
Z_0 = 1000*[0]
X_axis = np.linspace(-x_lim, x_lim, 1000)
ax.plot(X_axis, Y_0, Z_0, color = 'k', linewidth = 1, alpha = 0.5)
Y_axis = np.linspace(-y_lim, y_lim, 1000)
ax.plot(X_0, Y_axis, Z_0, color = 'k', linewidth = 1, alpha = 0.5)
Z_axis = np.linspace(-z_lim, z_lim, 1000)
ax.plot(X_0, Y_0, Z_axis, color = 'k', linewidth = 1, alpha = 0.5)
#Plot the charge, moving along the x-axis.
ax.plot([v*t], [0], [0], marker = 'o', markerfacecolor = 'k', markeredgecolor = 'None', alpha = 0.8)
#Adjust the viewing angle of the plot.
ax.view_init(elev = 20, azim = 275)
#Label the plot.
ax.set_xlabel('x (meters)')
ax.set_ylabel('y (meters)')
ax.set_zlabel('z (meters)')
ax.set_title('Electric Field of a Charge Moving at Constant Velocity, $\\beta = 0.95$')
#plt.savefig('Electric Field of a Charge Moving at Constant Velocity, B = 0.95.png')
plt.show()