help-octave
[Top][All Lists]
Advanced

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

lsode parameters slows down solution ?


From: Oz Nahum
Subject: lsode parameters slows down solution ?
Date: Sun, 28 Mar 2010 13:22:29 +0200

Hi Everyone,

I'm trying to compare Octave to Matlab speed of ODE solution.

when I solve the ODE with passing parameter to the function octave slows down significantly, wheres
without parameters, octave is faster then Matlab.

I'm trying to understand if I'm doing something wrong. Could it be that there is a better way to pass parameters to the functions ?

here are the function definitions in octave and matlab, note that matlab has to unpack much more variables, and still it's faster.

Matlab:
function f=batch1_rate(t,c1,ko,ks,Ys,Yo,Kdec,umax,kb)

or without parameters:
function f=batch1_rate(t,c1)
 
Octave:
function f=batch1_rate(c1,t,ko)

or without parameters:
function f=batch1_rate(c1,t)

the solving calls are the following in matlab:
 
timerange=[0:3600:43*86400];
tic()
[t,c]=ode15s(@batch1_rate_matlab,timerange,c1,[],ko,ks,Ys,Yo,Kdec,umax,kb);
toc()

without params:
tic()
timerange=[0:3600:43*86400];
[t,c]=ode15s(@batch1b_rate_matlab,timerange,c1,[]);
toc()

or with Octave:
g = @(x,t) batch1_rate(x, t, ko);
tic()
timerange=[0: 3600: 43*86400];
%[t,c]=ode15s(@batch1_rate,timerange,c1,[],ko,ks,Ys,Yo,Kdec,umax,kb);
[c,t]=lsode(g,c1,timerange,ko);
toc()

without params:
tic()
timerange=[0: 3600: 43*86400];
%[t,c]=ode15s(@batch1_rate,timerange,c1,[],ko,ks,Ys,Yo,Kdec,umax,kb);
[c,t]=lsode("batch1b_rate",c1,timerange);
toc()


The results of the CPU times on my computer (1GB RAM and 1.6 MHZ Intel Pentium) are in seconds:

no params with params
matlab 0.14840 0.14677
octave 0.03766 1.64757


So, Octave is MUCH faster without parameters, but really falls down when I pass parameters. Would be great to know why, and how I can improve it.

I also attached here the code of my files, in case someone wants to have a look.

Thanks in advance,

Oz Nahum
Graduate Student
Zentrum für Angewandte Geologie
Universität Tübingen

---

Imagine there's no countries
it isn't hard to do
Nothing to kill or die for
And no religion too
Imagine all the people
Living life in peace


Attachment: batch1.m
Description: Text Data

Attachment: batch1b.m
Description: Text Data

Attachment: batch1b_rate.m
Description: Text Data

Attachment: batch1_rate.m
Description: Text Data


reply via email to

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