# Large interpolation error for exponential integrators in DifferentialEquations

**URL:** <https://discourse.julialang.org/t/large-interpolation-error-for-exponential-integrators-in-differentialequations/117047>\
**Category:** Numerics\
**Tags:** question, package, sciml\
**Created:** [July 15, 2024, 8:35am UTC](https://discourse.julialang.org/t/large-interpolation-error-for-exponential-integrators-in-differentialequations/117047 "2024-07-15T08:35:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RayleighLord](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayleighlord/32/33592_2.png) [@RayleighLord](https://discourse.julialang.org/u/RayleighLord)\
**Post date:** [July 15, 2024, 8:35am UTC](https://discourse.julialang.org/t/large-interpolation-error-for-exponential-integrators-in-differentialequations/117047/1 "2024-07-15T08:35:41Z")

</div>

I was recently working with `SplitODEProblem` using exponential integrators and I noticed a huge error when doing the interpolation of the solution, which I think is wrong.

I began to notice this since, by default, the solution gives the values at each time step and always ends at `tspan[2]`, regardless if this value is smaller than the last step for a given `dt`. This last interpolated step seemed to be way off from the solution, so I started experimenting with it and I have the following MWE.

```julia
using DifferentialEquations, GLMakie

K = [1.0 -1.0 0.0;
    -1.0 2.0 -1.0;
    0.0 -1.0 2.0]
M = [1.0 0.0 0.0;
    0.0 1.0 0.0;
    0.0 0.0 1.0]

F = [0.1, 0.0, 0.0]
F₀ = [20.0, 20.0, 0.0]

M⁻¹F, M⁻¹F₀, M⁻¹K = M \ F, M \ F₀, M \ K

ξ = 0.01

function f2!(du, u, p, t)
    N = length(u) ÷ 2
    M⁻¹F, M⁻¹F₀, Ω = p

    du[(N+1):end] .= M⁻¹F * sin(Ω * t) .+ M⁻¹F₀
end

A = MatrixOperator([zeros(size(M)) I; -M⁻¹K -M⁻¹K*ξ])

Ω = 0.445
p = (M⁻¹F=M⁻¹F, M⁻¹F₀=M⁻¹F₀, Ω=Ω)

tspan = (0.0, 2π / Ω * 10)
u0 = zeros(6)
prob = SplitODEProblem(A, f2!, u0, tspan, p)
sol = solve(prob, LawsonEuler(), dt=1e-1, progress=true)

t = (2π/Ω*9):(2π/Ω/100):(2π/Ω*10)
lines(t, sol(t)[1, :])

```

This example creates an oscillating dynamical system and I solve it with an exponential integrator. However, if I do the interpolation as in the last lines, I get the following plot

![image](https://global.discourse-cdn.com/julialang/original/3X/b/0/b08a58962467ca58b8dca1a89d52c531f60dbe55.png)

whereas examining the complete solution from the integrator gives

![image](https://global.discourse-cdn.com/julialang/original/3X/3/6/365cb9f38b8ed2d41e173aa2e496178c1eacd197.png)

which seems to be smooth and well resolved. Therefore, is this a bug of the interpolation functions for these kinds of scheme? Also, is it intended that the last time step from the time vector is always `tspan[2]` even though there could be a time instant that goes after this point?

---

<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:** [July 16, 2024, 4:12am UTC](https://discourse.julialang.org/t/large-interpolation-error-for-exponential-integrators-in-differentialequations/117047/2 "2024-07-16T04:12:11Z")

</div>

Can you open an issue?

---

<div class="post-metadata">

**Author:** ![RayleighLord](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayleighlord/32/33592_2.png) [@RayleighLord](https://discourse.julialang.org/u/RayleighLord)\
**Post date:** [July 16, 2024, 7:11am UTC](https://discourse.julialang.org/t/large-interpolation-error-for-exponential-integrators-in-differentialequations/117047/3 "2024-07-16T07:11:10Z")

</div>

Done, you can find it [here](https://github.com/SciML/DifferentialEquations.jl/issues/1041).
