Change ode time step based on state

4 次查看(过去 30 天)
Jona Vonk
Jona Vonk 2025-6-11
编辑: Torsten 2025-6-11
I have a system of ODE's that I am solving using ode45. I am simulating a dynamic system and can therfore easily determine the energy that is currently in the system. Furthermore, I can can determin the Work of the forces acting on the system. If E_0 is the initial energy at t = 0, E_t the energy in the system in the currenttime step, W is the fork done by the forces, than it should hold that E_t - E_0 - W = 0 (for there is no damping). However when I run the ode45 function and afterwards compare the energy balance, this is not nesecarily true. Only if I set the maximum time step of ode45 to a suitably small number the energies remain balanced.
To decrease computational time it would be nice to use the maximum allowable time step, whilest keeping the energies balanced. Is there a way to do this? Can I dynamically change the time step based on the energy balance?

回答(1 个)

Torsten
Torsten 2025-6-11
编辑:Torsten 2025-6-11
An easier way is to choose appropriate absolute and relative tolerances to reduce the error of the integration:
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
[T,Y] = ode45(@fun,tspan,y0,options);
e.g.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by