help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Skript takes much longer in Octave than in Matlab


From: Kai Torben Ohlhus
Subject: Re: Skript takes much longer in Octave than in Matlab
Date: Mon, 25 Mar 2019 09:52:14 +0100

On Mon, Mar 25, 2019 at 8:44 AM Martin Marmsoler <address@hidden> wrote:
Hi,

sorry that I'm asking again, but on the last mail I didn't get a response.

I have a script which I wrote in Matlab and tested it in Octave to, but there I saw that the program takes in Octave much longer than in Matlab R2018a. I have some matrix multiplications in some classes and a few loops but don't understand from where the duration difference come.


[snip]

Martin


You got unrecognized responses [1,2].  khalil2535 and I pointed out, that you cannot hope to get for-loops with expensive computations (without JIT) to work with Octave in a reasonable time.  You need to implement in Matlab/Octave language, that is vectorization.

One for-loop example (System/SystemSimulation.m, line 90, "% calculate position and velocity") I already showed in [2] what do do.  Replace that for-loop with

           i = 2:nrTime;
           v_i(:, i) = a_i(:, i) * obj.sampleTime; % euler integrator
           v_i = cumsum (v_i, 2);
           p_i(:, i) = v_i(:, i) * obj.sampleTime; % euler integrator
           p_i = cumsum (p_i, 2);

Then already Matlab takes advantage of implementing code in Matlab language ;-)

--- main.m without vectorization in Matlab R2018b ---
Start simulation
Data evaluation
Warning: mahonyComplementaryFilter Not implemented 
> In Evaluation (line 110)
  In main (line 260) 
Elapsed time is 13.224820 seconds.

--- main.m WITH mentioned vectorization in Matlab R2018b ---
Start simulation
Data evaluation
Warning: mahonyComplementaryFilter Not implemented 
> In Evaluation (line 110)
  In main (line 260) 
Elapsed time is 10.892137 seconds.


This is the path to go to with the remaining for-loops to get the script to work in Octave and Matlab.  It requires some programming/vectorization skills, but the effort is manageable.

HTH,
Kai


reply via email to

[Prev in Thread] Current Thread [Next in Thread]