Change ode time step based on state

4 visualizaciones (últimos 30 días)
Jona Vonk
Jona Vonk el 11 de Jun. de 2025
Editada: Torsten el 11 de Jun. de 2025
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?

Respuestas (1)

Torsten
Torsten el 11 de Jun. de 2025
Editada: Torsten el 11 de Jun. de 2025
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.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by