Inconsistent typing making adding arrays and adding a vector to the end of an array difficult

Interestingly, Wikipedia (Lorenz system - Wikipedia) provides Julia code for this same Lorenz problem that uses DifferentialEquations.jl.
Fyi, this problem then seems to run 12x faster than the faster implementation above, with a @btime of 1.2 ms. If we are comparing apples to apples then there is a lot of room for improvement.
See the code here for your reference:

using DifferentialEquations, ParameterizedFunctions, Plots
using BenchmarkTools

lorenz = @ode_def begin                  # define the system
 dx = σ * (y - x)
 dy = x * (ρ - z) - y
 dz = x * y - β*z
end σ ρ β

u0 = [1.0,1.0,1.0]                       # initial conditions
tspan = (0.0,60.0)                       # timespan
p = [10.0,28.0,8/3]                      # parameters

prob = ODEProblem(lorenz, u0, tspan, p)  # define the problem
sol0 = solve(prob, reltol=1e-9)          # solve it
# @btime solve(prob, reltol=1e-9)
plot(sol0, vars = (1, 2, 3))
5 Likes