I am currently doing a computational physics homework which asked us to use leapfrog to give the relations between timevelocities and time-distance of these two objects.
The full question is as follows:
Consider two parallel wire with distance d. A negative charged object(m1) is moving along the wire with initial velocity v0. One positive charged object(m2) is located on another wire with zero initial velocity and located at the original point(x = 0). The initial distance between two objects(x), velocity(v0), charges and(e1,e2) masses(m1,m2) are arbitrary. Relativity effect can be ignored.
- Write down the equations of motion for these two objects for this problem and convert it from a second-order equation to two-rst order ones. Write down a program using the time-reversal symmetric methods such as leapfrog or Verlet method to give the relations between timevelocities and time-distance of these two objects.(please use initial conditions: m1 = 1; m2 = 1; e1 = −1; e2 = 1; d = 1; x = 100; v0 = −5)
- Keep the original distance, masses and charges unchanged(m1 = 1; m2 = 1; e1 = −1; e2 = 1; d = 1; x = 100), please plot the nal velocity of m2 with dierent v0 (v0 ∈ (−10,0)). (here, you may need to enlarge the total time to nd the stable nal velocity of m2, roughly should be δv < 10−4). In the distance gure, we can always nd that m2 rst move along positive direction and then move along negative direction. Please nd the maxinum distance(D2max) of m2 in the positive direction at dierent v0 and plot this relation between v0 and D2max
I have already found the two 2nd order differential equation:
And by substituting the initial value as required, we obtained the following result:
And I have already convert the two equations into first order:
First of all, I would like to ask whether or not my steps for now are correct or not, since I am really skeptical on whether I can just directly convert it to first order one since the upsidedown L in the denominator still contains the variable x_1 and x_2
Secondly, since there are variable x_1 and x_2 in the upsidedown L, how can I change the equation to the form that I can use in the modified function of rk2a() in http://www.math-cs.gordon.edu/courses/mat342/python/diffeq.py
I have modified the code in rk2a() function to the leapfrog form:
def leapfrog(f, x0, t):
n = len( t )
x = np.array( [ x0 ] * n )
for i in range( n - 1 ):
h = t[i+1] - t[i]
k1 = h * f( x[i], t[i] ) / 2.0
if (i%2 == 0):
x[i+1] = x[i] + h * f( x[i] + k1, t[i] + h / 2.0 )
else:
k2 = h * f( x[i], t[i] )
x[i+1] = k1 + h * f( x[i] + k2, t[i] + h / 2.0 )
return x
Thirdly, I would like to ask whether my modification is correct or not(Hopefully it should be correct i guess, but I don't have any equation to test it with since above, I have trouble changing it to the form required by the function)
And the modification is based on the equatuion by my lecture notes: