Change ode time step based on state
이전 댓글 표시
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개)
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.
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!