help-octave
[Top][All Lists]
Advanced

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

integration function


From: Paul Thomas
Subject: integration function
Date: Sun, 25 Jul 2004 14:57:32 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225

Just to expand the replies a bit further;

Take a simple example  y(s) = integral( 2*t*exp(-t^2) ) [0 to s]

1] with quad-
octave:1> function dydt = mz(t);dydt=2*t*exp(-t*t);endfunction
octave:2> quad("mz",0,[1,2])
ans = 0.63212

2] the analytic solution = ( 1 - exp( -s*s ))
octave:3> 1-exp(-1*1)
ans = 0.63212

3] with LSODE
octave:4> function dydt = mf(y,t);dydt=2*t*exp(-t*t);endfunction
octave:5> t=[0,1];[a,b,c]=lsode("mf",0,t);a(2)
ans = 0.63212

Note that the function for lsode has as inputs the dependent variable(y), which is unused here and the independent variable(t).

4] Getting a bit perverse, a tiny bit of algebra gives:
y(s) = integral( 2*t*y(t) ) [0 to s], so using LSODE again:

octave:6> function dydt = mg(y,t);dydt=2*t*(1-y);endfunction
octave:7> t=[0,1];[a,b,c]=lsode("mg",0,t);a(2)
ans = 0.63212

quad is about 4 times faster than lsode for this application, with default accuracies. However, if you want to tabulate intermediate values by putting more values in the input t-vector, the execution time of lsode barely changes, whereas quad must be put in a loop (I think?).

This time using dependent and independent variables.

Paul T



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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