1
$\begingroup$

So I want to integrate an expression that looks something like this:

Integrate[f[x]+DiracDelta[x-y]g[x],{x,-Infinity,Infinity}]

With some more terms added with delta functions after g[x]. Even after expanding and simplifying Mathematica won't break up the expression and evaluate the delta function, it just leaves it in exactly the form I have above. How do I make Mathematica evaluate the integral term by term?

Cheers :)

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Commented Apr 20, 2015 at 2:23

2 Answers 2

3
$\begingroup$

I would try to see if you can use Distribute for this:

Distribute@
 Integrate[f[x] + DiracDelta[x - y] g[x], {x, -Infinity, Infinity}]

distribute

Unlike Map, Distribute is especially (though not exclusively) intended for use with sums.

$\endgroup$
2
  • $\begingroup$ Perfect. My only problem with that is some of my terms should actually be integrated over a different dummy variable. Apart from that it looks great. $\endgroup$ Commented Apr 20, 2015 at 7:09
  • $\begingroup$ Actually, nevermind - you're a life saver :) $\endgroup$ Commented Apr 21, 2015 at 6:40
2
$\begingroup$

One approach, admittedly not elegant, is

Map[Integrate[#, {x, -∞, ∞}] &, f[x] + DiracDelta[x - y] g[x]]
(* ConditionalExpression[g[y] + Integrate[f[x], {x, -∞, ∞}], Element[y, Reals]] *)

Incidentally, the code in the Question can be rewritten as

Integrate[#, {x, -∞, ∞}] & @ (f[x] + DiracDelta[x - y] g[x])

and the code at the beginning of this Answer as

Integrate[#, {x, -∞, ∞}] & /@ (f[x] + DiracDelta[x - y] g[x])

From this perspective the change needed to integrate DiracDelta is small.

Addendum

In response to the OP's Comment below, if the integral in the Question is designated int (for instance), then

int = Integrate[f[x]+DiracDelta[x-y]g[x],{x,-∞, ∞}];
Integrate[#, {x, -∞, ∞}] & /@ int[[1]]

produces the desired result without copying the integrand.

$\endgroup$
4
  • $\begingroup$ Yeah I thought of that, the only problem is that my expression is actually about 20 terms long, none of the terms are the same and 18 have delta functions. So a simple replacement rule like that will only work if I actually write in all 20 terms myself, in which case I might as well not bother. $\endgroup$ Commented Apr 20, 2015 at 5:17
  • $\begingroup$ @SpamuelNeedbeef Does the addendum address your issue? $\endgroup$
    – bbgodfrey
    Commented Apr 20, 2015 at 5:26
  • $\begingroup$ It does, but some of my terms in the integral are actually over different dummy variables - an unfortunately unavoidable annoyance. $\endgroup$ Commented Apr 20, 2015 at 7:27
  • $\begingroup$ All sorted. Thanks folks! $\endgroup$ Commented Apr 21, 2015 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.