Why do I get different behavior in my Julia vs Matlab implementation?

I’ve written two scripts: one in Julia and one in Matlab. Both are supposed to do the same thing: solve a system of ODEs

One way to do a “sanity” check, in this case, for the numerical solutions is to check if the L2 norm of my solution are conserved. In Julia this corresponds to writing something like norm(sol[i], 2) and never seeing a change in value. Plotting this, one would see a flat line for all time. In Matlab it is just about the same syntax.

What is different are the ODE solvers. In Julia, ODEProblem defaults to Tsit5() whereas in Matlab we default to use ode45.

Question: Why is the L2-norm conserved in my Julia implementation, but not the Matlab implementation?

Attempt: I have done my best at copying my Julia code into Matlab so I think I am solving the same ODE system as in my Julia implementation. In both implementations I have examined the values of the solution at each time step and see there are very small differences. In Matlab, I see the norm is decreasing and oscilating (?!). I have no explaination for this.

Guess: My only idea, after auditing the codes, is that Tsit5 does a “better job” at a numerical approximation of the code. But I do not know how to verify this as I do not have an exact solution to compare to.

Julia code: fDNLS_Direct.jl (5.8 KB)

Matlab code: There are three files: 1) https://paste.ofcode.org/vAySi4DUAzahPdmBFJ3TNY,
2) https://paste.ofcode.org/KAhexkWif2LcnxBvNnXCAP,
3) https://paste.ofcode.org/TnLgPjbbRvULh2cMUWL2pr

DP5 is the Dormand-Prince method ode45 uses. How does that differ?

Well, I have no good experiance with the solvers of Matlab/Simulink. Bad accuracy, slow (and with slow I mean 100 times slower than the best Julia solvers for the same accuracy), sometimes you get strange results and it is hard to figure out why… If you want to get good results use Julia and DifferentialEquations, if you have issues with the (about 100) solvers that are available ask here and you will get competent answers…

If you have issues with Matlab solvers ask the Matlab support…