4
$\begingroup$

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: Plot

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?

$\endgroup$
9
  • $\begingroup$ Can you show what you have tried? I assume you tried Integrate and NIntegrate? $\endgroup$
    – Szabolcs
    Commented Jan 15, 2020 at 12:33
  • $\begingroup$ 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. $\endgroup$
    – Gouz
    Commented Jan 15, 2020 at 12:41
  • $\begingroup$ Yes, that is the syntax. Have you read the documentation page of Integrate (and that of NIntegrate) and looked at the many examples? $\endgroup$
    – Szabolcs
    Commented Jan 15, 2020 at 12:49
  • 2
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Jan 15, 2020 at 13:06
  • 2
    $\begingroup$ @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). $\endgroup$ Commented Jan 15, 2020 at 13:45

2 Answers 2

2
$\begingroup$

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])]

$\endgroup$
6
  • $\begingroup$ 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? $\endgroup$
    – Gouz
    Commented Jan 21, 2020 at 2:52
  • $\begingroup$ 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. $\endgroup$
    – Gouz
    Commented Jan 21, 2020 at 3:04
  • 1
    $\begingroup$ @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. $\endgroup$ Commented Jan 21, 2020 at 4:47
  • $\begingroup$ @Gouz... looks like 10Pi ;-) $\endgroup$
    – mgamer
    Commented Jan 21, 2020 at 12:17
  • 1
    $\begingroup$ @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 ;-) $\endgroup$
    – mgamer
    Commented Jan 21, 2020 at 15:55
1
$\begingroup$
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$

$\endgroup$
2
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Jan 21, 2020 at 4:49
  • 1
    $\begingroup$ I have revised the statement. $\endgroup$ Commented Jan 21, 2020 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.