# How to insert Integral in a NonLinearProblem

**URL:** <https://discourse.julialang.org/t/how-to-insert-integral-in-a-nonlinearproblem/101183>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 4, 2023, 6:53pm UTC](https://discourse.julialang.org/t/how-to-insert-integral-in-a-nonlinearproblem/101183 "2023-07-04T18:53:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xx-Seth-xX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xx-seth-xx/32/51244_2.png) [@Xx-Seth-xX](https://discourse.julialang.org/u/Xx-Seth-xX)\
**Post date:** [July 4, 2023, 6:53pm UTC](https://discourse.julialang.org/t/how-to-insert-integral-in-a-nonlinearproblem/101183/1 "2023-07-04T18:53:46Z")

</div>

If I want to have an integral inside a Non Linear System of equations how would I do it with ModelingToolkit.jl and NonLinearSolver.jl?

e.x. I have an integral from 0 to 1 of sin(a\*x) which equals to 1, how would I solve for a using NonLinearSolve?

My problem is actually more complex (a lot).

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 5, 2023, 1:47pm UTC](https://discourse.julialang.org/t/how-to-insert-integral-in-a-nonlinearproblem/101183/2 "2023-07-05T13:47:10Z")

</div>

You can’t do this with ModelingToolkit’s interface right now, you’ll need to directly write the code for NonlinearSolve.jl until this is supported in the symbolic language.

---

<div class="post-metadata">

**Author:** ![Xx-Seth-xX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xx-seth-xx/32/51244_2.png) [@Xx-Seth-xX](https://discourse.julialang.org/u/Xx-Seth-xX)\
**Post date:** [July 5, 2023, 1:53pm UTC](https://discourse.julialang.org/t/how-to-insert-integral-in-a-nonlinearproblem/101183/3 "2023-07-05T13:53:29Z")

</div>

Thanks!, is it on the roadmap?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 5, 2023, 2:26pm UTC](https://discourse.julialang.org/t/how-to-insert-integral-in-a-nonlinearproblem/101183/4 "2023-07-05T14:26:29Z")

</div>

> [@Xx-Seth-xX](#):
>
> e.x. I have an integral from 0 to 1 of sin(a\*x) which equals to 1, how would I solve for a using NonLinearSolve?

Note that you can just implement this as a numeric integral using any quadrature package, and then pass the resulting function to any root-finding package. For example:

```julia
using QuadGK, Roots, ForwardDiff
D(f) = x -> ForwardDiff.derivative(f,float(x))
f(a) = quadgk(x -> sin(a*x), 0, 1, atol=1e-11)[1]
find_zero((f, D(f)), 3, Roots.Newton(), xatol=1e-8)

```

returns \approx 2\pi. (Be sure to specify an _absolute_ tolerance for any quadrature routine, since you will be looking at parameters where the integral is nearly zero.)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 5, 2023, 2:52pm UTC](https://discourse.julialang.org/t/how-to-insert-integral-in-a-nonlinearproblem/101183/5 "2023-07-05T14:52:40Z")

</div>

> [@Xx-Seth-xX](#):
>
> Thanks!, is it on the roadmap?

It is on the roadmap. So do what Steven says for now, and there’s a lot of other random stuff ModelingToolkit is growing into so I won’t guarantee it’s happening soon but the connections between system types is one of the big focuses.
