# Dirac Delta with DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/dirac-delta-with-differentialequations-jl/84835>\
**Category:** Modelling & Simulations\
**Created:** [July 26, 2022, 5:14pm UTC](https://discourse.julialang.org/t/dirac-delta-with-differentialequations-jl/84835 "2022-07-26T17:14:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmdenis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmdenis/32/211517_2.png) [@cmdenis](https://discourse.julialang.org/u/cmdenis)\
**Post date:** [July 26, 2022, 5:14pm UTC](https://discourse.julialang.org/t/dirac-delta-with-differentialequations-jl/84835/1 "2022-07-26T17:14:51Z")

</div>

Hi,

I want to integrate a differential equations system numerically, but some equations involve Dirac delta functions.

Is there a built-in delta function to do this? Or should I be mimicking one with a continuous function?

Thanks!

---

<div class="post-metadata">

**Author:** ![liamfdoherty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liamfdoherty/32/24516_2.png) [@liamfdoherty](https://discourse.julialang.org/u/liamfdoherty)\
**Post date:** [July 26, 2022, 5:36pm UTC](https://discourse.julialang.org/t/dirac-delta-with-differentialequations-jl/84835/2 "2022-07-26T17:36:34Z")

</div>

There is a Dirac distribution available in `Distributions.jl` [here](https://juliastats.org/Distributions.jl/stable/univariate/#Distributions.Dirac) that might suit your needs.

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [July 26, 2022, 5:46pm UTC](https://discourse.julialang.org/t/dirac-delta-with-differentialequations-jl/84835/3 "2022-07-26T17:46:41Z")

</div>

Dirac deltas are not nice functions you can represent on a computer, so you can’t really have them naively. You can possibly get by with events. Eg if you solve for u’ = f(u) + delta(t=2), then solve u’ = f(u), set an event at t=2, and at that time modify the state u to have the appropriate behavior (here, a discontinuity of size 1). If your equation is more complicated, you have to derive the relationship between u(t+0) and u(t-0) by hand.

---

<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 26, 2022, 6:18pm UTC](https://discourse.julialang.org/t/dirac-delta-with-differentialequations-jl/84835/4 "2022-07-26T18:18:54Z")

</div>

Yeah that’s how it’s done. Just use a DiscreteCallback (or PresetTimeCallback). That’s how the adjoint system handles Dirac deltas.

---

<div class="post-metadata">

**Author:** ![cmdenis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmdenis/32/211517_2.png) [@cmdenis](https://discourse.julialang.org/u/cmdenis)\
**Post date:** [August 2, 2022, 8:18pm UTC](https://discourse.julialang.org/t/dirac-delta-with-differentialequations-jl/84835/5 "2022-08-02T20:18:55Z")

</div>

Ok, thank you! I’m using those callback functions:

[https://diffeq.sciml.ai/stable/features/callback\_functions/](https://diffeq.sciml.ai/stable/features/callback_functions/)

The continuous callback seems to do the trick for my specific use since I have functions inside the Dirac. The bouncing ball example made it very clear!
