Decoupling tspan and initial time, t0, in Julia

Viewed 192

I'm faced with a problem, which is the following: I want to represent a solution, in which (t0,η) is given. Let's say, (t0,η) = (0,1). But, I would like to see the graph represented in the whole (-1,1) domain.

As tspan is intrinsically related with my t0, how can I make the solver resolve my problem for the given t0, differing the initial value in the interval in tspan?

So, in the given example, I would like to observe the ODE in (-0.88, 0.88), but to solve the problem with condition (t0, y0) = (0,1).

Ex8(c)
using DifferentialEquations
using Plots

function example2!(dy, y, t, p)
    c1  = p
    dy[1] = c1 * y[1]^3
end

y0 = [1]
p = [1]
tspan = (0, 0.88)
prob2 = ODEProblem(example2!, y0, tspan, p)
sol2 = solve(prob2)

plot(sol2)

EDIT:

A discussion I had with the creator of the package, on the issue, on github,

issue#705

The solver has no way of intelligently discriminate, locate, and work around divergences in a graph. So, this analysis must be done without the aid of computers as of now.

2 Answers

This is not a programming question, but rather a mathematical one. It seems you are asking how to solve a boundary value problem. An ODE where instead of a initial condition, you have some other condition. The solution to this is the use the shooting method and turn your BVE to a ODE.

As an example from the linked page, you are searching for the initial condition at y'(0)=a such that the solution passes through a known condition y'(5)=30.

fig1

You need to call the solver twice, once for the time span from 0 to 1 and once for the time span from 0 to -1. Any competent solver will correctly translate the negative direction of the time interval into correspondingly negative step sizes.

Then combine the two partial solutions either using array operations or by drawing them with the same parameters in one plot.

Related