Single initial value problem for ODE: numerical integration forward and backward

Hi there,

I have an ordinary differential equation, such as (mine is much more complicated, besides being a 2-d system):

function dxdt!(du, u, p, t)
    x = u[1]
    du[1] = dx = 2*x^2

whose general analytical solution is, of course; x = 1/(c-2t), c = constant.
The initial condition (corresponding to c=1), for instance,

u0 = [1.0]

is given at time t = 0.0, but I would like to find the corresponding numerical solution for a whole interval containing the initial time, i.e, both forward and backward, such as, e.g., in the interval (-5.0, 0.45). I am able to set two ODEProblem’s, with the same single initial value, with distinct timespans: (0.0, 0.498) and (0.0, -5.0), such as:

tspan1 = (0.0,0.498)
prob1 = ODEProblem(dxdt!, u0, tspan1)
sol1 = solve(prob1)
tspan2 = (0.0,0.498)
prob2 = ODEProblem(dxdt!, u0, tspan2)
sol2 = solve(prob1)

but then it is a bit awkward to deal with the union of these solutions in a convenient way. Is there a way to find the numerical solution, in a single shot, which comes from the past, passes through the initial condition point, and goes to the future?

Thanks in advance.

@Vaibhavdixit02 had code for stitching two solutions together you might want to start from.

Thanks Chris, I will try to look at it. At any rate, I think this might be a nice improvement to the package: generating a solution, from a given initial value problem, in both time directions, with all the current features (interpolation, plots, …) of the single direction problem; certainly, then, the user would have to provide the concrete time span or interval (a, b) for the integration (within which the initial time t0 should be included: a < t0 < b).

DiffEqParamEstim.jl/multiple_shooting_objective.jl at d812632db012913f7f026002db6680f7b314f05e · SciML/DiffEqParamEstim.jl · GitHub this is the code that Chris mentioned, hope it helps!

1 Like

Thanks @Vaibhavdixit02

1 Like