How to numerically solve a differential equation with a dirac delta function ?
이전 댓글 표시
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
Alan Stevens
2020년 6월 30일
What are your initial conditions and the time over which you want to solve?
Mohit Kumar
2020년 6월 30일
Alan Stevens
2020년 6월 30일
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
2020년 6월 30일
Mohit Kumar
2020년 7월 1일
Alan Stevens
2020년 7월 1일
편집: Alan Stevens
2020년 7월 1일
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?
채택된 답변
추가 답변 (1개)
Carlos M. Velez S.
2025년 7월 24일
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
Walter Roberson
2025년 7월 24일
ode45() is not a continuous time system, so this function is irrelevant to the situation.
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




