JamesTaylor - Author
JamesTaylor - Author
Abstract
In this paper, the implementation of two important methods in numer-
ical partial differential equations is explored. A finite difference method
and a spectral method are employed to obtain a solution to the Korteweg-
de Vries equation, and several aspects of the solutions obtained are com-
pared, including convergence, stability, and computing time.
1 Introduction
Partial differential equations provide interesting challenges in numerical
analysis as partial differential equations are central topic in applied math-
ematics. One important partial differential equation is the Korteweg-de
Vries equation, which describes the propagation of a type of nonlinear,
dispersive wave. The Korteweg-de Vries equation is given by
∂ ∂ ∂3
φ(x, t) + αφ(x, t) φ(x, t) + ν 3 φ(x, t) = 0, (1)
∂t ∂x ∂x
where α and ν are constants.[1] Several closed-form solutions to (1) are
known, and the physical phenomenon these solutions represent are re-
ferred to as solitons. By classification, (1) is a hyperbolic partial differen-
tial equation.
In this paper, I consider the Korteweg-de Vries equation with an initial
Gaussian distribution centered on a domain of [−π, π]. I will take α = 1,
ν = 1, and I will assume the solution is assumed periodic on the inter-
val, with φ(−π, t) = φ(π, t), so no other boundary conditions need to be
specified.
Many different techniques have been developed to solve partial differ-
ential equations, and three main classes of methods have emerged: finite
difference methods, finite element methods, and spectral methods. Fi-
nite difference methods are based on local approximations to the solution
at discrete points in the domain.[3] In finite difference methods, formu-
lae approximating the derivative at discrete points are derived through
various techniques, for example, through finite approximations to Taylor
1
polynomial expansions. Error is introduced into the derivative because
the distance between points from which the derivative is computed is a
fixed positive value. As the distance between grid points decreases, the
error can be somewhat reduced. Additionally, as the stencil size used to
approximate the derivative at a point increases, the derivative approx-
imation is typically more accurate, but larger stencils require increased
computer storage, which is limited. Nevertheless, finite difference schemes
are attractive because they are fairly easy to implement.
In contrast with the local approximation approach of finite difference
methods, spectral methods are based on the global expansion of the solu-
tion in terms of a set of basis functions, for example a Fourier expansion.[2]
The expansion is substituted into the equation, and a transformation is
used to change the partial differential equation in physical time and space
into an ordinary differential equation in physical time. In general, an infi-
nite linear combination is required for the expansion, but implementation
on the computer obviously requires that the series expansion be truncated.
The truncation introduces error into the algorithm. Although many dif-
ferent sets of basis functions can be used for expansion, Fourier expansions
and expansions in Chebyshev polynomials are advantageous for computing
because the fast Fourier transformation can be used to quickly transform
the expansion. The ordinary differential equation can then be solved by
many well-developed techniques, such as the Runge-Kutta method.
In this paper, I will explore finite difference and spectral methods
through their application to the Korteweg-de Vries equation. I will then
compare some basic convergence and stability properties of the solutions
obtained by each of these methods.
2 Methods
For the problem considered in this paper, the Crank-Nicolson finite dif-
ference approach is appropriate because the Korteweg-de Vries equation
is a hyperbolic partial differential equation. The approach I use is mod-
eled after the approach taken in [1]. For the time derivative, the forward
difference formula,
∂ 1 ` n+1
φj + φn+1 n n
´
φ(xj+ 1 , tn+ 1 ) = j+1 − φj − φj+1 , (2)
∂t 2 2 2τ
is used, where τ is the step size in time. For the first partial with respect
to the spatial variable, x,
∂ 1 ` n+1
φ(xj+ 1 , tn+ 1 ) = φ − φn+1 + φn n´
j+1 − φj , (3)
∂x 2 2 2h j+1 j
is used, where h is the step size in space. For the third partial with respect
to x, the difference formula,
∂3 1 ` n+1
φ(xj+ 1 , tn+ 1 ) = φ − 3φn+1
j+1 + 3φj
n+1
− φn+1 n n n n ´
j−1 + φj+2 − 3φj+1 + 3φj − φj−1 ,
∂x3 2 2 2h3 j+2
(4)
is used. A complication for the implicit finite difference method that is
encountered with the Korteweg-de Vries equation is the nonlinear convec-
tive term. In the Crank-Nicolson scheme, the discretized time derivative
2
is centered in between discrete time points, and it is possible to center the
spatial derivatives around the same points, but there is no obvious way
of centering the nonlinear portion of the convective term between dis-
crete time points. I will use a predictor-corrector method to approximate
the nonlinear convective term between grid point as in [1]. A standard
Crank-Nicolson approach is then taken by solving a system of equations
using matrices and progressing the solution forward in time. The matrices
are sparse and toeplitz. The boundary conditions in the problem are re-
ally simply conditions of periodicity at the boundaries, which the matrix
entries enforce.
For the spectral method, the natural choice of basis are the trigono-
metric functions because φ(x, t) is periodic on [−π, π]. As noted above,
the expansion can be implemented through the fast Fourier transform,
and the problem is thereby converted into an ordinary differential equa-
tion in time. It is typically difficult to implement the spectral method
for time-stepping because it is difficult to ensure stability. Therefore, a
Runge-Kutta method will be implemented to solve the ordinary differ-
ential equation and progress the solution forward in time. According to
[2], even though the rate of convergence is sacrificed to a degree by intro-
ducing finite difference formulae, the overall accuracy and convergence of
the combined spectral/finite-difference method is nonetheless acceptable
because the small time step required for reasonable accuracy only affects
the computing time but not the required storage since only the derivative
matrix associated with the spatial variable needs to be stored. The basic
formulation of the problem I use can be found in [2].
3
4
3.5
4
3
3.5
2.5
3
2
2.5
phi(x,0.25)
1.5
2
1
phi(x,0)
1.5
0.5
1
0
0.5
−0.5
0
−1
−0.5
−1.5
−1 −3 −2 −1 0 1 2 3
x
−1.5
−3 −2 −1 0 1 2 3
x
3.5
4
3
3.5
2.5
3
2
2.5
phi(x,0.85)
1.5
2
phi(x,0.475)
1
1.5
0.5
1
0
0.5
−0.5
0
−1
−0.5
−1.5
−1 −3 −2 −1 0 1 2 3
x
−1.5
−3 −2 −1 0 1 2 3
x
4
spatial grid had 256 spatial points and a time step of 0.0025. I allowed
the system to evolve until t = 2, and I checked the solution at t = 1 at
the left boundary point, x = −π, and also at the center of the interval,
x = 0. To check convergence, I used
„ «
φmedium (x, t) − φcoarse (x, t)
log = O(convergence). (5)
φf ine (x, t) − φmedium (x, t)
With the Crank-Nicolson method I found slightly better than linear con-
vergence, with the center point converging slightly faster than the left
boundary point. Plots demonstrating the convergence on the whole in-
terval and at the center point are displayed below in Figures 5 and 6.
2.5
2.85
2
φ(x,1)
φ(x,1)
2.8
1.5
1 2.75
0.5
2.7
0
−0.5 2.65
−3 −2 −1 0 1 2 3 −0.3 −0.2 −0.1 0 0.1 0.2 0.3
x x
5
Convergence of Fourier Spectral Method at t = 1 Convergence of Fourier Spectral Method at t = 1
4
Coarse res Coarse res
3.5 Medium res Medium res
Fine res 2.9 Fine res
3
2.8
2.5
2.7
2
phi(x,1)
phi(x,1)
1.5 2.6
1
2.5
0.5
2.4
0
2.3
−0.5
−3 −2 −1 0 1 2 3 −0.5 0 0.5
x x
4 Conclusion
After comparing the two algorithms, the spectral method is clearly supe-
rior in several ways. To begin with, although the finite difference method
is for the most part simple in its implementation, the spectral method was
in some ways actually more simple to implement because of the availabil-
ity of the fast Fourier transform in MATLAB. The spectral method took
much less computing time than the finite difference method to perform the
same task, and it provided a solution converging at a slightly faster rate
than the finite difference method. Additionally, the nonlinearity of the
Korteweg-de Vries equation did not pose a challenge for the spectral but
fit seamlessly into the Fourier spectral approach while the finite difference
method had to be modified slightly with a predictor-corrector algorithm.
Still, the spectral method was very sensitive to its stability conditions,
whatever they are, and worked very poorly in with nonstable parameters.
The finite difference method, on the other hand, was more robust than
the spectral method in that the grid could be refined in a straightforward
way without compromising stability, if not indefinitely, at least beyond
the stability limits of the spectral method.
References
[1] Ross L. Spencer Computational Physics 430: Partial Differential
Equations 2006: Brigham Young University, UT.
[2] Lloyd N. Trefethen Spectral Methods in MATLAB 2000: Society For
Industrial and Applied Mathematics, PA.
[3] Richard L. Burden and J. Douglas Faires (Numerical Analysis, 8th
Edition) 2005: Thomson Brooks/Cole, CA.