Simulation with a loop and ode 45 inside it executed much slower in Octave (5.2 and 6.x) compared to Matlab. Before optimising the differential equation I was integrating, I decided to profile the code to see if my differential equation code or the discrete-time-controller code was the bottleneck.
Profiling indicated that most of the execution time is spent inside functions other than the differential equation functions specific to my problem.
@inputParser_xxxxx and runge_kutta_45_dorpri are consuming most of the time.
I am simulating a system which has both discrete time sub-system (digital control) and continuous time system (plant being controlled). The fixed-time-step part is implemented by the while loop and the continuous time part is implemented by the ode45.
Is there a way to speed up my simulation ? If the functions at the top of the profile were user written, I could have attempted to convert them to C++ mkoct files.
Below is the code and the profiling result. The code is a minimum working example to illustrate the problem. Even for much more complicated (non linear, time varying) differential equations, I am still getting similar results.
fprintf('example profiled running...\n');
endtime = 1000;
stepsize = 0.5; % the fixed step used by the controller
t = 0; ii = 1; % reserve space so that it doesn't slow down the program tl = zeros(ceil(endtime/stepsize), 1); yl = zeros(ceil(endtime/stepsize), 2);
ic = [1, 0];
control = 0.1;
while(t < endtime)
% run the non linear time varying differential equation