New to julia, I have a question about how to expand the equations when solve the ODEs, here is a simple example
if the initial program is
function Eq(dy, y, p, t)
para01, para02 = p
dy[1] = dot(para01 * y[2], para02 * y[1]) - y[2]
dy[2] = dot(para01 * y[1], exp.(para02 * y[2])) - y[3]
dy[3] = -dot(para01 * y[3], para02 * y[1]) - y[1]
end
using DifferentialEquations, LinearAlgebra, Plots
para01 = [1.0, 2.0]
para02 = [3.0, 4.0]
tstart = 0
tend = 1e-2
tspan = (tstart, tend)
u0 = [0.0, 0.0, 1.0]
p = (para01, para02)
prob = ODEProblem(Eq, u0, tspan, p)
sol = solve(prob, Tsit5())
plot(sol.t, sol[1, :])
Then I expand it to
function Eq(dy, y, p, t)
para01, para02 = p
for ii = 1:length(para01)
dy[1] += para01[ii] * y[2] * para02[ii] * y[1]
dy[2] += para01[ii] * y[1] * exp(para02[ii] * y[2])
dy[3] += -para01[ii] * y[3] * para02[ii] * y[1]
end
dy[1] -= y[2]
dy[2] -= y[3]
dy[3] -= y[1]
end
using DifferentialEquations, LinearAlgebra, Plots
para01 = [1.0, 2.0]
para02 = [3.0, 4.0]
tstart = 0
tend = 1e-2
tspan = (tstart, tend)
u0 = [0.0, 0.0, 1.0]
p = (para01, para02)
prob = ODEProblem(Eq, u0, tspan, p)
sol = solve(prob, Tsit5())
plot!(sol.t, sol[1, :])
From my understanding, they should be the same, but the final result is different, and here is just a very simple case, for my real program, if I do this expansion, it can decrease the calculation time by a factor of 3, the problem is the result is different with and without expansion, any suggestions are welcome