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: c.
Subject: Re: Numerical Differentiation and Integration of Array Data
Date: Sat, 3 Dec 2011 13:02:38 +0100

On 3 Dec 2011, at 11:51, syberraith wrote:

> Although I would figure this should sum to zero.  It seems to be providing
> only three significant digits of of accuracy.  That would be the minimum I
> could use.  I would prefer at least 4 and 6 would be comforting.  I'll have
> to study up on some err management.

Why exactly do you expect s to be 0? 
you are not integrating over an exact period as 
1256 is not exactly equal to (2 * pi / p).

If I integrate over a period I get the expected order of convergence

n = 100000; # Number of data points
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);

f = diff (a + sin ((2 * pi / p) * t)) / h;
s = sum (g * (f(1:end-1) + f(2:end)))
s = -6.2832e-05

n = 200000; # Number of data points
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 = sum (g * (f(1:end-1) + f(2:end)))
s = -3.1416e-05


Notice that changing the finite difference scheme 
I have also reduced the number of function evaluations 
by half.

c.


reply via email to

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