In [1]:
from sympy import *
In [2]:
from sympy.matrices import Matrix
In [3]:
init_printing()
In [4]:
#In the first section, all variables are symbols. The transformation and relationship are ignored
Theta = var('Theta') #Theta is the angle between the direction vector and its projection on xOy plane
phi = var('phi')#phi denote the angle between the projection mentioned above and the direction of +x axis, which is also the direction of the speed
Theta_prime = var('Theta_prime')
phi_prime = var('phi_prime')
psi = var('psi')
theta = var('theta')
psi_prime = var('psi_prime')
theta_prime = var('theta_prime')
cos_theta = lambda : cos(theta)
sin_theta = lambda : sin(theta)
cos_psi = lambda : cos(psi)
sin_psi = lambda : sin(psi)
cos_theta_prime = lambda : cos(theta_prime)
sin_theta_prime = lambda : sin(theta_prime)
cos_psi_prime = lambda : cos(psi_prime)
sin_psi_prime = lambda : sin(psi_prime)
c = var('c') #light speed
B = var('B') #the strength of magnetic field during the period in which the particle passes through the segment
beta = var('beta')
v = lambda : beta * c #the speed of the particle during the period
gamma = var('gamma')
#func_gamma = lambda : gamma
E_prime = var('E_prime') #the strength of electric field in the S' frame
#func_E_prime = lambda : E_prime
B_prime = var('B_prime')
#func_B_prime = lambda : B_prime
vector_epsilon_prime_in = Matrix([[S(0), -S(1), S(0)]])
#in S frame
def vector_n():
return Matrix([[cos_theta(), sin_theta() * cos_psi(), sin_theta() * sin_psi()]]) #the vector of observor's direction
def vector_epsilon_out_1():
return Matrix([[-sin_theta() * sin_psi() * cos_theta() / sqrt(S(1) - sin_theta()**2 * sin_psi()**2), -sin_theta() * sin_psi() * sin_theta() * cos_psi() / sqrt(S(1) - sin_theta()**2 * sin_psi()**2), sqrt(1 - sin_theta()**2 * sin_psi()**2)]]) #the out vector which lies in the xOy plane
def vector_epsilon_out_2():
return vector_epsilon_out_1().cross(vector_n()) #the other out vector
#in S' frame
def vector_n_prime():
return Matrix([[cos_theta_prime(), sin_theta_prime() * cos_psi_prime(), sin_theta_prime() * sin_psi_prime()]])
def vector_epsilon_prime_out_1():
return Matrix([[-sin_theta_prime() * sin_psi_prime() * cos_theta_prime() / sqrt(S(1) - sin_theta_prime()**2 * sin_psi_prime()**2), -sin_theta_prime() * sin_psi_prime() * sin_theta_prime() * cos_psi_prime() / sqrt(S(1) - sin_theta_prime()**2 * sin_psi_prime()**2), sqrt(S(1) - sin_theta_prime()**2 * sin_psi_prime()**2)]]) #the out vector which lies in the xOy plane
def vector_epsilon_prime_out_2():
return vector_epsilon_prime_out_1().cross(vector_n_prime())
r_e = var('r_e') #classical electron radius
def E_prime_out_1():
return r_e * E_prime * vector_epsilon_prime_out_1().dot(vector_epsilon_prime_in)
def E_prime_out_2():
return r_e * E_prime * vector_epsilon_prime_out_2().dot(vector_epsilon_prime_in)
def vector_E_prime_out():
return E_prime_out_1() * vector_epsilon_prime_out_1() + E_prime_out_2() * vector_epsilon_prime_out_2()
def vector_B_prime_out():
return S(1) / c * vector_n_prime().cross(vector_E_prime_out())
vector_x = Matrix([[S(1), S(0), S(0)]])
def vector_E_out():
return gamma * (vector_E_prime_out() - v() * vector_x.cross(vector_B_prime_out())) - (gamma - 1) * vector_E_prime_out().dot(vector_x) * vector_x
def factor_vector(vector_instance):
return Matrix([[factor(vector_instance[i]) for i in range(len(vector_instance))]])
In [5]:
factor_vector(vector_E_out())
Out[5]:
In [6]:
factor(vector_E_out()[0])
Out[6]:
In [7]:
factor(vector_E_out()[1])
Out[7]:
In [8]:
factor(vector_E_out()[2])
Out[8]:
In [9]:
cos_theta = lambda : cos(Theta) * cos(phi)
sin_theta = lambda : sqrt(S(1) - cos_theta()**2)
cos_psi = lambda : cos(Theta) * sin(phi) / sin_theta()
sin_psi = lambda : sqrt(S(1) - cos_psi()**2)
sin_theta_prime = lambda : sin_theta() / (gamma * (S(1) - beta * cos_theta()))
cos_theta_prime = lambda : (cos_theta() - beta) / (S(1) - beta * cos_theta())
sin_psi_prime = lambda : sin_psi()
cos_psi_prime = lambda : cos_psi()
#sin_phi_prime = lambda : sin_theta_prime() * cos_psi_prime() / sqrt(1 - sin_theta_prime()^2 * sin_psi_prime()^2)
#cos_phi_prime = lambda : sqrt(1 - sin_phi_prime()^2)
#sin_Theta_prime = lambda : sin_theta_prime() * sin_psi_prime()
#cos_Theta_prime = lambda : sqrt(1 - sin_Theta_prime()^2)
gamma = S(1) / sqrt(S(1) - beta ** 2)
In [10]:
factor_vector(vector_E_out())
Out[10]:
In [11]:
factor(vector_E_out()[0])
Out[11]:
In [12]:
factor(vector_E_out()[1])
Out[12]:
In [13]:
factor(vector_E_out()[2])
Out[13]:
In [14]:
factor(vector_E_out().dot(vector_E_out()))
Out[14]:
In [15]:
#Below is the canonical calculation of electrodynamics
canonical_vector_E_out = lambda : vector_n().cross((vector_n() - beta * vector_x).cross(vector_epsilon_prime_in)) / (S(1) - beta * vector_x.dot(vector_n()))**2
In [16]:
factor_vector(canonical_vector_E_out())
Out[16]:
In [17]:
factor(canonical_vector_E_out()[0])
Out[17]:
In [18]:
factor(canonical_vector_E_out()[1])
Out[18]:
In [19]:
factor(canonical_vector_E_out()[2])
Out[19]:
In [20]:
factor(canonical_vector_E_out().dot(canonical_vector_E_out()))
Out[20]:
In [25]:
factor_vector(vector_E_out() - (-E_prime * r_e / gamma * canonical_vector_E_out()))
Out[25]:
In [24]:
factor(vector_E_out().dot(vector_E_out()) - E_prime**2 * r_e**2 / gamma**2 * canonical_vector_E_out().dot(canonical_vector_E_out()))
Out[24]:
In [22]: