Message Boards Message Boards

0
|
2467 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Is there a sign error in the FDFormula in the Mathematica tutorial?

Posted 12 years ago
Looking at http://reference.wolfram.com/mathematica/tutorial/NDSolvePDE.html there is a formula called FDFormula there. (near the top)

I think the error term given by that formula above has the wrong sign.

According to its documentation, it says
Here m is the order of the derivative,n is the number of grid intervals enclosed in the stencil, and s is the number of grid intervals between the point at which the derivative is approximated and the leftmost edge of the stencil.
FDFormula[m_, n_, s_]
Therefore , to obtain a forward difference for first derivative, m=1, n=1 and now s=0, since that is the distance between the left-most edge and the point of expansion.  The call becomes
FDFormula[1, 1, 0]
but this gives an error term as (h*f''/2), where it should be (-h*f''/2)
and to obtain the backward difference, s=1, since now the distance is one to the left edge.
FDFormula[1, 1, 1]
and now it gives the error term as (-h*f''/2) instead of (h*f''/2).
Also for centered difference, it does give the wrong sign
FDFormula[1, 2, 1]
The eror term given is  1/6 *h^2*f''', when it should be a minus that.

Could someone please double check this? May be I am not reading the API correctly.  I do not know how to enter Latex here, else will show the derivation, but it is only 2-3 lines and any one can verify this by hand.

thanks,
--Nasser
POSTED BY: Nasser M. Abbasi
The 'error term', as returned by FDFormula, is correct when taken to mean the Taylor approximation error. For example, consider the following finite difference
fd = (45 f[x] - 154 f[x + h] + 214 f[x + 2 h] - 156 f[x + 3 h] + 61 f[x + 4 h] - 10 f[x + 5 h])/(12 h^2);
which is being approximated by a Taylor expansion
Series[fd, {h, 0, 4}]

(* Out[8]= f''[x] - (137/180) h^4 f^(6)[x] + O[h]^5 *)
so fd is approximately equal to f'' and the leading term of the Taylor approximation error is - (137/180) h^4 f^(6).

However, if we want the error being made when f'' is substituted by the finite difference, it would be
Series[f''[x] - fd, {h, 0, 4}]

(* Out[9]= (137/180) h^4 f^(6)[x] + O[h]^5 *)
and that indeed has the opposite sign.

Even though when actually using these error terms in convergence estimates, one only cares about their absolute value, I agree that the example wording might be confusing. Thank you for bringing this to our attention.
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract