Mathematica for Dirac delta functions and Green functions

Mathematica for Dirac delta functions and Green
functions
DiracDelta function
Mathematic has Dirac’s delta function built in for use in integrals and solving differential equations.
If you evaluate it directly you get 0 unless the argument is 0 in which case it gives you the function
back---it is not evaluated and does not evaluate to infinity.
8DiracDelta@1D, DiracDelta@0D, DiracDelta@- 1D<
80, DiracDelta@0D, 0<
So there is no peak in a plot of the function
Plot@DiracDelta@xD, 8x, - 1, 1<, Exclusions ® None, PlotStyle ® 8Red, Thick<D
1.0
0.5
-1.0
-0.5
0.5
1.0
-0.5
-1.0
However, it integrates to give the theta function:
Integrate@DiracDelta@xD, xD
HeavisideTheta@xD
Plot@HeavisideTheta@xD, 8x, - 1, 1<, Exclusions ® None, PlotStyle ® 8Red, Thick<D
1.0
0.8
0.6
0.4
0.2
-1.0
-0.5
0.5
1.0
2
RevisedGreen.nb
And differentiating the theta function returns the Dirac delta function
D@HeavisideTheta@xD, xD
DiracDelta@xD
Further derivatives are just denoted symbolically
D@DiracDelta@xD, xD
DiracDelta¢ @xD
Note that numerical integration over a delta function does not give the correct result because the routines cannot “find” the infinitely narrow peak. So, beware of this---use DiracDelta only in analytical
integrations or solves.
NIntegrate@DiracDelta@xD, 8x, - 1, 1<D
NIntegrate::izero :
Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion
option. If value of integral may be 0, specify a finite value for the AccuracyGoal option. ‡
0.
Integrals using Dirac delta function
Defining properties
Integrate@f@xD DiracDelta@x - 1D, 8x, - Infinity, Infinity<D
f@1D
Integral vanishes if integration range does not include position of delta function
Integrate@f@xD DiracDelta@x - 1D, 8x, - Infinity, 0.5<D
0.
Dirac delta is an even function
Integrate@f@xD DiracDelta@- xD, 8x, - 1, 1<D
f@0D
Correct Jacobians
Integrate@f@xD DiracDelta@3 Hx - 1LD, 8x, - 2, 2<D
f@1D
3
Example from lecture
Integrate@3 Exp@xD DiracDelta@Sinh@2 xDD, 8x, - Infinity, Infinity<D
3
2
Checking explicitly:
RevisedGreen.nb
D@Sinh@2 xD, xD
2 Cosh@2 xD
2 Cosh@0D
2
3
IntegrateB
2
3
Exp@xD DiracDelta@xD, 8x, - Infinity, Infinity<F
2
Correctly picks up multiple crossings of zero by argument of delta function
Integrate@f@xD DiracDelta@Sin@2 xDD, 8x, - 1, Pi + 1<D
Π
Kf@0D + fB F + f@ΠDO
2
2
1
More examples from lecture
Integrate@Cos@x  2D DiracDelta@Sin@xDD, 8x, - Pi  2, 3 Pi  2<D
1
Integrate@Cos@x  2D DiracDelta@Sin@xDD, 8x, - Pi  2, - Pi  4<D
0
Integrals of derivatives of delta functions
Integrate@f@xD DiracDelta'@xD, 8x, - 1, 1<D
- f¢ @0D
A few cautions about Mathematica’s DiracDelta[ ]:
Only HeavisideTheta[x]’s derivative gives DiracDelta[ ], functions with similar behavior do not
testfunctions =
8HeavisideTheta@xD, UnitStep@xD, HSqrt@x ^ 2D  x + 1L  2, HAbs@xD  x + 1L  2<
:HeavisideTheta@xD, UnitStep@xD,
x2
1
1+
2
1
x
Abs@xD
1+
,
2
x
>
3
4
RevisedGreen.nb
Plot@ð, 8x, - 1, 1<D & ž testfunctions
:
1.0
1.0
0.8
0.8
0.6
0.6
,
0.4
0.2
-1.0
-0.5
0.2
0.5
1.0
-1.0
-0.5
0.5
1.0
1.0
0.8
0.8
0.6
>
0.4
0.2
-0.5
1.0
0.6
,
0.4
-1.0
,
0.4
0.2
0.5
1.0
-1.0
-0.5
0.5
1.0
The limits from each side have the appropirate values
Limit@testfunctions, x ® 0, Direction ® 1D
80, 0, 0, 0<
Limit@testfunctions, x ® 0, Direction ® - 1D
81, 1, 1, 1<
At the discontinuous point they have different interpretations
testfunctions . x ® 0
1
Power::infy : Infinite expression
encountered. ‡
0
Infinity::indet : Indeterminate expression 0 ComplexInfinity encountered. ‡
1
Power::infy : Infinite expression
encountered. ‡
0
Infinity::indet : Indeterminate expression 0 ComplexInfinity encountered. ‡
8HeavisideTheta@0D, 1, Indeterminate, Indeterminate<
Mathematica will only correctly identify the derivative of HeavisideTheta[x] as DiracDelta[x]
D@testfunctions, xD
:DiracDelta@xD,
1
Indeterminate x Š 0
, 0,
0
True
2
DiracDelta[ ] is not defined for complex arguments:
DiracDelta@2 + ID
DiracDelta@2 + äD
Abs@xD
-
+
x2
Abs¢ @xD
x
>
RevisedGreen.nb
5
Integrate@DiracDelta@x - ID, 8x, - 2 I, 2 I<D
à
2ä
DiracDelta@- ä + xD â x
-2 ä
Limits which can be used to define a delta function will not return DeltaFunction[ ]:
Limit@¶  Hx ^ 2 + ¶ ^ 2L, ¶ ® 0D
0
Integrals will not return a delta function:
Integrate@Exp@I k xD, 8x, - ¥, ¥<, Assumptions -> k Î RealsD
Integrate::idiv : Integral of ãä k x does not converge on 8-¥, ¥<. ‡
IntegrateAãä k x , 8x, - ¥, ¥<, Assumptions ® k Î RealsE
But FourierTransform[ ] will:
FourierTransform@Exp@I k xD, x, y, FourierParameters ® 8- 1, - 1<D
DiracDelta@k - yD
Sec. 8.11 #9---example worked in class
Mathematica can deal with general t0 (which it assumes is real, as DiracDelta is only defined for reals):
Clear@t0, yD
soln9 =
Flatten@DSolve@8y ''@tD + 2 y '@tD + 10 y@tD Š DiracDelta@t - t0D, y '@0D Š 0, y@0D Š 0<,
y@tD, tDD  Simplify
:y@tD ®
1
3
ã-t+t0 HHeavisideTheta@3 t - 3 t0D - HeavisideTheta@- 3 t0DL Sin@3 Ht - t0LD>
Make into a function:
yy@t_D = FullSimplify@Flatten@y@tD . soln9 DD
1
3
ã-t+t0 HHeavisideTheta@t - t0D - HeavisideTheta@- t0DL Sin@3 Ht - t0LD
Next consider t0=1 for definiteness.
This gives the answer obtained in class in various ways:
t0 = 1; yy@tD
1
3
ã1-t HeavisideTheta@- 1 + tD Sin@3 H- 1 + tLD
Recall this is a damped oscillator at rest given a unit impulse at t=1, so that its slope has a discontinuity, although the function is continuous.
6
RevisedGreen.nb
Plot@yy@tD, 8t, - 1, 10<, PlotStyle ® 8Thick, Red<,
PlotRange ® 88- 1, 10<, 8- 0.2, 0.25<<D
0.2
0.1
2
4
6
8
10
-0.1
-0.2
Finding Green function obtained in Boas using “DiracDelta”
soln = DSolve@8y ''@tD + y@tD Š DiracDelta@t - tpD, y@0D Š 0, y@Pi  2D Š 0<, y@tD, tD
Π
::y@tD ® - Cos@tpD HeavisideThetaB - tpF Sin@tD + Cos@tpD HeavisideTheta@t - tpD Sin@tD 2
Cos@tD HeavisideTheta@t - tpD Sin@tpD + Cos@tD HeavisideTheta@- tpD Sin@tpD>>
To simplify, need to let Mathematica know the range of “tp”.
This result agrees with that we found.
soln2 = Simplify@soln, Assumptions ® 80 < tp < Pi  2<D
88y@tD ® - Cos@tpD Sin@tD + HeavisideTheta@t - tpD Sin@t - tpD<<
Green function is thus
GG@t_, tp_D = - Sin@tD Cos@tpD + HeavisideTheta@t - tpD Sin@t - tpD;
Sec. 8.12 #13---example worked in class
Forcing function.
ff@x_D = Piecewise@88x, 0 £ x < Pi  4<, 8Pi  2 - x, Pi  4 £ x < Pi  2<<D
0£x<
x
Π
2
0
-x
Π
4
£x<
True
Π
4
Π
2
RevisedGreen.nb
Plot@ff@xD, 8x, 0, Pi  2<, PlotStyle ® 8Thick, Red<D
0.8
0.6
0.4
0.2
0.5
1.0
1.5
Here’s the result for the solution using the Green function from above applied to the forcing function:
fullyy@x_D = Integrate@GG@x, xpD ff@xpD, 8xp, 0, Pi  2<D  Simplify
1
4
K- 4 J- 1 +
2 N Sin@xD - HeavisideThetaB-
Π
4
2 HΠ - 2 x - 2 Cos@xDL HeavisideThetaB-
K4 Hx - Sin@xDL + HeavisideThetaB-
Π
4
+ xF K- 2 Π + 4 x + 4 CosB
Π
Π
+ xF +
4
Π
+ xF + Π SinB
2
+ xF K- 4 x - 4 CosB
+ xFO + HeavisideTheta@xD
4
Π
Π
+ xF + Π SinB
4
+ xFOOO
4
To get simple form, need to tell Mathematica the range of x:
yyless@x_D = Integrate@GG@x, xpD ff@xpD, 8xp, 0, Pi  2<, Assumptions ® 80 < x < Pi  4<D
x-
2 Sin@xD
yymore@x_D =
Integrate@GG@x, xpD ff@xpD, 8xp, 0, Pi  2<, Assumptions ® 8Pi  4 < x < Pi  2<D
1
2
JΠ - 2 x - 2
2 Cos@xDN
Subsequent three plots show resulting y, y’ and y’’, so that one can see the nature of the solution,
whose third derivative is discontinuous.
7
8
RevisedGreen.nb
Plot@fullyy@xD, 8x, 0, Pi  2<, PlotStyle ® 8Thick, Blue<, AxesLabel ® 8"x", "y"<D
y
x
0.5
1.0
1.5
-0.05
-0.10
-0.15
-0.20
Plot@Evaluate@D@fullyy@xD, xDD, 8x, 0, Pi  2<,
PlotStyle ® 8Thick, Blue<, AxesLabel ® 8"x", "y'"<D
y'
0.4
0.2
x
0.5
1.0
1.5
-0.2
-0.4
Plot@Evaluate@D@fullyy@xD, 8x, 2<DD, 8x, 0, Pi  2<,
PlotStyle ® 8Thick, Blue<, AxesLabel ® 8"x", "y''"<D
y''
1.0
0.8
0.6
0.4
0.2
x
0.5
1.0
1.5
Mathematica can also solve the differential equation including the piecewise function:
RevisedGreen.nb
Simplify@DSolve@8y ''@xD + y@xD Š ff@xD, y@0D Š 0, y@Pi  2D Š 0<, y@xD, xDD
::y@xD ®
- J- 1 +
- J- 1 +
1
2
2 N Cos@xD
2 N Sin@xD
JΠ - 2 x - 2
x-
2 Sin@xD
2 Cos@xDN
2x>Π
x£0
Π
4
<x£
True
Π
2
>>
Keep in mind when Mathematica says “True” for a piecewise function, it just means “Otherwise”
9