About
Developed by Larry Engelhardt
In these exercises, you will determine the motion of a proton in a uniform electric field. We will begin by simulating a proton in an electric field using the NONrelativistic version of Newton’s 2nd Law. Then we will modify this simulation to take special relativity into account. In the process, we will observe the transition from nonrelativistic to relativistic dynamics. In order to generate results, we will see that we need to be careful when working with nonSI units. In particular, we will need to pay close attention to factors of eV and $c$.
Subject Area  Modern Physics 

Level  Beyond the First Year 
Available Implementations  IPython/Jupyter Notebook and Python 
Learning Objectives 
Students will be able to:

Time to Complete  120 min 
Exercise 1:
The file ending with “Version1” contains code to simulate a proton in an electric field using the nonrelativistic acceleration derived above. (This code uses the “Euler algorithm” described in the “Theory” section.) Execute this code, and look at the plots of position versus time and speed versus time. Explain why these plots have the shapes that they have.
Exercise 2:
The file ending with “Version2” contains the same code as the file ending with “Version1” except that a few lines have been added in order to also calculate and plot the nonrelativistic energy. Locate the line where the nonrelativistic energy is calculated. (The same line appears both inside the loop and before the loop.) Explain why this line is correct. You will need to be very careful with the units and the factors of ${c}^{2}$. Write down the equation for nonrelativistic energy (including both rest energy and nonrelativistic kinetic energy), and carefully argue why this line of code is correct.
Execute this code, and look at the plot of energy versus time. Why does this plot have the shape that it has? How large is the kinetic energy compared to the rest energy after the proton has been accelerating for 1 second?
Exercise 3:
Again use the file ending with “Version2” but now increase the value of the maximum time from 1 second to 5 seconds. How large is the kinetic energy compared to the rest energy after the proton has been accelerating for 5 seconds? Look at the plot of speed versus time. Something should bother you! Explain what is wrong
Exercise 4:
Derive the relativistic form of Newton’s 2nd Law,
from the equation $F=dp/dt$. See the “Theory” section for additional background.
Exercise 5:
Save a copy of the file ending with “Version2” using a file name ending with “Version3”. In this new file, you are going to modify the code in order to take special relativity into account. This will involve the following steps:
 Compute the value of the Lorentz factor, $\gamma $.
 Use the Lorentz factor to compute the acceleration.
 Modify the equation for the energy (both before the loop and within the loop) in order to compute the relativistic energy. Hint: Once you have computed the Lorentz factor, the relativistic energy is actually very simple to compute, but be very careful of the units and factors of ${c}^{2}$.
Execute your modified program, and fix any bugs!
Exercise 6:
Execute your modified program (Version3) using a maximum time of 5 seconds, and look at the plot of speed versus time. Does the plot look better than the plot that you looked at in Exercise 3? It should! If it doesn’t, there is a bug in your code that needs to be fixed before you continue. Explain why the new plot of speed versus time has the shape that it has.
Exercise 7:
Now that you have created a new program, you should attempt to validate your program (to test how accurate the numbers actually are). One simple way to do this is using the energy. From the workenergy theorem, the kinetic energy of the proton (starting from rest) is
Add code to your program (after the program’s loop has completed) to compute the kinetic energy both analytically and numerically. Print both results, and make sure that they are similar. (If they aren’t you need to fix something!) Compute the percent error in the numerical kinetic energy. How large is the error? Increase the value of your program’s time step by a factor of 10. How does this affect the error? Why does this happen? (This code uses the “Euler algorithm” described in the “Theory” section.) Before you continue to the next exercise, make sure that the error is a small fraction of a percent.
Exercise 8:
Increase the maximum time for your simulation until you are able to get the total energy of the proton up to 100 GeV. Discuss the shape of each of the three plots (position, speed, and energy). Why do they have the shapes that they have? (Incorporate the term “ultrarelativistic” into your answer.)
Exercise 9:
Using an electric field of $\u03f5=1$ Volt/meter, how much time does it take to accelerate a proton to an energy of 100 GeV? How far does it travel in that time? (Use your plots from Exercise 8.)
At the Large Hadron Collider (LHC), protons are accelerated to an energy of 8 TeV. Instead of using a longer simulation, extrapolate your results in order to determine how long it would take to accelerate a proton up to $E=8$ TeV using $\u03f5=1$ Volt/meter. How far does the proton travel during this time? How many trips around the LHC would the proton make during this time? How does this distance compare to the circumference of the Earth’s orbit around the sun?
# relativisticDynamicsVersion3.py
from pylab import *
from time import time
start = time()
c = 2.998e8 # Speed of light in m/s
m = 0.938e9 # Mass in eV/c^2
Efield = 5e6 # Electric field in Volts per meter
x = 0 # Position in meters
v = 0 # Velocity in meters/second
t = 0 # Time in seconds
dt = 1e8 # Time STEP in seconds
lorentz = 1 / sqrt(1  v**2 / c**2) ## ADDED ##
E = lorentz * m ## MODIFIED ##
# Create arrays using initial values
tArray = array(t)
xArray = array(x)
vArray = array(v)
EArray = array(E)
lorentzArray = array(lorentz) ## ADDED ##
while t < 1e5:
# The dynamics:
lorentz = 1 / sqrt(1  v**2 / c**2) ## ADDED ##
a = Efield*c**2/(lorentz**3*m) ## MODIFIED ##
t = t + dt
x = x + v*dt
v = v + a*dt
E = lorentz * m ## MODIFIED ##
# Append the new values onto arrays
tArray = append(tArray, t)
xArray = append(xArray, x)
vArray = append(vArray, v)
EArray = append(EArray, E)
lorentzArray = append(lorentzArray, lorentz) ## ADDED ##
end = time()
print('Elapsed time:', endstart)
# The following lines are added for Exercise 7
KE_numerical = lorentz * m  m
KE_analytical = Efield*x
print('Numerical KE: ', KE_numerical)
print('Analytical KE:', KE_analytical)
print('Percent Difference:', 100*abs(KE_numericalKE_analytical)/KE_analytical)
# Create plots
figure(1)
plot(tArray, vArray, linewidth=2)
xlabel('Time (sec)')
ylabel('Speed (m/s)')
grid(True)
ylim([0, 3.1e8])
savefig('ultrarelativistic_v_vs_t.png')
show()
figure(2)
plot(tArray, xArray, linewidth=2)
xlabel('Time (sec)')
ylabel('Position (m)')
grid(True)
savefig('ultrarelativistic_x_vs_t.png')
show()
figure(3)
plot(tArray, EArray, linewidth=2)
xlabel('Time (sec)')
ylabel('Energy (eV)')
grid(True)
savefig('ultrarelativistic_E_vs_t.png')
show()
Translations
Code  Language  Translator  Run  

Software Requirements
Android  iOS  Windows  MacOS  
with best with  Chrome  Chrome  Chrome  Chrome 
support fullscreen?  Yes. Chrome/Opera No. Firefox/ Samsung Internet  Not yet  Yes  Yes 
cannot work on  some mobile browser that don't understand JavaScript such as.....  cannot work on Internet Explorer 9 and below 
Credits
Fremont Teng; Loo Kang Wee; based on code by Larry Engelhardt
end faq
{accordionfaq faqid=accordion3 faqclass="lightnessfaq defaulticon headerbackground headerborder contentbackground contentborder round5"}Version:
 https://www.compadre.org/PICUP/exercises/exercise.cfm?I=103&A=RelativisticDynamics1DConstantForce
 http://weelookang.blogspot.com/2018/06/picuprelativisticdynamicsin1dwith.html
Other Resources
end faq
{accordionfaq faqid=accordion4 faqclass="lightnessfaq defaulticon headerbackground headerborder contentbackground contentborder round5"}