I have an ODE that I am trying to solve as follows:
L = 39
c = 0.0
Δx = 0.2
Δt = 0.1
Tspan = 100
t_vec = 0:Δt:Tspan
x_vec = 0:Δx:L
N = length(x_vec)
p = c
u0 = 0.2 * sin.((2π / L) * x_vec)
prob = ODEProblem(DerSen, u0, tspan, p)
sol = solve(prob, RK4(), saveat = Δt)
Where:
function DerSen(du,u,p,t)
for i=1:Nx
if i==2
du[i]=-(u[i+1]^2-0)/(4*Δx)-p*(u[i+1]-0)/(2*Δx)-(u[i+1]-2*u[i]+0)/(Δx^2)-(u[i]-0+6*u[i]-4*u[i+1]+u[i+2])/(Δx^4)
end
if i==3
du[i]=-(u[i+1]^2-u[i-1]^2)/(4*Δx)-p*(u[i+1]-u[i-1])/(2*Δx)-(u[i+1]-2*u[i]+u[i-1])/(Δx^2) -(0-4*u[i-1]+6*u[i]-4*u[i+1]+u[i+2])/(Δx^4)
end
if i>=4 && i<=Nx-3
du[i]=-(u[i+1]^2-u[i-1]^2)/(4*Δx)-p*(u[i+1]-u[i-1])/(2*Δx)-(u[i+1]-2*u[i]+u[i-1])/(Δx^2) -(u[i-2]-4*u[i-1]+6*u[i]-4*u[i+1]+u[i+2])/(Δx^4)
end
if i==Nx-2
du[i]=-(u[i+1]^2-u[i-1]^2)/(4*Δx)-p*(u[i+1]-u[i-1])/(2*Δx)-(u[i+1]-2*u[i]+u[i-1])/(Δx^2) -(u[i-2]-4*u[i-1]+6*u[i]-4*u[i+1]+0)/(Δx^4)
end
if i==Nx-1
du[i]=-(0-u[i-1]^2)/(4*Δx)-p*(0-u[i-1])/(2*Δx)-(0-2*u[i]+u[i-1])/(Δx^2)-(u[i-2]-4*u[i-1]+6*u[i]-0+u[i])/(Δx^4)
end
end
return du
end
when Δx
becomes lower than 0.5
, the ODE solver takes an infinite time to solve the same problem. Any suggestions?