Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that uses the fourth-order Runge-Kutta method to integrate the Hamiltonian equations of motion, q=pH,p=qH, where H(q,p)=2mp2+V(q). To this end, use a function
Write a program that uses the fourth-order Runge-Kutta method to integrate the Hamiltonian equations of motion, q=pH,p=qH, where H(q,p)=2mp2+V(q). To this end, use a function rk4step(f,t0, z0,dt) that performs one Runge-Kutta step and returns a vector containing the function value (in our case that is a point in phase space) after the step. In your function, f(t,z) should be a function itself, taking time t and corresponding (vector-valued) function value z as an input and return the right-hand side of the ODE. Next, to and z0 are the inputs for time and function value (z0 will be a two-dimensional vector for our investigation), and dt is the stepsize. Test your program with the harmonic oscillator potential using k=1,m=3, for which you can calculate the exact solution. Hint: One approach would be to have a wrapper function that takes the right-hand-side function, the initial conditions, the step size and the number of steps as an input and returns an array containing all the phase space points of the trajectory
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started