help-octave
[Top][All Lists]
Advanced

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

Re: Numerical Differentiation and Integration of Array Data


From: Carlo de Falco
Subject: Re: Numerical Differentiation and Integration of Array Data
Date: Sat, 3 Dec 2011 14:28:29 +0100

On 3 Dec 2011, at 13:22, c. wrote:

>>> 
>>> tic,
>>> n = 1000000; # One million samples
>>> p = 0.005;   # Time period
>>> a = 5;    # Just a variable parameter
>>> h = p / (n-1);  # dt
>>> g = h / 2;  # dt/2 for my version of central diff
>>> t = linspace (0, p , n);
>>> tmp = a + sin ((2 * pi / p) * t);
>>> f = diff (tmp) / h;
>>> s = g * sum (f(1:end-1) + f(2:end))
> s = -6.2832e-06
>>> toc
> Elapsed time is 0.1559 seconds.

oops! this should have actually been:

>> tic,
>> n = 1000000; # One million samples
>> p = 0.005;   # Time period
>> a = 5;    # Just a variable parameter
>> h = p / (n-1);  # dt
>> t = linspace (0, p , n);
>> tmp = a + sin ((2 * pi / p) * t);   ## one-side finite differences
>> f = diff (tmp) / h;                 ## midpoint rule
>> s = h * sum (f)
s =  4.4830e-14
>> toc
Elapsed time is 0.1509 seconds.
>> 

the previous code was actually computing the integral from h/2 to p - h/2
c.


reply via email to

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