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!




