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)