Ask Your Question
1

Alternative to Desolve_System_Rk4 for System of Second-Order ODE

asked 2023-05-27 03:35:11 +0200

Jack Zuffante gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-28 07:05:34 +0200

achrzesz gravatar image

updated 2023-06-06 12:12:59 +0200

slelievre gravatar image

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$

Introduce additional functions:

  • $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[2], y[3], -y[1] - 1, -y[0]]
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()
edit flag offensive delete link more

Comments

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?

Jack Zuffante gravatar imageJack Zuffante ( 2023-06-14 01:38:02 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-05-27 03:35:11 +0200

Seen: 236 times

Last updated: Jun 06 '23