0% found this document useful (0 votes)
16 views6 pages

JamesTaylor - Author

The document compares a finite difference method and spectral method for solving the Korteweg-de Vries equation numerically. It describes implementing each method and comparing aspects of the solutions like convergence, stability, and computing time.

Uploaded by

Ashmitha Nagesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

JamesTaylor - Author

The document compares a finite difference method and spectral method for solving the Korteweg-de Vries equation numerically. It describes implementing each method and comparing aspects of the solutions like convergence, stability, and computing time.

Uploaded by

Ashmitha Nagesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

A Comparison of a Finite-difference and a

Spectral Method for the Korteweg-de Vries


Equation
James B. Taylor, Jr.
December 17, 2007

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 Results and Discussion


Qualitatively, both the finite difference and the spectral method demon-
strated similar results. The wave begins as a Gaussian pulse centered
in the interval. It begins moving towards the left, but a quick-moving
pulse with a small amplitude develops to the right of the original pulse
and overtakes it. The two pulses merge briefly, but they reemerge with
their original amplitude and propagating speeds, only changed by a phase
shift with the faster moving wave in front. Since the grid is periodic, the
smaller wave leaves to the left of the grid but reappears at the right of
the grid, overtaking the larger wave again. This process can be seen in
Figures 1-4 below.
With both schemes I checked convergence by halving the spatial and
time grids two times, obtaining a solution on a coarse, medium, and fine
grid. For the coarse grid, I used 64 spatial points and a time step of 0.01. I
chose the spatial step in this way simply to be consistent with the spectral
method, which required 2n spatial points for some n since the fast Fourier
transform was used. Also, using even numbers insures that certain spatial
values are always included in the discrete domain, making convergence
testing simpler. Finally, I tried to use as much of the same code in both
algorithms so that I could somewhat compare the computing time required
in each case using MATLAB’s tic/toc commands. Therefore, the medium
grid consisted of 128 spatial points and a time step of 0.005, and the fine

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

Figure 2: A small pulse centered


Figure 1: An initial Gaussian pulse. near x = 2 overtakes the initial
(t = 0) pulse. (t = 0.25)

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

Figure 4: The pulses reemerge un-


Figure 3: The pulses merge. (t = changed except for a phase shift.
0.475) (t = 0.85)

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.

Convergence of Crank−Nicolson at t = 1 Convergence of Crank−Nicolson at t = 1


4
Coarse res 2.95 Coarse res
3.5 Medium res Medium res
Fine res Fine res
2.9
3

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

Figure 5: Convergence of Crank- Figure 6: Convergence of Crank-


Nicolson Method Nicolson Method at x = 0

For the collocation method, convergence was much more difficult to


check because the stability of the algorithm was highly sensitive to the
relationship between the number of grid points and the time step. Indeed,
I was able to use the same pairs of time and spatial step sizes, but for the
next step of n = 256 grid points, the Crank-Nicolson method remained
stable and continued convergent at about the same rate while the spec-
tral method became unstable. A much smaller time step was needed to
obtain a solution that continued to converge. I do not know what the
actual stability requirement is for the spectral method, but the time step
size obviously has very severe limits. Nevertheless, for the stable time
and space step pairs, I found that the solution converged slightly better
than linearly near the boundary but converged quadratically at the center
point. The plots below (Figures 7 and 8) demonstrate this converge on
the whole interval and at the center of the interval.
The computing time for the two methods was markedly different, prob-
ably largely due to the speed of the fast Fourier transform in the spectral
method. A very rough estimate of the time for each algorithm to complete
with MATLAB’s tic/toc command showed that the spectral found the so-
lution for all three grid resolutions in a little more than a second, while
the much slower finite difference method required over twenty seconds to
perform the same task!

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

Figure 7: Convergence of Fourier Figure 8: Convergence of Fourier


Spectral Method Spectral Method at x = 0

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.

You might also like