How can I integrate a multivariable function that includes Dirac delta?

I'm trying to integrate an expression that includes a Dirac delta function, but the "integral" function (as well as integral2 and integral3) isn't handling the Dirac delta correctly.
For example,
f = @(x) dirac(x);
q = integral(f,-100,100)
gives me an incorrect answer of 0, while
p = int(dirac(x),x,-100,100)
gives me a correct answer of 1.
Is this just a factor of the integral function using numerical integration? If so, any recommendations for how to integrate multivariable functions with a Dirac delta in MATLAB?

 Accepted Answer

When you use integral() you need to add Waypoints corresponding to everywhere the dirac changes between zero and non-zero, because each dirac is a discontinuity.

3 Comments

Can you provide an example of the same?
I have the following situation.
x = -1:4
x =
-1 0 1 2 3 4
x.^3.*dirac(x-3)
ans =
0 0 0 0 Inf 0
f = @(x)(x.^3.*dirac(x-3))
f =
function_handle with value:
@(x)(x.^3.*dirac(x-3))
integral(f,-1,4,'Waypoints',3)
ans =
0
Good question, Rupsagar Chatterjee . I am seeing seemingly contradictory explanations of waypoints, and as I dig into the code, it does not look to me as if the function gets executed at the waypoints exactly.
Ah, the documentation says,
Do not use waypoints to specify singularities. Instead, split the interval and add the results of separate integrations with the singularities at the endpoints.
This would mean that in your example you should calculate
integral(f,-1,3) + integral(f,3,4) + value associated with f(3)
When I say value associated with f(3), I do not mean f(3) itself, since dirac(0) is classically infinity; you would need to know to use the value associated with the distribution dirac(0), which is to say 1, multiplied by any associated constant or function value...
This is, of course, a nuisance, and the value to be associated with the point is not always obvious.
My summary... integral() appears to be unable to integral dirac() properly in practice. :(

Sign in to comment.

More Answers (1)

Matt J
Matt J on 14 Feb 2016
Edited: Matt J on 14 Feb 2016
So you want to do symbolic double and triple integrals, etc...? If so, can't you apply int() several times in succession?

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!