Error using Peaks function to get maximum of ODE solution

I am trying to get the maximum of a plot from ODE solve using Peaks function. I need help cause i get error. Here is my code. Thanks.

using DifferentialEquations
using Plots ; gr()

function f(du,u,p,t)
du[1] = dx = -p[1]*u[1]*u[2]
du[2] = dy = p[1]*u[1]*u[2] - p[2]*u[2]
du[3] = dz = p[2]*u[2]
end

u0 = [738.0;1.0;0]
tspan = (0.0,14.0)
p = [0.00237,0.465]
prob = ODEProblem(f,u0,tspan,p)
sol = solve(prob,abstol=1e-8,reltol=1e-8,Tsit5(),save_idxs=2)
plot(sol,linewidth=2)

using peaks command to get the maximum of the plotted graph (using maximum command does not work in some cases)

using Peaks
sol2 = solve(prob,abstol=1e-8,reltol=1e-8,Tsit5())
g = (t) → sol2(t,idxs=2)
pks1,vals1 = findmaxima(g)

Can you provide an example of code where calling maximum(sol.u) does not work after running your ODE solver? I don’t see a reason why that would fail.

The Peaks code you provided seems to find the maximum of a vector, not a function. If you wanted to find a maximum of a function (as a general tip), I would suggest taking a look at SciML’s Optimization.jl package.

In the future, it is also helpful if you provide the stacktrace (i.e., the error message). That helps us figure out what part of your code is raising the error and gets to the solution a little faster.

Thank you.