# What's a better way to integrate an ODE for one time-step than the Euler method?

I'm simulating a simple cart-pendulum system for purposes of testing different control strategies and data-driven approaches. I need to simulate the dynamical system one time-step at a time.

I'm trying to make the simulation as realistic as possible (non-linear, with disturbances and noise etc.)

At the moment I'm just using the Euler method:

y_dot = cartpend_dydt(t, y)

# Simple state update (Euler method)
y += tau*y_dot


where y_dot is the time-derivative of y, the state-vector (length 4) and tau is the time-step.

Since it's a very fast calculation I can run at 50 steps/second and so I'm sure Euler method is accurate enough.

But what if I want to reduce the sample efficiency to say 10 steps/second (more typical real-world scenario)?

Then I assume I should do something more accurate (and a bit more computationally expensive) each time step. But what's 'the next step up' from Euler?

I tried using a numerical integrator (in Python):

from scipy.integrate import solve_ivp

sol = solve_ivp(cartpend_dydt, [t, t + tau], y)
y = sol.y[:, 1]


where cartpend_dydt(t, y) is a function that returns the time derivative of y.

I think scipy.integrate.solve_ivp is an "explicit Runge-Kutta method of order 5(4)" by default.

But is this over-kill for a relatively short time-step? Is there a simpler method that would be better than Euler but not too computationally intensive?

• There's a lot of off-topic topics for this question. First of all, Python scripting and their libraries... The only on-topic questions for Python is either circuit simulation or embedded scripting. Second, a cart-pendulum is a control system, yes, but not an electrical control system. Third, you're asking for a more accurate mathematical algorithm than Euler method. – user103380 May 16 '19 at 20:14
• Yes, where to post control engineering questions is an open question. Thanks for clarifying that I'm asking for a more accurate mathematical algorithm than Euler method. Are you implying I should be posting on Mathematics? I'm not clear what you are recommending. – Bill May 16 '19 at 20:19
• I'm not entirely sure where this question would belong since you're talking about mathematical algorithms and accuracy optimization (implying both Math SE and Stackoverflow respectively). However, if you did this by hand, you could ask this on Math SE. Once you get a more accurate algorithm, then you can apply it to Python. – user103380 May 16 '19 at 20:26