Processing math: 0%

First time here? Check out the FAQ!

Ask Your Question
1

Alternative to Desolve_System_Rk4 for System of Second-Order ODE

asked 1 year ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 1 year ago

achrzesz gravatar image

updated 1 year ago

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:

  • y1
  • 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()
Preview: (hide)
link

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 ( 1 year ago )

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: 1 year ago

Seen: 628 times

Last updated: Jun 06 '23