# Alternative to Desolve_System_Rk4 for System of Second-Order ODE

Since desolve_system_rk4 is only for first-order systems, is there another way to numerically integrate a second-order system?

edit retag close merge delete

Sort by » oldest newest most voted

Systems of second order ODEs can be reduced to systems of first order ODEs.

For example let us start with this system of second order ODEs:

• $y_1'' + y_2 + 1 = 0$
• $y_2'' + y_1 = 0$

• $y_3 = y_1'$
• $y_4 = y_2'$

We obtain a system of first order ODEs:

• $y_1' = y_3$
• $y_2' = y_4$
• $y_3' = -y_2 - 1$
• $y_4' = -y_1$

Sage numerical solution:

sage: T = ode_solver()
sage: f = lambda t, y: [y, y, -y - 1, -y]
sage: T.function = f
sage: T.ode_solve(y_0=[1, 1, 0, 0], t_span=[0, 20], num_points=1000)


Plot $y_1$:

sage: f = T.interpolate_solution()
sage: plot(f, 0, 5).show()


Plot $y_2$:

sage: f = T.interpolate_solution(i=1)
sage: plot(f, 0, 5).show()

more

Thank you! This generally works. But can I define functions of the variables and first derivatives beforehand, for the cases where the right sides of the second derivatives are very long?