Difference between revisions of "Numerical Solution of the KdV"
Line 30: | Line 30: | ||
(note that there are other ways of writing this transform). The most | (note that there are other ways of writing this transform). The most | ||
important property of the Fourier transform is that | important property of the Fourier transform is that | ||
− | <center><math>\begin{matrix} | + | <center><math> |
+ | \begin{matrix} | ||
\int_{-\infty }^{\infty }\left( \partial _{x}f\left( x\right) \right) | \int_{-\infty }^{\infty }\left( \partial _{x}f\left( x\right) \right) | ||
− | \mathrm{e}^{-\mathrm{i}kx}\mathrm{d}x &=&-\int_{-\infty }^{\infty }f\left( x\right) \left( \ | + | \mathrm{e}^{-\mathrm{i}kx}\mathrm{d}x &=&-\int_{-\infty }^{\infty }f\left( x\right) |
− | + | \left( \partial_{x}\mathrm{e}^{-\mathrm{i}kx}\right) \mathrm{d}x \\ | |
&=&-k\int_{-\infty }^{\infty }f\left( x\right) \mathrm{e}^{-\mathrm{i}kx}\mathrm{d}x | &=&-k\int_{-\infty }^{\infty }f\left( x\right) \mathrm{e}^{-\mathrm{i}kx}\mathrm{d}x | ||
− | + | \mathrm{d} | |
+ | \end{matrix} | ||
+ | </math></center> | ||
where we have assumed that the function <math>f\left( x\right) </math> vanishes at <math>\pm | where we have assumed that the function <math>f\left( x\right) </math> vanishes at <math>\pm | ||
\infty .</math> This means that the Fourier transform converts differentiation to | \infty .</math> This means that the Fourier transform converts differentiation to |
Revision as of 01:43, 24 August 2010
Nonlinear PDE's Course | |
---|---|
Current Topic | Numerical Solution of the KdV |
Next Topic | Conservation Laws for the KdV |
Previous Topic | Introduction to KdV |
Numerical Solution to the KdV
We present here a method to solve the KdV equation numerically. There are many different methods to solve the KdV and we use here a spectral method which has been found to work well. \ Spectral methods work by using the Fourier transform (or some varient of it) to calculate the derivative.
Fourier Transform
Recall that the Fourier transform is given by
and the inverse Fourier transform is given by
(note that there are other ways of writing this transform). The most important property of the Fourier transform is that
where we have assumed that the function [math]\displaystyle{ f\left( x\right) }[/math] vanishes at [math]\displaystyle{ \pm \infty . }[/math] This means that the Fourier transform converts differentiation to multiplication by [math]\displaystyle{ k }[/math].
Solution for the Linearized KdV
We begin with a simple example. Suppose we want to solve the linearized KdV equation
subject to solve initial conditions
We can solve this equation by taking the Fourier transform. and obtain
So that
Therefore
Numerical Implementation Using the FFT
The Fast Fourier Transform (FFT)\ is a method to calculate the fourier transform efficiently for discrete sets of points. These points need to be evenly spaced in the [math]\displaystyle{ x }[/math] plane and are given by
(note they can start at any [math]\displaystyle{ x }[/math] value). For the FFT to be as efficient as possible [math]\displaystyle{ N }[/math] should be a power of [math]\displaystyle{ 2. }[/math] Corresponding to the discrete set of points in the [math]\displaystyle{ x }[/math] domain is a discrete set of points in the [math]\displaystyle{ k }[/math] plane given by
where [math]\displaystyle{ \Delta k=2\pi /(N\Delta x). }[/math] Note that this numbering seems slighly odd and is due to aliasing. We are not that interested in the frequency domain solution but we need to make sure that we select the correct values of [math]\displaystyle{ k }[/math] for our numerical code.
Numerical Code for the Linear KdV
Here is the code to solve the linear KdV using MATLAB
N = 1024;
x = linspace(-10,10,N);
delta_x = x(2) - x(1);
delta_k = 2*pi/(N*delta_x);
k = [0:delta_k:N/2*delta_k,-(N/2-1)*delta_k:delta_k:-delta_k];
f = exp(-x.^2);
f_hat = fft(f);
u = ifft(f_hat.*exp(i*k.^3*t);
Numerical Solution of the KdV
It turns out that a method to solve the KdV equation can be derived using spectral methods. We begin with the KdV equation written as
The Fourier transform of the KdV is therefore
We solve this equation by a split step method. We write the equation as
We can solve
exactly while the equation
needs to be solved by time stepping. The idea of the split step method is to solve alternatively each of these equations when stepping from [math]\displaystyle{ t }[/math] to [math]\displaystyle{ t+\Delta t. }[/math] Therefore we solve
Note that we are using Euler's method to time step and that the solution could be improved by using a better method, such as the Runge-Kutta 4 method.
The only slighly tricky thing is that we have both [math]\displaystyle{ u }[/math] and [math]\displaystyle{ \hat{u} }[/math] in the equation, but we can simply use the Fourier transform to connect these. The equation then becomes
Numerical Code to solve the KdV by the split step method
Here is some code to solve the KdV using MATLAB
N = 256;
x = linspace(-10,10,N);
delta_x = x(2) - x(1);
delta_k = 2*pi/(N*delta_x);
k = [0:delta_k:(N/2-1)*delta_k,0,-(N/2-1)*delta_k:delta_k:-delta_k];
c_1=10;
c_2 = 5;
u = 1/2*c_1*(sech(sqrt(c_1)*(x+8)/2)).^2 + 1/2*c_2*(sech(sqrt(c_2)*(x+5)/2)).^2;
delta_t = 0.4/N^2;
tmax = 1; nmax = round(tmax/delta_t);
U = fft(u);
for n = 1:nmax
% first we solve the linear part
U = U.*
%then we solve the non linear part
U = U +delta_t*;
end