How to numerically solve a differential equation with a dirac delta function ?
Afficher commentaires plus anciens
The differential equation that I want to solve is
Upon using ode45 and the dirac function, the dirac function doesn't seem to have any effect (which makes sense because x never reaches 1 in a numerical solution)
Any ideas on how to solve this numerically?
6 commentaires
Alan Stevens
le 30 Juin 2020
What are your initial conditions and the time over which you want to solve?
Mohit Kumar
le 30 Juin 2020
Alan Stevens
le 30 Juin 2020
You could use a coarse approximation to the dirac delta function to see it give a kick to dx/dt. Something like:
d = 0;
if abs(x - 1) < small value
d = (v - abs(v))/2;
end
dXdt = [v; -v - x + d];
However, the "small value" probably needs to be quite large (say 10^-1 or 10^-2 ) to see anything!
Any smaller and ode45 is likely to jump across x = 1 without invoking the condition.
Mohit Kumar
le 30 Juin 2020
Mohit Kumar
le 1 Juil 2020
Alan Stevens
le 1 Juil 2020
Modifié(e) : Alan Stevens
le 1 Juil 2020
Hmm. I assumed you just wanted the dxdt - |dxdt| to kick in when x = 1 (The area under the delta function being unity). I'm not sure what you are after if you truly want it to go to infnity (what do you expect the ode function to do with that?). Indeed, if infinity is what you want why bother multiplying it by anything else?
Réponse acceptée
Plus de réponses (1)
Carlos M. Velez S.
le 24 Juil 2025
If you want to apply the Dirac delta function in simulation to continuous-time systems, the following code is enough:
function y = delta_dirac(u)
[n,m] = size(u);
if max(n,m) ==1
dt = 1e-6; % Define a small time increment for the delta function
else
dt = u(2) - u(1);
end
y = zeros(n,m);
for i=1:max(m,n)
if u(i) == 0
y(i) = 1/dt;
else
y(i) = 0;
end
end
1 commentaire
Walter Roberson
le 24 Juil 2025
ode45() is not a continuous time system, so this function is irrelevant to the situation.
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




