# Area under the solution curve

I am trying to calculate the integral of the solution of a differential equation and find the area under the curve.
So far I numerically integrate the solution with a certain dt (see following MWE), but I was wondering how this can be done more precisely and efficiently. I understand that the solution comes with an interpolation by default. Can this interpolation be used directly to find the integral?

``````using DifferentialEquations
f(u,p,t) = 1.01*u
u0 = 1/2
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)

using Plots
plot(sol)

dt = 0.1
ts = 0.0:dt:1.0
ys = sol(ts)
AUC = sum(ys)*dt
``````

I think you can use `QuadGK` as follows:

``````using QuadGK
julia> AUC, err = quadgk(sol, 0, 1.0)
(0.8641589183483787, 4.908429218630772e-11)
``````
2 Likes