# Integrating Gaussian in polar coordinates problem

1. Jun 15, 2015

### MathewsMD

I have a 2D Gaussian:

$f(x,y) = e^{-[(x-x_o)^2 + (y-y_o)^2]/(2*{sigma}^2)}$

which I converted into polar coordinates and got:

$g(r,θ) = e^{-[r^2 + r_o^2 - 2*r*r_o(cos(θ)cos(θ_o) + sin(θ)sin(θ_o))]/({2*{sigma}^2})}$

The proof for how this was done is in the attached file, and it would be great if someone could verify my steps in case I messed up somewhere. I have plotted the functions, and they do seem comparable by visual inspection.

The characteristics of the functions (including $sigma_o$) are manually specified by me, so the values for $x_o$, $y_o$ match up with $r_o$ and $θ_o$. Now, when I integrate these functions over the same regions, I don't always get the same answers. For example, when $r = 0$ or $θ = 0$, I do get the same answers, but when $θ != 0$, then the answers are slightly off. I have been trying to search for where I'm going wrong, and it may completely obvious (likely associated with the sine and cosine terms), but I'm just not seeing it. The fact that the values from completing the integration on Python (in polar coordinates) and WolframAlpha (in cartesian coordinates) are relatively similar for the cases where $θ != 0$ seems a little odd to me. If anyone has any thoughts, it would be greatly appreciated!

Here is my code:

Code (Text):

import numpy as np
from scipy import integrate

RIT = [] # Region Intensity (integration)
i = 0
N = 1
while i < N: #1 random beam generated
i = i + 1
sigma0 = 5 # just an example--arbitrary, I usually set it between 1 and 10
r0 = #you can input any value here, I usually set it between 0 and 10
theta0 = random.uniform(0,np.pi*2) #you can make it arbitrary instead of random if you wish
def G(r,theta): #this is the Gaussian in polar coordinates
return (np.e**(-((r**2 + r0**2 \
- 2*r*r0*(np.cos(theta)*np.cos(theta0) + \
np.sin(theta)*np.sin(theta0)))/(2*sigma0**2))))*r
#this r is here because
#the integrand includes dr and dtheta, NOT dx and dy any longer!!!
RI = integrate.nquad(G, [[4,7],[0,0.5*np.pi]]) #this region is between r = 4 and 7 in the first quadrant
RIT.append(RI)

print RIT

#### Attached Files:

• ###### Work.jpg
File size:
38.3 KB
Views:
113
2. Jun 15, 2015

### Staff: Mentor

What do you mean with relatively similar?
Numeric integration will always lead to small errors, and those are different for different parametrizations. It would be surprising if the results match "exactly".
Do you have some examples?