Different integration time step in Matlab and Simulink with ode45
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Carlotta Mummolo
2016 年 2 月 9 日
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.
回答 (2 件)
Kaustubha Govind
2011 年 8 月 5 日
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
2016 年 2 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Manual Performance Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!