I am trying to save multiple solutions of my ODE in an Array. Right now this is what I got:
sols = []
for i in 1:numSim
if solver == "Rosenbrock23"
solution = solve(odeprob, Rosenbrock23())
append!(sols, solution)
end
end
As you can see I only want to append to this Array, if a certain ode solver is used. However, the "append!" statement neglects this statement and runs every iteration of the loop. I tried preallocating the array sol, to use a statement like this:sols[i] = solution
But here im struggling with the type declaration of the array sol.
I tried
sols = zeros(length)
and then
sols[i] = solution
However solution is of type ODESolution and can not be converted to Float64
Please provide adequate information to get an exact answer. I can't reproduce your problem since you didn't mention what is
odeprob
or the value ofnumSim
. Since you declaredsols = []
then theeltype
ofsols
should beAny
; hence it should be capable to contain any element.However, I can replicate the code in the official doc (Example 1 : Solving Scalar Equations (ODE)), and combine it with your approach:
Then if I call the
sols
variable: