Runge-Kutta 4th order method to solve second-order ODES
问题 I am trying to do a simple example of the harmonic oscillator, which will be solved by Runge-Kutta 4th order method. The second-order ordinary differential equation (ODE) to be solved and the initial conditions are: y'' + y = 0 y(0) = 0 and y'(0) = 1/pi The range is between 0 and 1 and there are 100 steps. I separated my 2nd order ODE in two first-order ODEs, using u as auxiliary variable: y' = u u' = -y The analytical solution is sinusoidal y(x) = (1/pi)^2 sin(pi*x). My Python code is below: