Solving ODEs with Initial Values u(t0) = u0 for t0 ≠ 0


I’ve gotten into Julia to solve a number of ODEs (mostly for boundary value problems) and I’ve started to practice solving them in Julia. I’ve checked a lot of threads and the documentation for Differentialequations.jl but have now been able to find an answer to this problem. In all of the reading I have done, the initial values that we use when defining a problem are always some u(t0) = u0 for a t0 = 0. However, I am encountering a number of ODEs I must solve whose initial conditions are given by some u(t0) = u0 where t0 ≠ 0.

For instance, solving du/dt + u*tan(t) = exp(2*t)*cos(t), u(0) = 2 looks like

using DifferentialEquations
f(u,p,t) = exp(2*t)*cos(t) - u*tan(t)
u0 = 2.
tspan = (0.,4.)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob)

However, I am clueless on how to set up t*du/dt = u + t, u(2) = 8

Thank you so much!

Just use a tspan that starts at t0.


That’ll do it, thank you.