Author 
Message 
1940LaSalle@gmail.com science forum beginner
Joined: 28 Apr 2006
Posts: 17

Posted: Wed Jul 12, 2006 8:07 pm Post subject:
Recommendation for numerical differentiation formulas?



Here's the situation: I have a series of data in a spreadsheet; the
independent variables are spaced equally. I need to determine the
first derivative at each of the values of the independent variable,
including the endpoints, within the spreadsheet, and would prefer to do
it automatically, rather than do a new regression for every case study.
Could someone please (1) recommend a numerical differentiation scheme,
and (2) mention the source with explicit formulas (ideally, formulas
suitable for spreadsheet use)?
Thanks. 

Back to top 


Helmut Jarausch science forum beginner
Joined: 08 Jul 2005
Posts: 49

Posted: Thu Jul 13, 2006 9:31 am Post subject:
Re: Recommendation for numerical differentiation formulas?



1940LaSalle@gmail.com wrote:
Quote:  Here's the situation: I have a series of data in a spreadsheet; the
independent variables are spaced equally. I need to determine the
first derivative at each of the values of the independent variable,
including the endpoints, within the spreadsheet, and would prefer to do
it automatically, rather than do a new regression for every case study.
Could someone please (1) recommend a numerical differentiation scheme,
and (2) mention the source with explicit formulas (ideally, formulas
suitable for spreadsheet use)?

Let your data be L M R and h = difference in the indep. var.
1st) 1st deriv at the position of M = (RL)/(2*h)
for use in the "interior"
2nd) 1st deriv at the position of L = (4*M3*LR)/(2*h)
use this at the left endpoint
3rd) 1st deriv at the position of R = (L4*M+3*R)/(2*h)
use this at the right endpoint

Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH  Aachen University
D 52056 Aachen, Germany 

Back to top 


Peter Spellucci science forum Guru
Joined: 29 Apr 2005
Posts: 702

Posted: Thu Jul 13, 2006 10:53 am Post subject:
Re: Recommendation for numerical differentiation formulas?



In article <1152734860.671170.151780@m73g2000cwd.googlegroups.com>,
1940LaSalle@gmail.com writes:
Quote:  Here's the situation: I have a series of data in a spreadsheet; the
independent variables are spaced equally. I need to determine the
first derivative at each of the values of the independent variable,
including the endpoints, within the spreadsheet, and would prefer to do
it automatically, rather than do a new regression for every case study.
Could someone please (1) recommend a numerical differentiation scheme,
and (2) mention the source with explicit formulas (ideally, formulas
suitable for spreadsheet use)?
Thanks.
this is a special situation insofar as you want the derivative for all 
points in the table. there exist special schemes for this, and here
is a good one: (compact difference scheme of order 6)
alpha*u(i1)+u(i)+alpha*u(i+1) = (beta/(2*h))*(f(i+1)f(i1))
+(gamma/(4*h))*(f(i+2)f(i2))
for i=2,...,n1. here f(i)=f(x(i)) , x(i+1)x(i)=h for all i
u(i) is the approximation for f'(x(i)).
alpha=1/3, beta=14/9, gamma=1/9;
this is a linear system of equations with tridigonal matrix, which can be solved
efficiently.
you miss here approximations for the first i=0 and last i=n+1 point. for these
endpoints you must use secail one sided formulas, for example
f'(x(0))=(1/(2*h))*(3*f(0)+4*f(1)f(2)) error const*h^2
f'(x(0))=(1/12*h))*(25*f(0)+48*f(1)36*f(2)+16*f(3)3*f(4)) error const*h^4
for the right endpoint you complete flip these formulas .
hth
peter 

Back to top 


1940LaSalle@gmail.com science forum beginner
Joined: 28 Apr 2006
Posts: 17

Posted: Fri Jul 14, 2006 2:04 pm Post subject:
Re: Recommendation for numerical differentiation formulas?



Peter Spellucci wrote:
Quote:  In article <1152734860.671170.151780@m73g2000cwd.googlegroups.com>,
1940LaSalle@gmail.com writes:
Here's the situation: I have a series of data in a spreadsheet; the
independent variables are spaced equally. I need to determine the
first derivative at each of the values of the independent variable,
including the endpoints, within the spreadsheet, and would prefer to do
it automatically, rather than do a new regression for every case study.
Could someone please (1) recommend a numerical differentiation scheme,
and (2) mention the source with explicit formulas (ideally, formulas
suitable for spreadsheet use)?
Thanks.
this is a special situation insofar as you want the derivative for all
points in the table. there exist special schemes for this, and here
is a good one: (compact difference scheme of order 6)
alpha*u(i1)+u(i)+alpha*u(i+1) = (beta/(2*h))*(f(i+1)f(i1))
+(gamma/(4*h))*(f(i+2)f(i2))
for i=2,...,n1. here f(i)=f(x(i)) , x(i+1)x(i)=h for all i
u(i) is the approximation for f'(x(i)).
alpha=1/3, beta=14/9, gamma=1/9;
this is a linear system of equations with tridigonal matrix, which can be solved
efficiently.
you miss here approximations for the first i=0 and last i=n+1 point. for these
endpoints you must use secail one sided formulas, for example
f'(x(0))=(1/(2*h))*(3*f(0)+4*f(1)f(2)) error const*h^2
f'(x(0))=(1/12*h))*(25*f(0)+48*f(1)36*f(2)+16*f(3)3*f(4)) error const*h^4
for the right endpoint you complete flip these formulas .
hth
peter

This looks promising. If I understand the scheme, the right side of
the first equation yields a vector that is generated by the tabulated
values and the constants of beta and gamma. At the same time, the left
side is a tridiagonal matrix where the nonzero entries are all equal
to alpha, which we also know going in. Now, let's say the table has a
total of j values (and therefore I want j first derivatives): if I
understand things properly, j=i+2. Last but not least, when you say
"completely flip", referring to the onesided formulas, that means that
the constants take the opposite sign; that is, for the jth point:
f'(x(j))=(1/12*h)*[(25*f(j4))+(48*f(j3))+(36*f(j2))+(16*f(j1))+(3*f(j))]
Correct?
Thanks. 

Back to top 


Peter Spellucci science forum Guru
Joined: 29 Apr 2005
Posts: 702

Posted: Fri Jul 14, 2006 5:27 pm Post subject:
Re: Recommendation for numerical differentiation formulas?



In article <1152885890.796128.65800@m79g2000cwm.googlegroups.com>,
1940LaSalle@gmail.com writes:
Quote: 
Peter Spellucci wrote:
In article <1152734860.671170.151780@m73g2000cwd.googlegroups.com>,
1940LaSalle@gmail.com writes:
Here's the situation: I have a series of data in a spreadsheet; the
independent variables are spaced equally. I need to determine the
first derivative at each of the values of the independent variable,
including the endpoints, within the spreadsheet, and would prefer to do
it automatically, rather than do a new regression for every case study.
Could someone please (1) recommend a numerical differentiation scheme,
and (2) mention the source with explicit formulas (ideally, formulas
suitable for spreadsheet use)?
Thanks.
this is a special situation insofar as you want the derivative for all
points in the table. there exist special schemes for this, and here
is a good one: (compact difference scheme of order 6)
alpha*u(i1)+u(i)+alpha*u(i+1) = (beta/(2*h))*(f(i+1)f(i1))
+(gamma/(4*h))*(f(i+2)f(i2))
for i=2,...,n1. here f(i)=f(x(i)) , x(i+1)x(i)=h for all i
u(i) is the approximation for f'(x(i)).
alpha=1/3, beta=14/9, gamma=1/9;
this is a linear system of equations with tridigonal matrix, which can be solved
efficiently.
you miss here approximations for the first i=0 and last i=n+1 point. for these
endpoints you must use secail one sided formulas, for example
f'(x(0))=(1/(2*h))*(3*f(0)+4*f(1)f(2)) error const*h^2
f'(x(0))=(1/12*h))*(25*f(0)+48*f(1)36*f(2)+16*f(3)3*f(4)) error const*h^4
for the right endpoint you complete flip these formulas .
hth
peter
This looks promising. If I understand the scheme, the right side of
the first equation yields a vector that is generated by the tabulated
values and the constants of beta and gamma. At the same time, the left
side is a tridiagonal matrix where the nonzero entries are all equal
to alpha, which we also know going in. Now, let's say the table has a
total of j values (and therefore I want j first derivatives): if I
understand things properly, j=i+2. Last but not least, when you say
"completely flip", referring to the onesided formulas, that means that
the constants take the opposite sign; that is, for the jth point:
f'(x(j))=(1/12*h)*[(25*f(j4))+(48*f(j3))+(36*f(j2))+(16*f(j1))+(3*f(j))]
Correct?
Thanks.

no, flip in a geometric sense right to left. means
f'(x(n+1))=(1/(12*h))
*(25*f(x(n+1)+48*f(x(n))36*f(x(n1))+16*f(x(n2))3*f(x(n3)))
you need these special one sided formulae only for the first data point
(I named it x(0)) and the last one x(n+1) because these are not covered by
the 3 point compact scheme. all other derivatives come out from the
tridiagonal solve, and you are right: the right hand side is made up from the
table and looking at the indices you see: f(x(0)) up to f(x(n+1)) are needed
there and give you u(1) up to u(n) which correspond to f'(x(1)) up to f'(x(n))
good luck
peter 

Back to top 


1940LaSalle@gmail.com science forum beginner
Joined: 28 Apr 2006
Posts: 17

Posted: Mon Jul 17, 2006 11:51 am Post subject:
Re: Recommendation for numerical differentiation formulas?



Peter Spellucci wrote:
Quote:  In article <1152885890.796128.65800@m79g2000cwm.googlegroups.com>,
1940LaSalle@gmail.com writes:
Peter Spellucci wrote:
no, flip in a geometric sense right to left. means
f'(x(n+1))=(1/(12*h))
*(25*f(x(n+1)+48*f(x(n))36*f(x(n1))+16*f(x(n2))3*f(x(n3)))
you need these special one sided formulae only for the first data point
(I named it x(0)) and the last one x(n+1) because these are not covered by
the 3 point compact scheme. all other derivatives come out from the
tridiagonal solve, and you are right: the right hand side is made up from the
table and looking at the indices you see: f(x(0)) up to f(x(n+1)) are needed
there and give you u(1) up to u(n) which correspond to f'(x(1)) up to f'(x(n))
good luck
peter

In thinking about this scheme, it seems I have a few more questions
about the mechanics of it. For the sake of discussion, let's say the
data involved have a total of j points. Then the right side of the
equation would appear to be a matrix (that is, a vector) with one
column and j1 rows (there are no rows corresponding to x(0) and x(j)
). The left side is the tridiagonal matrix we've mentioned before. I
may be missing something fundamental here, so please bear with me: when
one inverts the matrix on the left and does the appropriate matrix
multiplication, one gets a solution vector (again, one column with j1
rows)at least, I believe that's the case. In that solution vector,
the first row would yield the value of u(x(1)), the second, u(x(2)),
etc., up to u(x(j1)), correct? (What I know of matrix
algebra/manipulation has been acquired purely as needed; I've never
taken a formal course.)
Also: I'd like to verify that all of the coefficients on the left side
have the same sign. Unless I set up the matrices incorrectlynot out
of the questionI would expect that the results would all have the
same sign if the tabulated function is monotonic with no local maxima
or minima within the range of the independent variable.
Last but not least: what's the reference for the onesided formulas?
I'd like to see/read more.
Thanks again for your patience: this is very valuable. 

Back to top 


Peter Spellucci science forum Guru
Joined: 29 Apr 2005
Posts: 702

Posted: Mon Jul 17, 2006 1:37 pm Post subject:
Re: Recommendation for numerical differentiation formulas?



In article <1153137085.886668.152400@p79g2000cwp.googlegroups.com>,
1940LaSalle@gmail.com writes:
Quote: 
Peter Spellucci wrote:
In article <1152885890.796128.65800@m79g2000cwm.googlegroups.com>,
1940LaSalle@gmail.com writes:
Peter Spellucci wrote:
no, flip in a geometric sense right to left. means
f'(x(n+1))=(1/(12*h))
*(25*f(x(n+1)+48*f(x(n))36*f(x(n1))+16*f(x(n2))3*f(x(n3)))
you need these special one sided formulae only for the first data point
(I named it x(0)) and the last one x(n+1) because these are not covered by
the 3 point compact scheme. all other derivatives come out from the
tridiagonal solve, and you are right: the right hand side is made up from the
table and looking at the indices you see: f(x(0)) up to f(x(n+1)) are needed
there and give you u(1) up to u(n) which correspond to f'(x(1)) up to f'(x(n))
good luck
peter
In thinking about this scheme, it seems I have a few more questions
about the mechanics of it. For the sake of discussion, let's say the
data involved have a total of j points. Then the right side of the
equation would appear to be a matrix (that is, a vector) with one
column and j1 rows (there are no rows corresponding to x(0) and x(j)
). The left side is the tridiagonal matrix we've mentioned before. I
may be missing something fundamental here, so please bear with me: when
one inverts the matrix on the left and does the appropriate matrix
multiplication, one gets a solution vector (again, one column with j1
rows)at least, I believe that's the case. In that solution vector,
the first row would yield the value of u(x(1)), the second, u(x(2)),
etc., up to u(x(j1)), correct? (What I know of matrix
yes 
Quote:  algebra/manipulation has been acquired purely as needed; I've never
taken a formal course.)
this is a linear system of equations with a tridiagoanl matrix 
and you never invert the matrix, you solve the system by standard
Gaussian elimination with amounts in just some j arithmetic operations
and hence is extremely cheap.
Quote:  Also: I'd like to verify that all of the coefficients on the left side
have the same sign. Unless I set up the matrices incorrectlynot out
of the questionI would expect that the results would all have the
same sign if the tabulated function is monotonic with no local maxima
or minima within the range of the independent variable.
yes, if your function data are not subject to noise. noise will 
blow up by a factor 1/h, hence this may destroy these properties
if it is too large
Quote:  Last but not least: what's the reference for the onesided formulas?
I'd like to see/read more.
Thanks again for your patience: this is very valuable.

the linear system is from
Quarteroni, Alfio; Sacco, Riccardo; Saleri, Fausto
Numerical mathematics. (English)
Texts in Applied Mathematics. 37. New York, NY: Springer.
the one sided formula is from
Schmeisser, Gerhard; Schirmeier, Horst
Praktische Mathematik. (German)
de Gruyter Lehrbuch. BerlinNew York: Walter de Gruyter
but there should be other sources containing it it is obtained
simply by Taylor's formula for f(x+k*h) k=0,1,2,3
resp. f(xk*h) and combining these values linearly such that the f'(x)
obtains with error term h^4
hth
peter 

Back to top 


Google


Back to top 



The time now is Tue Mar 26, 2019 4:24 am  All times are GMT

