Numerical evaluation of multiple integral not working

5 views (last 30 days)
Hi guys,
I'm trying to numerically calculate the integral after Equation (1) from here: Distances In Bounded Regions
The final purpose is to calculate the average distance between all points in a region.
The result of the integral should be 0.5214.
I'm calculating it by calling integral2 function like this:
clear all;
f = @(theta,r)(1-r.*sin(theta)).*(1-r.*cos(theta)).*r.^2;
ymax = @(theta)1./cos(theta);
xmax = pi/8;
8*integral2(f, 0, xmax, 0, ymax)
However I'm getting the wrong answer. What's the problem with my code?

Accepted Answer

John D'Errico
John D'Errico on 8 Sep 2016
Edited: John D'Errico on 8 Sep 2016
Really? Lets do it symbolically.
syms r theta
kernel = (1-r.*sin(theta)).*(1-r.*cos(theta)).*r.^2;
rint = int(kernel,r,[0,1/cos(theta)])
rint =
1/(12*cos(theta)^3) - sin(theta)/(20*cos(theta)^4)
sbar = 8*int(rint,theta,[0,pi/8])
sbar =
log(tan((5*pi)/16))/3 - 16/(15*(2^(1/2) + 2)^(3/2)) + (2*2^(1/2))/(3*(2^(1/2) + 2)^(3/2)) + 2/15
vpa(sbar)
ans =
0.24810023714331117778996075103314
So the symbolic toolbox questions the result in that paper.
pretty(sbar)
/ / 5 pi \ \
log| tan| ---- | |
\ \ 16 / / 16 2 sqrt(2) 2
------------------ - ------------------- + ------------------ + --
3 3/2 3/2 15
15 (sqrt(2) + 2) 3 (sqrt(2) + 2)
What did integral2 produce as a result?
f = @(theta,r)(1-r.*sin(theta)).*(1-r.*cos(theta)).*r.^2;
ymax = @(theta)1./cos(theta);
xmax = pi/8;
8*integral2(f, 0, xmax, 0, ymax)
ans =
0.248100237144312
Which happens to be quite the same as that produced by the symbolic solution.
So I don't know where that article you found on the internet came from. But it seems to have at least one flawed claim in it. I won't spend the time to check their previous results, or the derivation that went into it. Anyone can post anything online, and with no validation of their results, you get what you pay for.
  3 Comments
Daniel
Daniel on 8 Sep 2016
To provide a follow up:
The paper is indeed wrong. With xmax=pi/4 the result in the paper is achieved.
Thanks again John!
John D'Errico
John D'Errico on 8 Sep 2016
Edited: John D'Errico on 8 Sep 2016
I read over that formula about 5 times to make sure that it was written as it was in the paper. Its easy to not trust your own code. After all, how can something written in a paper be wrong? As I said, the internet needs proofreaders. Sadly, the pay is poor.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!