centered finite differences

1
Centered finite difference coefficients on uniform grids Setup Establish uniform weights formula as given in Fornberg, B. "Calculation of Weights in Finite Difference Formulas." SIAM Review 40, no. 3 (1998): 685-691 and discussed within http : // reference.wolfram.com/mathematica/tutorial/NDSolvePDE.html. In[273]:= UFDWeights@m_, n_, s_D := CoefficientList@Normal@Series@x s Log@xD m , 8x, 1, n<D h m D,xD Compute centered differences and rescale coefficients according to their least common multiple. In[274]:= CDCoefficients@m_, n_D := With@8weights = UFDWeights@m, n, n 2D<, With@8lcm = Apply@LCM, Denominator@weights h m DD<, 8lcm h m , weights h m lcm<DD First derivative In[275]:= CDCoefficients@1, 2D Out[275]= 82h, 8- 1, 0, 1<< In[276]:= CDCoefficients@1, 4D Out[276]= 812 h, 81, - 8, 0, 8, - 1<< In[277]:= CDCoefficients@1, 6D Out[277]= 860 h, 8- 1, 9, - 45, 0, 45, - 9, 1<< In[278]:= CDCoefficients@1, 8D Out[278]= 8840 h, 83, - 32, 168, - 672, 0, 672, - 168, 32, - 3<< Second derivative In[279]:= CDCoefficients@2, 2D Out[279]= 9h 2 , 81, - 2, 1<= In[280]:= CDCoefficients@2, 4D Out[280]= 912h 2 , 8- 1, 16, - 30, 16, - 1<= In[281]:= CDCoefficients@2, 6D Out[281]= 9180 h 2 , 82, - 27, 270, - 490, 270, - 27, 2<= In[282]:= CDCoefficients@2, 8D Out[282]= 95040 h 2 , 8- 9, 128, - 1008, 8064, - 14350, 8064, - 1008, 128, - 9<=

Upload: rhysu

Post on 10-Apr-2015

352 views

Category:

Documents


0 download

DESCRIPTION

How to generate centered finite difference coefficients on uniform grids with Mathematica, including first and second order finite difference derivatives with accuracy through eighth order.

TRANSCRIPT

Page 1: Centered Finite Differences

Centered finite difference coefficients on uniform grids

Setup

Establish uniform weights formula as given in Fornberg, B. "Calculation of Weights in Finite Difference Formulas." SIAMReview 40, no. 3 (1998): 685-691 and discussed withinhttp : // reference.wolfram.com/mathematica/tutorial/NDSolvePDE.html.

In[273]:= UFDWeights@m_, n_, s_D := CoefficientList@Normal@Series@xs Log@xDm, 8x, 1, n<D � hmD, xD

Compute centered differences and rescale coefficients according to their least common multiple.

In[274]:= CDCoefficients@m_, n_D :=

With@8weights = UFDWeights@m, n, n � 2D<, With@8lcm = Apply@LCM, Denominator@weights hmDD<,8lcm hm, weights hm lcm<DD

First derivative

In[275]:= CDCoefficients@1, 2D

Out[275]= 82 h, 8-1, 0, 1<<

In[276]:= CDCoefficients@1, 4D

Out[276]= 812 h, 81, -8, 0, 8, -1<<

In[277]:= CDCoefficients@1, 6D

Out[277]= 860 h, 8-1, 9, -45, 0, 45, -9, 1<<

In[278]:= CDCoefficients@1, 8D

Out[278]= 8840 h, 83, -32, 168, -672, 0, 672, -168, 32, -3<<

Second derivative

In[279]:= CDCoefficients@2, 2D

Out[279]= 9h2, 81, -2, 1<=

In[280]:= CDCoefficients@2, 4D

Out[280]= 912 h2, 8-1, 16, -30, 16, -1<=

In[281]:= CDCoefficients@2, 6D

Out[281]= 9180 h2, 82, -27, 270, -490, 270, -27, 2<=

In[282]:= CDCoefficients@2, 8D

Out[282]= 95040 h2, 8-9, 128, -1008, 8064, -14 350, 8064, -1008, 128, -9<=