Problem in 2 dimensional numerical integration

I am trying to integrate a function of the form
, (where H is the heaviside function)
for the domain , where and are fixed constants, i.e.,
= ??
For this I have used the code:
y1 = 10; y2 = 20;
B = @(x1,x2) ( y1.*del(x1-y1).*heaviside(y2-y1) + y2.*del(x2-y2).*heaviside(y1-y2) )./(y1.*y2);
integral2(B,0,y1,0,y2)
where 'del' is the dirac delta function defined below:
%% definiiton of del
function retval = del(x)
if x==0
retval = 1;
else
retval = 0;
end
return
Now if I run the main code, it gives the following error:
Error using integral2Calc>integral2t/tensor (line 241)
Integrand output size does not match the input size.
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in test (line 4)
integral2(B,0,y1,0,y2)
Any suggestions?

Answers (1)

Hi Ashok,
you can make a decent case that the answer is 1/2, at least if the variables are continuous. For the first term,
Int{0,y1} delta(x1-y1) dx1 = 1/2
Int{0,y2} dx2 = y2
so the first term is
(1/2) H(y2-y1)
Likewise, the second term is
(1/2) H(y1-y2)
and the whole thing is
(1/2)( H(y2-y1)+H(y1-y2)) = 1/2

4 Comments

Ashok Das
Ashok Das on 31 Jan 2020
Edited: Ashok Das on 31 Jan 2020
Thanks David.
But my query is not about the answer, it is about how to do that.
In my case, this is not the only integration required, I need to integrate the functions in several domains, as well as multiplying the function 'b' by some other functions too.
I just posted the query in order to check that, whether I am getting the right integral value or not. As you have said, the correct value will be 1.
Hi Ashok,
I was maintaining that the answer here is 1/2, not 1. However, I appreciate what you are saying about this just being a simple example of a more general problem that you want to solve. I will probably delete my answer but I believe that will also delete your comment, so in the meantime I would like to inquire, are the variables discrete by intent, or are discrete variables being used to approximate a continuous variable situation?
Hi David,
The variables are continuous by nature.
If that's the case, can't you basically do the delta function part of the integrals by hand first, or are there too many delta functions in your expressions for that to be feasible? (and I still like 1/2)

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

on 30 Jan 2020

Community Treasure Hunt

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

Start Hunting!