Integrating Gaussian in polar coordinates problem

Click For Summary
SUMMARY

The discussion centers on integrating a 2D Gaussian function in polar coordinates, specifically the transformation from Cartesian coordinates to polar coordinates. The Gaussian function is defined as f(x,y) = e^{-[(x-x_o)^2 + (y-y_o)^2]/(2*{sigma}^2)} and its polar counterpart is g(r,θ) = e^{-[r^2 + r_o^2 - 2*r*r_o(cos(θ)cos(θ_o) + sin(θ)sin(θ_o))]/({2*{sigma}^2})}. The user reports discrepancies in integration results between Python (using SciPy) and WolframAlpha, particularly when θ is not equal to zero. The integration is performed over specified regions, and the user seeks verification of their steps and insights into potential errors.

PREREQUISITES
  • Understanding of Gaussian functions and their properties
  • Familiarity with polar coordinates and coordinate transformations
  • Proficiency in Python programming, particularly with NumPy and SciPy libraries
  • Basic knowledge of numerical integration techniques
NEXT STEPS
  • Review the mathematical derivation of Gaussian functions in polar coordinates
  • Learn about numerical integration methods in Python using SciPy's integrate module
  • Explore the differences between Cartesian and polar coordinate systems in mathematical modeling
  • Investigate error analysis in numerical integration to understand discrepancies in results
USEFUL FOR

Mathematicians, physicists, data scientists, and software developers working with Gaussian functions and numerical integration in Python.

MathewsMD
Messages
430
Reaction score
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: 564
Physics news on Phys.org
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?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K