Can we solve complex valued two point boundary value problems?

Hi,

I am new to using Julia for differential equations. I am having a problem trying to solve a complex valued two point boundary value problem using the MIRK4 solver. I have tried to define complex valued initial conditions, and this throws an inexact error.

Does this algorithm work with complex functions? Are there alternatives?

Let me know if I should provide more information, and I can give details or post code.

Thanks! Michael

It should work, do you have a minimum working example?

L = 1.0
tspan = (0.0,pi/2)
function simplependulum!(du,u,p,t)
    θ  = u[1]
    dθ = u[2]
    du[1] = dθ
    du[2] = -(g/L)*sin(θ)
end

function bc2!(residual, u, p, t)
    residual[1] = u[1][1] + pi/2 
    residual[2] = u[end][1] - pi/2 
bvp2 = TwoPointBVProblem(simplependulum!, bc2!, [pi/2+1*im,pi/2+1*im], tspan)
sol2 = solve(bvp2, MIRK4(), dt=0.05)```

This is the example given in the docs, where I have replaced the initial guess with an imaginary value. This is a nonsensical input for this example, but it shows the error. similarly, making one of the equations complex valued throws an inexact error.

Definitively a bug in the BVPSystem constructor from BoundaryValueDiffEq.jl

It assumes same type for x and y
https://github.com/SciML/BoundaryValueDiffEq.jl/blob/fcb3f40e7cddf8aa1a22528f434ebe336c3ff554/src/collocation.jl

Actually easy to fix:
Proposed fix

Thanks for the quick fix!

I will leave this open for the moment until all the changes are implemented.

It seems like a still get an error when using the fix_y_type branch. It is now “InexactError: Int64(NaN)”. Could you post a working example?

Try:

using Pkg
Pkg.add(url="https://github.com/MatFi/BoundaryValueDiffEq.jl", rev="fix_y_type")
using BoundaryValueDiffEq
using DiffEqBase, OrdinaryDiffEq
L = 1.0
g = 9.81
tspan = (0.0,pi/2)
function simplependulum!(du,u,p,t)
    θ  = u[1]
    dθ = u[2]
    du[1] = dθ
    du[2] = -(g/L)*sin(θ)
end

function bc2!(residual, u, p, t)
    residual[1] = u[1][1] + pi/2 
    residual[2] = u[end][1] - pi/2 
end
bvp2 = TwoPointBVProblem(simplependulum!, bc2!, [pi/2+1*im,pi/2+1*im], tspan)
sol2 = solve(bvp2, MIRK4(), dt=0.05)

The branch was broken for a few minutes, but now it is working again…

Thanks! This example works. I’m still getting the error in my code, but I’ll try to see if it’s something on my end, as I can’t reproduce it.

Solved. I got the error with u0 as a complex Int instead of complex float.