How to numerically solve a differential equation with a dirac delta function ?
Mostrar comentarios más antiguos
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 comentarios
Alan Stevens
el 30 de Jun. de 2020
What are your initial conditions and the time over which you want to solve?
Mohit Kumar
el 30 de Jun. de 2020
Alan Stevens
el 30 de Jun. de 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
el 30 de Jun. de 2020
Mohit Kumar
el 1 de Jul. de 2020
Alan Stevens
el 1 de Jul. de 2020
Editada: Alan Stevens
el 1 de Jul. de 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?
Respuesta aceptada
Más respuestas (1)
Carlos M. Velez S.
el 24 de Jul. de 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 comentario
Walter Roberson
el 24 de Jul. de 2025
ode45() is not a continuous time system, so this function is irrelevant to the situation.
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




