Hi everybody,
I am a new Julia user. I try to solve KdV equation with the aid of DifferentialEquations.jl. Here is my code:
using DifferentialEquations, DiffEqOperators
using Plots
a = 1
u_analytic(x) = 3*a*a/cosh(a*0.5*(x-3*π))^2
nknots = 1024
h = 10*π/(nknots)
knots = range(0, step=h, length=nknots)
const Δ = CenteredDifference(1, 2, h, nknots)
const Δ3 = CenteredDifference(3, 2, h, nknots)
const bc = PeriodicBC(Float64)
t0 = 0.0
t1 = 20.0
u0 = u_analytic.(knots)
step(u,p,t) = -1*u*Δ*bc*u - Δ3*bc*u
prob = ODEProblem(step, u0, (t0, t1))
alg = KenCarp4()
sol = solve(prob, alg,reltol=1e-12)
plot(knots, [sol(i) for i in 0:5:20])
The initial condition corresponds to the exact soliton solution. When the time interval is sufficiently small, the solution looks not bad.
But when I increase time interval, strange things begin:
That is, the exact soliton solution is destroyed when passes through periodic boundary. Moreover, when I use Dirichlet boundary condition (bc = Dirichlet0BC(Float64)), Julia is just hanging and gives no result at all…
Could someone tell me what I’m doing wrong?