# Troubles with solving Korteweg-de Vries equation

**URL:** <https://discourse.julialang.org/t/troubles-with-solving-korteweg-de-vries-equation/59406>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [April 16, 2021, 12:22pm UTC](https://discourse.julialang.org/t/troubles-with-solving-korteweg-de-vries-equation/59406 "2021-04-16T12:22:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stepan\_Shcherbinin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stepan_shcherbinin/32/23970_2.png) [@Stepan\_Shcherbinin](https://discourse.julialang.org/u/Stepan_Shcherbinin)\
**Post date:** [April 16, 2021, 12:22pm UTC](https://discourse.julialang.org/t/troubles-with-solving-korteweg-de-vries-equation/59406/1 "2021-04-16T12:22:23Z")

</div>

Hi everybody,

I am a new Julia user. I try to solve KdV equation with the aid of **DifferentialEquations.jl**. Here is my code:

```julia
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:  
 ![KdV_2](https://global.discourse-cdn.com/julialang/original/3X/d/8/d8e1ec0862e2c1deed0cae1300e685ed639f4e22.png)  
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?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 22, 2021, 7:40am UTC](https://discourse.julialang.org/t/troubles-with-solving-korteweg-de-vries-equation/59406/2 "2021-04-22T07:40:14Z")

</div>

Open an issue on DiffEqOperators.jl for this.
