How can i assure the same ode45 solver settings for Matlab and Simulink?
4 views (last 30 days)
I would like to compare the performance of matlab and simulink. Different ODE's are solved by both. In Simulink I only use the standard components. Currently I use the ode45 solver and enter the maximal time step, the initial time step, the relative and absolute tolerance.
With the simpler ODE the results agree in amount. the result vectors of the ODE solved by matlab has however another size than the result vector of simulink. In principle, this is not a problem, but since I want to compare the performance and matlab currently makes ~4 times as many steps, the calculation using matlab is significantly slower than with simulink. The difference in calculation time is certainly also influenced by other factors.
While I can vary 22 parameters with Matlab via odeset (I am aware that some of these parameters have no influence on the ode45, such as Jacobian), I have 17 available within simulink configuration parameters, whereby in my opinion only the four parameters that I have specified so far change the same settings.
Is there a possibility to get the solver properties e.g. from Simulink with a command as struct or similar, comparable to "gca" with figures, which I can adapt in matlab?
Since I want to compare the pure calculation time, I do not want to specify a fixed result time interval for the ode45 solver in Matlab (or sampletime when logging in simulink).
I use R2018b, in Simulink I save the results via "to workspace" as an array.
Fangjun Jiang on 10 Jun 2022
Choose whatever the proper settings for solver in Simulink, run simulation and save the simulation time data (through model configuration parameters, data import/export), then use the saved simulation time data when calling ode45() in MATLAB. You can specify the actual time step vector, instead of start/stop/step. This way, the time step vector are the same between MATLAB and Simulink.