# Way to write the integral with ModelingToolkit

**URL:** <https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347>\
**Category:** Machine Learning\
**Tags:** diffeq, pde\
**Created:** [June 6, 2022, 9:42pm UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347 "2022-06-06T21:42:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaido975](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaido975/32/36862_2.png) [@kaido975](https://discourse.julialang.org/u/kaido975)\
**Post date:** [June 6, 2022, 9:42pm UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/1 "2022-06-06T21:42:36Z")

</div>

Is there a way to write the following integral with ModelingToolkit.jl, is binomial expansion the only option here?

\int\_{0}^{t} (t - x)^{\lambda} u(x) d x \quad \text{, } \lambda \< 0 \quad \text{, for } t\> 0

I want to include this integral in a PINN.

---

<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:** [June 7, 2022, 11:06am UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/2 "2022-06-07T11:06:36Z")

</div>

This tutorial should be helpful:

[https://neuralpde.sciml.ai/dev/pinn/integro\_diff/](https://neuralpde.sciml.ai/dev/pinn/integro_diff/)

---

<div class="post-metadata">

**Author:** ![kaido975](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaido975/32/36862_2.png) [@kaido975](https://discourse.julialang.org/u/kaido975)\
**Post date:** [June 7, 2022, 12:46pm UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/3 "2022-06-07T12:46:59Z")

</div>

Hi @ChrisRackauckas, I have read that tutorial, but I am not sure how to write the code for the power term inside the integral with ModelingToolkit.

---

<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:** [June 7, 2022, 2:08pm UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/4 "2022-06-07T14:08:02Z")

</div>

```julia
Ix = Integral(x in DomainSets.ClosedInterval(0, t))
Ix((t-x)^lambda * u(x))

```

---

<div class="post-metadata">

**Author:** ![kaido975](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaido975/32/36862_2.png) [@kaido975](https://discourse.julialang.org/u/kaido975)\
**Post date:** [June 7, 2022, 5:44pm UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/5 "2022-06-07T17:44:11Z")

</div>

Hi @ChrisRackauckas I tried what you suggested but I am unable to discretize the equation, below is the code and the error. I am not sure where to pass the parameter x.

```julia
using NeuralPDE, Flux, ModelingToolkit, DiffEqFlux, DomainSets
import ModelingToolkit: Interval

@parameters t, x
@variables u(..)
lambda = -1.5
Di = Differential(t)
Ii = Integral(x in DomainSets.ClosedInterval(0, t))
eq = Di(u(t)) + Ii((t-x)^lambda*u(x)) ~ 1.0
bcs = [u(0.0) ~ 0.0]
domains = [t ∈ Interval(0.0,2.0)]
chain = Chain(Dense(1,15,Flux.σ),Dense(15,1))
initθ = Float64.(DiffEqFlux.initial_params(chain))

strategy_ = GridTraining(0.05)
discretization = PhysicsInformedNN(chain,
                                   strategy_;
                                   init_params = nothing,
                                   phi = nothing,
                                   derivative = nothing)
@named pde_system = PDESystem(eq,bcs,domains,[t],[u(t)])
prob = NeuralPDE.discretize(pde_system,discretization)

```

```julia
ERROR: KeyError: key :x not found

```

---

<div class="post-metadata">

**Author:** ![Ashutosh\_Bharambe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashutosh_bharambe/32/37003_2.png) [@Ashutosh\_Bharambe](https://discourse.julialang.org/u/Ashutosh_Bharambe)\
**Post date:** [June 8, 2022, 5:22am UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/7 "2022-06-08T05:22:42Z")

</div>

Hi @kaido975 The integral `Ii` should be defined in this way,

```julia
Ii = Integral(t in DomainSets.ClosedInterval(0, t))

```

---

<div class="post-metadata">

**Author:** ![kaido975](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaido975/32/36862_2.png) [@kaido975](https://discourse.julialang.org/u/kaido975)\
**Post date:** [June 8, 2022, 4:48pm UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/8 "2022-06-08T16:48:32Z")

</div>

Hi @Ashutosh_Bharambe, I want the equation to be of the form,

```julia
Integral(x, 0..t)(((t - x)^lambda)*u(x)) + Differential(t)(u(t)) ~ 0.0

```

What you suggested would give me,

```julia
Integral(t, 0..t)(((t - x)^lambda)*u(x)) + Differential(t)(u(t)) ~ 0.0

```

---

<div class="post-metadata">

**Author:** ![Ashutosh\_Bharambe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashutosh_bharambe/32/37003_2.png) [@Ashutosh\_Bharambe](https://discourse.julialang.org/u/Ashutosh_Bharambe)\
**Post date:** [June 13, 2022, 3:22pm UTC](https://discourse.julialang.org/t/way-to-write-the-integral-with-modelingtoolkit/82347/9 "2022-06-13T15:22:45Z")

</div>

Hey @kaido975 there’s an issue with dealing integrands of this sort. We’re working on it.
