# Solve for upper/lower bound of a numerical definite integral

**URL:** <https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164>\
**Category:** General Usage\
**Tags:** question, math\
**Created:** [March 29, 2021, 2:14pm UTC](https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164 "2021-03-29T14:14:21Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 1, 2021, 9:55pm UTC](https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164/22 "2021-04-01T21:55:15Z")

</div>

If you’re worried about accumulated errors, the best approach is probably to compute first to low precision (.1 or so), and then restart with that as a guess. This will take much less than 2x the time (since the second newton pass will converge very quickly since you start close to the right answer), but should prevent excessive back and forths causing cancellation issues.

---

<div class="post-metadata">

**Author:** ![carloslesmes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carloslesmes/32/18882_2.png) [@carloslesmes](https://discourse.julialang.org/u/carloslesmes)\
**Post date:** [April 2, 2021, 10:16pm UTC](https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164/23 "2021-04-02T22:16:58Z")

</div>

Roots.jl do the job. Thanks

---

<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:** [April 2, 2021, 10:55pm UTC](https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164/24 "2021-04-02T22:55:21Z")

</div>

@carloslesmes, could you post the solution that you have found using Roots,jl?

---

<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:** [April 2, 2021, 11:41pm UTC](https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164/25 "2021-04-02T23:41:56Z")

</div>

Another way is to write the problem like this:

\\ \int\_a^x f(x')dx'=K(x)\\ \\ \frac{d}{dx}K(x) = f(x),\quad K(a)=0 

Use Differential Equations to solve for K(x) and then use interpolation to find the solution:  
 ![DiffEqs_to_solve_definite_integral](https://global.discourse-cdn.com/julialang/original/3X/e/8/e8a03d8a78c1b935059961a35acd788fe18af957.png)

_NB: I have updated the code above under solution#4_

---

<div class="post-metadata">

**Author:** ![carloslesmes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carloslesmes/32/18882_2.png) [@carloslesmes](https://discourse.julialang.org/u/carloslesmes)\
**Post date:** [April 5, 2021, 6:23pm UTC](https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164/26 "2021-04-05T18:23:52Z")

</div>

Hi  
Suppose you’re to solve for x:

```nohighlight
\int_{0}^{x} 5(1-t)^{4} dt=0.9

```

```julia
using Roots, QuadGK
f1(x)=5(1-x)^4
f2(x)=quadgk(f,0,x)[1]-0.9
find_zero(g,0.5)

```

[Previous page](https://discourse.julialang.org/t/solve-for-upper-lower-bound-of-a-numerical-definite-integral/58164.md?page=1)
