# Modifying time in sol after solve() function using DifferentialEquations.jl

**URL:** https://discourse.julialang.org/t/modifying-time-in-sol-after-solve-function-using-differentialequations-jl/124647
**Category:** Modelling & Simulations
**Tags:** diffeq, ode, sciml, modelingtoolkit, differentialequation
**Created:** [January 10, 2025, 3:59pm UTC](https://discourse.julialang.org/t/modifying-time-in-sol-after-solve-function-using-differentialequations-jl/124647 "2025-01-10T15:59:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Iddingsite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iddingsite/32/31840_2.png) [@Iddingsite](https://discourse.julialang.org/u/Iddingsite)
#### Post date: [January 10, 2025, 3:59pm UTC](https://discourse.julialang.org/t/modifying-time-in-sol-after-solve-function-using-differentialequations-jl/124647/1 "2025-01-10T15:59:17Z")

</div>

Hi,

I was wondering, using DifferentialEquations.jl (and co), if there is an easy way to modify the `t` in `sol` object after it is output and to synchronise it with the interpolation?

I have tried to simply modify it with `sol.t .=* 2` for instance, but it doesn’t seem to impact `sol(x)` when I try to obtain the values by interpolation.

If it is not clear, here is a MWE:

```julia
using OrdinaryDiffEq

function lorenz(u, p, t)
    dx = 10.0 * (u[2] - u[1])
    dy = u[1] * (28.0 - u[3]) - u[2]
    dz = u[1] * u[2] - (8 / 3) * u[3]
    [dx, dy, dz]
end

u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 100.0)
prob = ODEProblem(lorenz, u0, tspan)
sol = solve(prob, Tsit5());

sol2 = copy(sol)

sol2.t .*= 2 

sol2(200) == sol(100)

```

Which returns false. I would like it to be true for my purpose.

I know it would be probably a bit of a hack, but my goal is to rescale back the values of sol.t to a different unit for instance. I know that I could just access that value by converting, but for my purpose, I would like to hide from the user the scaling part and just provide a solution object with the units he defines as input in another function.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [January 10, 2025, 4:58pm UTC](https://discourse.julialang.org/t/modifying-time-in-sol-after-solve-function-using-differentialequations-jl/124647/2 "2025-01-10T16:58:09Z")

</div>

Note you’re hitting internals here so use at your own risk. You would need to modify the internal interpolation time, which is `sol2.interp.ts .*= 2`. This is an internal detail so there is no guarantee this will continue to work, but I also don’t have reason to change it any time soon.

---

<div class="post-metadata">

### Author: ![Iddingsite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iddingsite/32/31840_2.png) [@Iddingsite](https://discourse.julialang.org/u/Iddingsite)
#### Post date: [January 10, 2025, 5:06pm UTC](https://discourse.julialang.org/t/modifying-time-in-sol-after-solve-function-using-differentialequations-jl/124647/3 "2025-01-10T17:06:54Z")

</div>

Thanks! Exactly what I was looking for…

---

<div class="post-metadata">

### Author: ![Iddingsite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iddingsite/32/31840_2.png) [@Iddingsite](https://discourse.julialang.org/u/Iddingsite)
#### Post date: [January 10, 2025, 7:24pm UTC](https://discourse.julialang.org/t/modifying-time-in-sol-after-solve-function-using-differentialequations-jl/124647/4 "2025-01-10T19:24:58Z")

</div>

Well, interestingly, it actually doesn’t work properly. And I don’t really understand why:

```julia
using OrdinaryDiffEq

function lorenz(u, p, t)
    dx = 10.0 * (u[2] - u[1])
    dy = u[1] * (28.0 - u[3]) - u[2]
    dz = u[1] * u[2] - (8 / 3) * u[3]
    [dx, dy, dz]
end

u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 100.0)
prob = ODEProblem(lorenz, u0, tspan)
sol = solve(prob, Tsit5());

sol2 = deepcopy(sol)

sol2.interp.ts .*= 2

@show sol2.t[end] == sol.t[end] * 2
# True
@show sol2(sol2.t[end]) == sol(sol.t[end])
# False
@show sol2(sol2.t[end])
# 3-element Vector{Float64}:
# -4.361553927469487
# -1.2879782191167406
# 26.917854626761358
@show sol(sol.t[end])
# 3-element Vector{Float64}:
# -5.248620965966837
# -1.4596434517264187
# 28.39189720840952

```

So now, sol.t got updated correctly, as does sol.interp.ts, but the interpolation is wrong. I don’t know if it is a rounding error or whatever with the timestep, but the last point is a modelled one, so it should be the same in both case.  
I guess I shouldn’t play with that!

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [January 10, 2025, 10:24pm UTC](https://discourse.julialang.org/t/modifying-time-in-sol-after-solve-function-using-differentialequations-jl/124647/5 "2025-01-10T22:24:49Z")

</div>

You might need to modify the coefficients if the time is scaled instead of translated
