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 work-energy theorem, the kinetic energy of the proton (starting from rest) is

(25)KE=W=Fdx,
and since the force is constant, the kinetic energy is simply the product of the (constant) force times the distance traveled. This “analytical” result (which does not involve any approximations) can be compared with the “numerical” kinetic energy from your program,
(26)KE=γmc2mc2.

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.