[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 13:47:47 +0100 |
On 3 Dec 2011, at 13:22, c. wrote:
>
> On 3 Dec 2011, at 11:51, syberraith wrote:
>
>> My guess is that octave would be noticably slow then a compiled program.
>> The c program does all three functions even with 1 million data points each
>> as fast as I can release the return key. :)
>
> The time taken by Octave is also barely noticeable:
>
>>> 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.
>
> c.
and using the centered scheme as suggested by Jordi greatly improves the
accuracy whithout impact on the efficiency
>> 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);
>> f = [(tmp(2)-tmp(1))/h, (tmp(3:end)-tmp(1:end-2))/(2*h),
>> (tmp(end)-tmp(end-1))/h];
>> s = (h/2) * sum (f(1:end-1) + f(2:end))
s = -2.8232e-14
>> toc
Elapsed time is 0.1762 seconds.
>>
BTW why do you first compute the derivative of a + sin ((2 * pi / p) * t) and
then integrate it back?
you could get the same result simply as s = tmp(end) - tmp(1) ...
c.
- Re: Numerical Differentiation and Integration of Array Data, (continued)
- Re: Numerical Differentiation and Integration of Array Data, c., 2011/12/02
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/02
- Re: Numerical Differentiation and Integration of Array Data, Jordi Gutiérrez Hermoso, 2011/12/02
- Re: Numerical Differentiation and Integration of Array Data, Jordi Gutiérrez Hermoso, 2011/12/02
- Re: Numerical Differentiation and Integration of Array Data, c., 2011/12/03
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/03
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/03
- Re: Numerical Differentiation and Integration of Array Data, c., 2011/12/03
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/03
- Re: Numerical Differentiation and Integration of Array Data, c., 2011/12/03
- Message not available
- Re: Numerical Differentiation and Integration of Array Data,
Carlo de Falco <=
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/03
- Re: Numerical Differentiation and Integration of Array Data, c., 2011/12/04
- Re: Numerical Differentiation and Integration of Array Data, Carlo de Falco, 2011/12/04
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/04
- Re: Numerical Differentiation and Integration of Array Data, c., 2011/12/04
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/04
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/04
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/04
- Re: Numerical Differentiation and Integration of Array Data, Francesco Potortì, 2011/12/05
- Re: Numerical Differentiation and Integration of Array Data, syberraith, 2011/12/05