Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set fixed step size with scipy.integrate?

I am looking for a way to set a fixed step size for solving my initial value problem by Runge-Kutta method in Python. Accordingly, how I can tell the scipy.integrate.RK45 to keep a constant update (step size) for its integration procedure?

Thank you very much.

like image 605
behzad baghapour Avatar asked Sep 02 '25 16:09

behzad baghapour


1 Answers

Scipy.integrate is usually used with changeable step method by controlling the TOL(one step error) while integrating numerically. The TOL is usually computed by checking with another numerical method. For example RK45 uses the 5th order Runge-Kutta to check the TOL of the 4th order Runge-Kutta method to determine the integrating step.

Hence if you must integrate ODEs with fixed step, just turn off the TOL check by setting atol, rtol with a rather large constant. For example, like the form:

solve_ivp(your function, t_span=[0, 10], y0=..., method="RK45", max_step=0.01, atol = 1, rtol = 1)

The TOL check is set to be so large that the integrating step would be the max_step you choose.

like image 200
徐天壮 Avatar answered Sep 04 '25 11:09

徐天壮