Hi there, I am solving a system of differential equations using Differential equations.jl, and have the following result:
I would like to only plot the solution when it has stabilised (from 5 seconds onwards). I have been using plot(sol, xlims=(5.0,10.0)), which yields
but I am wondering if there is a way to re-index so that what used to be t=5 is now t=0 so that the x axis starts at zero instead of 5.
It’s not quite clear what he wants. I supposed that he intend to illustrate that the solution stabilizes starting from a time t’>0, and wanted to plot that solution above the integration time of the general solution, i.e. xlims=(sol.t[1], sol.t[end]). But I’m not sure…
The question seems to be resolved, but just in case someone is in a similar situation and is looking for alternatives:
To deal with a transient time in some simulation, I usually use something like this:
# Define system of equation
function f(du, u, p, t)
du[1] = -u[1]
end
# Parameter for system (in this case there are none)
p = []
# Initial conditions
u0 = [1]
# Time points to integrate
times = 0:0.01:8
# Transient time
transient = 1
# Define ODE problem
prob = ODEProblem(
f, # system to integrate
u0, # initial conditions
(times[1], times[end] + transient), # time bounds to integrate in
p # parameters for the system
)
# Solve problem
sol = solve(
prob, # problem to solve for
saveat = times .+ transient # times to get an answer for, but shifted by the transient time
)
# Plot trajectories
plot(sol)
Someone, please feel free to correct me if this is an unnatural or inefficient way of doing things!