Different integration time step in Matlab and Simulink with ode45
51 views (last 30 days)
Show older comments
Hi,
I am carrying out a comparison between Matlab and Simulink in order to learn more about how each works. I simulate a simple second order system using the following code in Matlab:
rhsfun = @(t,x) function_name(t,x);
[t,x] = ode45(rhsfun,[0 sim_time],x0);
I then simulate an equivalent system in Simulink, using the following call from the Matlab workspace:
sim('Model_name.mdl',sim_time);
What puzzles me is that after the simulation, the time vectors are very different. The vector from the Matlab simulation is approximately 6 times longer than that from the Simulink simulation, so obviously the integration time step in Simulink is greater.
I use the default options settings for the simulations. I am curious and would like to know the cause of this difference. Can someone enlighten me? Is there a way to have the solver use the same time steps in both cases?
Thank you,
Barry.
1 Comment
Carlotta Mummolo
on 9 Feb 2016
Hi Barry, the problem may be in the Refine option in the ode45 in Matlab, which by default is 4, while in Simulink is 1.
Answers (2)
Kaustubha Govind
on 5 Aug 2011
In Simulink, ode45 is a variable-step solver, so depending on the dynamics of your system, it will take a time-step just small enough to achieve a certain level of tolerance. So your for your system, it appears that the Simulink solver decided that that many time-steps were enough to preserve the desired accuracy of the outputs. See Choosing a Solver for more information. To force the Simulink solver to take specified time-steps, please refer to my answer here: http://www.mathworks.com/matlabcentral/answers/11340-set-simulink-time-step
Carlotta Mummolo
on 9 Feb 2016
Hi Barry, the problem may be in the Refine option in the ode45 in Matlab, which by default is 4, while in Simulink is 1.
0 Comments
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!