現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to numerically solve a differential equation with a dirac delta function ?
50 ビュー (過去 30 日間)
古いコメントを表示
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 日
Timespan : 0 to say 100 Initial values : x(0)= any value more than 1 x_d(0) = say 0
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 年 7 月 1 日
Alan, this might be something that you missed in your previous comment. The dirac delta function assumes a value of infinity when its argument goes to zero.
So this creates a lot of approximation in the coarse version of the dirac delta function : "small value", "dirac delta's infinity" and the ode's step size.
I implemented the following code for the dirac delta function:
if abs(x-1)<0.01
x_dd=-(x+epsilon*(x_d-0.5*(x_d-abs(x_d))*1e5));
disp(['triggered ' num2str(t)]);
else
x_dd=-(x+epsilon*x_d);
end
And used a maximum step with the ode45 as 0.001
However, the dirac delta function triggers only at specific intervals when the function crosses 1, not all of them. This felt extremely weird. A plot is attached.

Thanks
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?
採用された回答
Walter Roberson
2020 年 7 月 1 日
Use ode45 to solve the equation over the start time to time 1 (the place the dirac delta is located.) Do not use the if statements like Alan and Mohit show: just end the integration at the point they would take effect. Using if presents theory problems that you can avoid by just stopping at the place of the event.
Now take the final output of that ode45 and give the appropriate kick to the boundary conditions.
Then restart the ode45 from time 1 to the final desired time, passing in the kicked boundary conditions. Do not use if -- again you avoid the theory problem by not having ode45 cross the interval of discontinuity.
11 件のコメント
Mohit Kumar
2020 年 7 月 1 日
Thanks for the answer Walter. Two questions about this implementation:
- How will we know the value of x and x_d after the boundary? All we know is that there will be a kick and that it is infinitely big.
- How do we locate when x reaches 1? I can think of a heuristic method of doing it for an initial condition and then noting down the time. But is there a better approach?
Thanks!
Walter Roberson
2020 年 7 月 1 日
Ah, I was thinking
was related to time, not to position. To do it for position, you would need to set up an ode event; see ballode https://www.mathworks.com/help/matlab/math/ode-event-location.html#bu7wjcg for a good example.

Because it is an integral equation,
will be 0 outside of
to
and will be
inside of
to
.
is not a value, it is a distribution. You cannot substitute infinity at the location where x-1=0 (which is to say, at x=1). Dirac delta is like a probability density function taken in the limit -- and knowing the probability of something does not tell you what the value is. The value associated is whatever the dirac delta is being multiplied by.







So, when the event tells you have reached x = 1, then you pull out the last t and last vector of boundary conditions. The vector of boundary conditions will probably be in the order [x,
] so to calculate the kick, you would take

boundaries = x{end,:};
kick = boundaries(2) - abs(boundaries(2));
Though at the moment I am not sure which component the kick should be applied to.. the second component, I think (not sure at all.)
Note: in theory x could cross 1 more than once, so you should loop the sequence, not just assume that it will only happen once.
Mohit Kumar
2020 年 7 月 3 日
Thanks for the answer Walter.
The article on ode events is very interesting. Did not know a thing about that! That will definitely help in the location of the event.
Also, the interpretation of the delta function analogous to the limiting value of a probability distribution makes sense. Admittedly, my knowledge of the dirac delta function is very limited.
Yet, the magnitude of the kick and the components to apply it to still remains unclear. This is because the only information we have for sure is that the differential equation is changing in the limiting neighbourhood of 1.
At this point, I do think that I am limited by my mathematical understanding of the dirac delta function :(
Walter Roberson
2020 年 7 月 3 日
In the context of differential equations, dirac deltas represent impulses at the time(s) that the dirac parameter becomes zeros, with impulse magnitude given by what the diract delta is being multiplied by.
WIth
being real-valued, then
is 0 if
is positive, and is
when
is negative. (The value is then divided by 2.) So there is no impulse if x is increasing (
positive ) and a kick downwards if x is decreasing.






The trick will be to figure out what it all means with respect to preserving the equation having to be 0 even under the circumstances of the impulse.
Mohit Kumar
2020 年 7 月 5 日
編集済み: Mohit Kumar
2020 年 7 月 5 日
Aha! I understand the problem much better now. I think this might be a viable solution. Let me know of your opinion of this and if this is theoretically valid.
At
if x is decreasing, the differential equation suddenly becomes
. As
,
.




So I propose that we can start the simulation from this point such that the output of the differential equation is
, where
is whatever value it initially was.


I'll try coding this and update here as to what happens.
David Goodmanson
2020 年 7 月 9 日
編集済み: David Goodmanson
2020 年 7 月 11 日
Hi Mohit, MODIFIED
I assume that x and t are reversed on your plot, otherwise you have several x values for the same t.
Without the delta function, the solution for x is
x = A*exp(-t/2)*cos(w*t+theta), with w = sqrt(3)/2.
Taking the dellta function term to the right hand side,
x'' +x' +x = -abs(xdot)*delta(x-x0) xdot <0 (1a)
= 0 xdot >0 (1b)
(It's best to use x0 here and set x0=1 later). There is a negative impulse if x crosses x0 with negative velocity.
If A is not large enough the function will never cross x = x0, so assume that A is greater than x0, maybe much greater than x0.
The delta function in x = x(t) needs to be re-expressed as a delta function in t. A standard identity for the delta function is
delta(x(t)-x0) = (1/abs(( dx/dt | t=t0 ))) * delta(t-t0)
where x(t0) = x0.
[ Here ( dx/dt | t=t0 ) is dx/dt evaluated at t0, and is a constant ].
The second line above assures that as t sweeps through t0, x sweeps through x0. That equation is used to determine t0.
Now
delta(x-x0) = 1/abs(xdot)) *delta(t-t0)
Plugging that into (1a) cancels the xdots and gives
x'' +x' +x = -delta(t-t0) xdot < 0
= 0 xdot > 0
where t0 is such that x(t0) = x0.
Under the usual assumptions, x is continuous and xdot is discontinuous across the delta function. For a delta function term of the form
B*delta(t-t0)
then
xdot(t0+eps) - xdot(t0-eps) = B
Since B = -1,
xdot(t0+eps) = xdot(t0-eps) -1
when crossing the delta function. So you can use event detection for x = x0 and then let xdot --> xdot-1 for the new initial condition.
Mohit Kumar
2020 年 7 月 10 日
編集済み: Mohit Kumar
2020 年 7 月 10 日
Great! That definitely solves my doubts!
Although I can now surely simulate the response, out of curiosity I would want to know a rough theoretical/intuitive background for this step.
xdot(t0+eps) - xdot(t0-eps) = B
If you could point me to any resource or answer it yourself, that will be great!
And yes, you rightly pointed out my careless mistake of interchanged axes.
David Goodmanson
2020 年 7 月 11 日
Hi Mohit,
This was a good request of yours, because I realized I made a mistake in the derivation. I modified my comment above to reflect that. For the equation in your comment, take
x'' + x' +x = B*delta(t-t0)
(the delta function is in t, not x) and assume the usual solution with
x continuous across the boundary and x' discontinouos across the boundary.
Integrate both sides from t0-eps to t0+eps and evaluate at the limits to obtain
x'(t0+eps) -x'(t0-eps) +x(t0+eps) -x(t0-eps)
+ Integral{t0-eps,t0+eps} x dt = B
The x(t0+eps) -x(t0-eps) terms cancel because x is continous. The integral term is zero because you are integrating across a vanishly small interval. That leaves
x'(t0+eps) -x'(t0-eps) = B
Mohit Kumar
2020 年 7 月 11 日
Thanks a lot for your response!
For the step that you use here,
delta(x(t)-x0) = (1/abs(( dx/dt | t=t0 ))) * delta(t-t0)
I tried to work out a derivation. Is this the correct jutification?

Hence, equating the functions inside the first and last term of the equality,

David Goodmanson
2020 年 7 月 12 日
編集済み: David Goodmanson
2020 年 7 月 12 日
Hi Mohit,
there is nothing in the derivation that connects t0 with x0, i.e. it's necessary that x(t0) = x0. Also if two definitie integrals are equal to each other that generally says nothing about the relation of the integrands to each other.
One of the easier ways to show this is by considering the delta function as a tall skinny gaussian function:
delta(x) ~~ (C/abs(a)) *exp(-x^2/a^2) (1)
in the 'limit' as a --> 0. The abs(a) is there because 'a' can be either positive or negative in the a^2 factor but the delta spike is supposed to be positive. (The limit can only be taken after multiplying by some function and integrating, but we will eventually be doing that sometime. It's kind of like Huck Finn saying it's not really stealing if you intend to give it back). Here C = 1/sqrt(pi) is a normalization factor so that the integral of this function = 1.
Consider delta(x(t)-x0)
delta(x(t)-x0) ~~ (C/abs(a))*exp(-(x(t)-x0)^2/a^2)
and suppose x = x0 at t = t0, i.e. x(t0) = x0. This is where the relation between x0 and t0 comes in.
If you expand x(t) in a Taylor series about t=t0 and keep only the constant term and the term that is linear in ((t-t0) you should be able to prove the result. Keep in mind that whatever squared constant appears in the denominator of the exponent, its abs value has to appear in the denominator in the factor in front.
Mohit Kumar
2020 年 7 月 13 日
Ah right, my proof is definitely fallacious. I got carried away trying to contrive the derivation!
Your derivation is nice and concise! Thanks for all the help! Glad to have learnt (although superficially) a hitherto alien concept of the dirac delta function in the context of differential equations.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Trigonometry についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)