Integrating Gaussian in polar coordinates problem

In summary, the conversation discusses the conversion of a 2D Gaussian function from Cartesian to polar coordinates. The proof of this conversion is attached and the functions are plotted, showing similarity by visual inspection. However, when the functions are integrated over the same regions, the results are not always the same, with slightly different answers for cases where theta is not equal to zero. The code used for integration is provided, with an arbitrary example of parameters. It is noted that the results from Python and WolframAlpha are relatively similar, but small errors are expected due to numeric integration. Examples of these results are not provided.
  • #1
MathewsMD
433
7
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:
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
 

Attachments

  • Work.jpg
    Work.jpg
    33.9 KB · Views: 496
Physics news on Phys.org
  • #2
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?
 

FAQ: Integrating Gaussian in polar coordinates problem

1. How do you integrate a Gaussian function in polar coordinates?

The process of integrating a Gaussian function in polar coordinates involves first converting the function from Cartesian coordinates to polar coordinates. This can be done by substituting x and y with rcosθ and rsinθ, respectively. Then, the integral can be solved using the appropriate integration techniques, such as using trigonometric identities or integration by parts.

2. What is the formula for integrating a Gaussian function in polar coordinates?

The formula for integrating a Gaussian function in polar coordinates is ∫∫f(r,θ) rdrdθ, where f(r,θ) is the function in polar coordinates and the integral is taken over the desired region.

3. Why is it necessary to convert a Gaussian function to polar coordinates before integrating?

Converting a Gaussian function to polar coordinates allows for easier integration as it simplifies the function by removing any terms involving x and y. This makes it easier to integrate using the appropriate techniques and can also provide a clearer understanding of the function in terms of its radial and angular components.

4. Can a Gaussian function be integrated in polar coordinates using software?

Yes, there are a number of software programs that can integrate a Gaussian function in polar coordinates. These include mathematical software such as MATLAB and Python, as well as graphing calculators.

5. Are there any special considerations when integrating a Gaussian function in polar coordinates?

One special consideration when integrating a Gaussian function in polar coordinates is the choice of limits for the integral. Depending on the region of integration, the limits may need to be adjusted to properly capture the entire area under the curve. Additionally, it is important to consider any symmetry in the function, as this can help simplify the integration process.

Similar threads

Replies
5
Views
1K
Replies
6
Views
3K
Replies
1
Views
1K
Replies
6
Views
3K
Replies
5
Views
2K
Replies
4
Views
2K
Replies
5
Views
1K
Replies
4
Views
2K
Replies
5
Views
3K
Replies
20
Views
6K
Back
Top