All problems
Symplectic Step
Problem
Take one velocity Verlet (symplectic) step for the oscillator with potential 0.5 * k * x ** 2.
Set x_new = x + dt * v - 0.5 * dt ** 2 * k * x, v_half = v - 0.5 * dt * k * x, and v_new = v_half - 0.5 * dt * k * x_new. Return [x_new, v_new].
Hint
Velocity Verlet splits the kick into two half-steps around the drift.
Test cases
case 1
in: [1,0,1,0.1]
expected: [0.995,-0.09975]
case 2
in: [0,1,2,0.5]
expected: [0.5,0.75]
case 3
in: [2,-1,0.5,0.2]
expected: [1.78,-1.189]
Starter codePython
def symplectic_step(x, v, k, dt):
# Returns [x_new, v_new]
# Your code here
pass3 test cases · run your code against them in the editor