| ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Numerical Differentiation Using FourierJing B. WangUniversity of Western Australia Nedlands WA 6009 Australia wang@physics.uwa.edu.au A common numerical task is to evaluate the derivatives of a data set given on a numerical mesh. For example, in simulating
quantum wavepacket scattering using the time-dependent Schrödinger's equation, the dominant computational effort is in the
evaluation of the second-order spatial derivatives of system wavefunctions [1, 2]. In the five-point finite-difference method (FD5), the second derivative of a data set ![]() where ![]() However, finite-difference methods are based on local approximations to the derivative operator, which brings about error. Also, the convergence with decreasing grid spacing is slow. A more accurate and computationally efficient scheme [3], based on the discrete Fourier transform (DFT), uses the fact that if
for a function ![]() It follows that the derivatives can be evaluated by firstly calculating For
where
where For any sampling interval ![]() where
The DFT scheme provides a global representation of the derivative operator and is highly accurate for functions with periodic boundary conditions. For one-dimensional data sets, implementation of equation (4) is straightforward. The kernel and the nth discrete derivative of the data set, data, with spacing (Since there must be constant spacing, The following code is included to handle derivatives of order zero, required for the generalization to higher dimensions. The syntax of DFTDerivative is based on that of Derivative. Re is included to eliminate the small imaginary component that can arise during computation. Although the derivation refers
to the interval For the Gaussian data set, the results of DFTDerivative[n] for Here, DFTDerivative[9][data][ These figures show that DFTDerivative[n] is extremely accurate even for high To compare the numerical error in evaluating the second derivatives using the FD5, FD7, and DFT methods, and to examine the
relative convergence of these methods as a function of grid spacing, Similarly, When There is a limitation to the DFT scheme because the Fourier transformation implies periodic boundary conditions in which the last point of the data set needs to be connected smoothly to the starting point. For Gaussian wavepackets, which rapidly approach zero far from the "center" of the wavepacket, such a boundary condition is clearly satisfied since the wavepackets have essentially zero values at the boundaries. This scheme works equally well for functions with periodic boundaries. The code is easily extended to arbitrary dimensions, with possibly different grid spacings for each dimension, using Outer. For a two-dimensional Gaussian data set, the difference between the exact derivative, The DFT representation of the derivative operator is global, giving it improved accuracy over local representations. Moreover, the calculation of higher-order derivatives using the DFT scheme requires little extra computing in contrast to, for example, the finite-difference methods. The code is simple, its structure transparent, and the generalization to arbitrary dimension is straightforward. Robert Knapp (rknapp@wolfram.com) comments: In applications it is important to cache the computation of Kernel. If the data consists of machine numbers, improved efficiency is possible if Kernel is a packed array. Doing this takes more work (and some type-detecting code), but it can make a huge difference in performance. Code for automatic computation of numerical derivatives using an extension of these ideas is planned for incorporation into a future version of Mathematica. Copyright © 2002 Wolfram Media, Inc. All rights reserved. |