# Area under the solution curve

**URL:** <https://discourse.julialang.org/t/area-under-the-solution-curve/54442>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [February 2, 2021, 8:36am UTC](https://discourse.julialang.org/t/area-under-the-solution-curve/54442 "2021-02-02T08:36:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaglino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaglino/32/16669_2.png) [@vaglino](https://discourse.julialang.org/u/vaglino)\
**Post date:** [February 2, 2021, 8:36am UTC](https://discourse.julialang.org/t/area-under-the-solution-curve/54442/1 "2021-02-02T08:36:41Z")

</div>

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?

```julia
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

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 2, 2021, 9:27am UTC](https://discourse.julialang.org/t/area-under-the-solution-curve/54442/2 "2021-02-02T09:27:02Z")

</div>

I think you can use `QuadGK` as follows:

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

```
