# How to calculate volume under $f(x, y)$?

I have the following function:

σ = 0.3;
μ = 5;
cy =0;
cx=0;
f[x_,y_]=Exp[-(1/2)((Sqrt[(x-cx)^2+(y-cy)^2]-μ)/σ)^2]/(σ*Sqrt[2*π])


Plotting this with:

max=10;
Plot3D[f[x,y], {x, -max, max}, {y, -max,max}, PlotPoints -> {100, 100},PlotRange -> Full, ClippingStyle -> None, ImageSize -> {1000, 1000},Axes-> True,BoxRatios ->Automatic]


I get the following:

What I need is to calculate the volume below the entire function (Infinity) so I can use it as a normalization constant for using this function as a 2D PDF.

How can I do that?

• Can you show what you have tried? I assume you tried Integrate and NIntegrate? Commented Jan 15, 2020 at 12:33
• Is this the correct syntax: Integrate[f[x,y],{x,-Infinity,Infinity},{y,-Infinity,Infinity}]? I get a value but I am not sure whether this is correct.
– Gouz
Commented Jan 15, 2020 at 12:41
• Yes, that is the syntax. Have you read the documentation page of Integrate (and that of NIntegrate) and looked at the many examples? Commented Jan 15, 2020 at 12:49
• To verify, replace Integrate by NIntegrate and compare numerically. If NIntegrate complains, try subdividing the region like this : NIntegrate[f[x,y],{x,-Infinity,-5,5,Infinity},{y,-Infinity,-5,5,Infinity}], where I picked ±5 from your graph. You could also change to polar coordinates, which could be reduced to a single integral and and even be done by hand. Two or three distinct approaches that agree is pretty good evidence. Commented Jan 15, 2020 at 13:06
• @Gouz The result from Integrate looks plausible. In your case of a normalization constant for a probability distribution Mathematicas automatic normalization does this conveniently for you: dist = ProbabilityDistribution[ Exp[-(1/2) ((Sqrt[(x - cx)^2 + (y - cy)^2] - \[Mu])/\[Sigma])^2]/(\[Sigma]* Sqrt[2*\[Pi]]), {x, -\[Infinity], \[Infinity]}, {y, \ -\[Infinity], \[Infinity]}, Method -> "Normalize", Assumptions -> \[Mu] > 0 \[And] \[Sigma] > 0] and is usable as a distribution (PDF, CDF, RandomVariate, etc. directly work). Commented Jan 15, 2020 at 13:45

This function is rotationally symmetric about {cx,cy} and hence polar coordinates might be a good idea. Indeed, the integral can be computed symbolically this way:

ClearAll[cx, cy, \[Sigma], \[Mu]];
f[x_, y_] =
Exp[-(1/2) ((Sqrt[(x - cx)^2 + (y - cy)^2] - \[Mu])/\[Sigma])^2]/(\[Sigma] Sqrt[2 \[Pi]])
\[CapitalPhi] = {r, \[Theta]} \[Function] {cx + r Cos[\[Theta]], cy + r Sin[\[Theta]]};
g = Simplify[ f @@ \[CapitalPhi][r, q] Det[D[\[CapitalPhi][r, \[Theta]], {{r, \[Theta]}, 1}]]]
Integrate[g, {\[Theta], -Pi, Pi}, {r, 0, \[Infinity]}]


E^(-(\[Mu]^2/(2 \[Sigma]^2))) Sqrt[ 2 \[Pi]] \[Sigma] + \[Pi] \[Mu] Sqrt[ 1/\[Sigma]^2] \[Sigma] + \[Pi] \[Mu] Erf[\[Mu]/(Sqrt[2] \[Sigma])]

• For σ=0.3, μ=5, cx=0 and cy=0, the NIntegrate[ f[x, y], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] returns 31.4159 (which btw surprised me since I picked these values by random and the outcome is aprox. pi*10) which is indeed the same as yours with the difference that yours, has also an imaginary part (i.e. 31.4159 - 1.07255*10^-12i). How to interpret this number?
– Gouz
Commented Jan 21, 2020 at 2:52
• On the other hand, the first way returns different values for different cx's and cy's which is also weird to me (shouldn't the integral be the same no matter the cx's and cy's?), while your approach indeed returns the same value nomatter the cx's and cy's. Which makes me feel a bit lost.
– Gouz
Commented Jan 21, 2020 at 3:04
• @Gouz with Henrik’s approach, we stay symbolic, and are not subject to the numerical error propagation present in uses of NIntegrate and other numeric functions. Commented Jan 21, 2020 at 4:47
• @Gouz... looks like 10Pi ;-) Commented Jan 21, 2020 at 12:17
• @HenrikSchumacher. Yes, but the output of the computed integral (your code) is 10*Pi - 5 * GammaRegularized[-(1/2), 1250/9] this is 10Pi -1.28589*10^-63. For this specific mu and sigma, cx=cy=0.Not exactly 10 Pi but a good approximation ;-) Commented Jan 21, 2020 at 15:55
In[2]:=
σ = 0.3;
μ = 5;
cy =0;
cx=0;
f[x_,y_]=Exp[-(1/2)((Sqrt[(x-cx)^2+(y-cy)^2]-μ)/σ)^2]/(σ*Sqrt[2*π])

\!$$\*SubsuperscriptBox[\(\[Integral]$$, $$-\[Infinity]$$, \
$$\[Infinity]$$]$$\*SubsuperscriptBox[\(\[Integral]$$, $$-\[Infinity]$$, \
$$\[Infinity]$$]f[x, y] \[DifferentialD]x \[DifferentialD]y\)\)
Out[2]:31.4159


$$\int _{-\infty }^{\infty }\int _{-\infty }^{\infty }f(x,y)dxdy$$

• This is merely a formatted output. Did you mean to post this with more content? —As it is now, it does not answer the question posed by the OP. Commented Jan 21, 2020 at 4:49
• I have revised the statement. Commented Jan 21, 2020 at 5:53