 Forum index » Science and Technology » Math » num-analysis
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. 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 = (R-L)/(2*h)
for use in the "interior"

2nd) 1st deriv at the position of L = (4*M-3*L-R)/(2*h)
use this at the left endpoint

3rd) 1st deriv at the position of R = (L-4*M+3*R)/(2*h)
use this at the right endpoint

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany 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? 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(i-1)+u(i)+alpha*u(i+1) = (beta/(2*h))*(f(i+1)-f(i-1))
+(gamma/(4*h))*(f(i+2)-f(i-2))
for i=2,...,n-1. 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 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(i-1)+u(i)+alpha*u(i+1) = (beta/(2*h))*(f(i+1)-f(i-1)) +(gamma/(4*h))*(f(i+2)-f(i-2)) for i=2,...,n-1. 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 non-zero 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 one-sided formulas, that means that
the constants take the opposite sign; that is, for the j-th point:

f'(x(j))=(1/12*h)*[(25*f(j-4))+(-48*f(j-3))+(36*f(j-2))+(-16*f(j-1))+(3*f(j))]

Correct?

Thanks. 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? 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(i-1)+u(i)+alpha*u(i+1) = (beta/(2*h))*(f(i+1)-f(i-1)) +(gamma/(4*h))*(f(i+2)-f(i-2)) for i=2,...,n-1. 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 non-zero 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 one-sided formulas, that means that the constants take the opposite sign; that is, for the j-th point: f'(x(j))=(1/12*h)*[(25*f(j-4))+(-48*f(j-3))+(36*f(j-2))+(-16*f(j-1))+(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(n-1))+16*f(x(n-2))-3*f(x(n-3)))

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 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(n-1))+16*f(x(n-2))-3*f(x(n-3))) 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 j-1 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 j-1
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(j-1)), 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 incorrectly--not out
of the question--I 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 one-sided formulas?
I'd like to see/read more.

Thanks again for your patience: this is very valuable. 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? 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(n-1))+16*f(x(n-2))-3*f(x(n-3))) 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 j-1 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 j-1 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(j-1)), 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 incorrectly--not out of the question--I 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 one-sided 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. Berlin-New 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(x-k*h) and combining these values linearly such that the f'(x)
obtains with error term h^4

hth
peter  Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 The time now is Tue Mar 26, 2019 4:24 am | All times are GMT Forum index » Science and Technology » Math » num-analysis
 Jump to: Select a forum-------------------Forum index|___Science and Technology    |___Math    |   |___Research    |   |___num-analysis    |   |___Symbolic    |   |___Combinatorics    |   |___Probability    |   |   |___Prediction    |   |       |   |___Undergraduate    |   |___Recreational    |       |___Physics    |   |___Research    |   |___New Theories    |   |___Acoustics    |   |___Electromagnetics    |   |___Strings    |   |___Particle    |   |___Fusion    |   |___Relativity    |       |___Chem    |   |___Analytical    |   |___Electrochem    |   |   |___Battery    |   |       |   |___Coatings    |       |___Engineering        |___Control        |___Mechanics        |___Chemical

 Topic Author Forum Replies Last Post Similar Topics Help in identifying a numerical method Don11135 num-analysis 2 Thu Jul 20, 2006 8:56 pm noncommutative algebra book recommendation? adomplayer@yahoo.com Math 2 Wed Jul 19, 2006 9:35 pm Numerical differentiation formulas? 1940LaSalle@gmail.com Math 2 Wed Jul 12, 2006 8:01 pm integrand numerical singular near boundary Axel Vogt num-analysis 2 Wed Jul 12, 2006 6:13 pm Numerical diagonalization by not using zgeev? MWimmer num-analysis 6 Tue Jul 11, 2006 11:11 am