How do you do a numerical integration of a delta function in MATLAB?

Say I have a function f(x,y) and a number A. My function g(x,y)=1 when A-f(x,y)>0 and 0 when A-f(x,y)<0 and 0 when A-f(x,y)=0. I would like to do a double integral over x and y (x goes from 0 to 1, and y goes from x-1 to -x+1) of the delta-like function g(x,y).
I am trying to use integral2, but I don't know what function in matlab I could use for g(x,y).
Thanks!

 Accepted Answer

You seem to have defined a step (Heaviside) function, not a delta function. The easiest way to do the integration is to integrate separately for ‘A-f(x,y)>0’ and ‘A-f(x,y)<=0’, then sum them.
I don’t understand what ‘g(x,y)’ is doing, because it only appears qualitatively in your description, so I didn’t include it.

3 Comments

Oh great, thank you, yes it is a heaviside function. I meant say g(x,y) is the heaviside function. I am not sure why I would need to do the integration separately though?
I am using the code (Say my function 'f(x,y) = x^2+y^2):
fun = @(x,y) heaviside(A-(x^2+y^2))
ymax = @(x) 1 - x;
ymin = @(x) -1 + x;
q = integral2(fun,0,1,ymin,ymax)
This seems to work I think.
Thank you!
Heaviside and Dirac Delta have discontinuities. The integral2() function is not designed to deal with discontinuities. The integral() function can handle some forms of discontinuity provided that you supply waypoints
@Sonia — My pleasure!
@Walter — Thank you!

Sign in to comment.

More Answers (1)

Sometimes you need to rewrite integral2 in terms of nested integral() so that you can pass in the waypoints option

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!