Dirac Delta with DifferentialEquations.jl

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!

There is a Dirac distribution available in Distributions.jl here that might suit your needs.

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.

4 Likes

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

3 Likes

Ok, thank you! I’m using those 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!

1 Like