- #1
MathewsMD
- 433
- 7
I have an original function ##z_{xy}## that I converted into cylindrical coordinates, now denoted ##z_{rθ}##. I have shown the steps I took to get here in the image file posted named "Work."
Now, I have taken that work and converted it into code to plot in Python. I plotted it in another piece of code not shown here and it looks fine (I can post that here too, if necessary) but am now trying to integrate this but am running into an odd error. Here is the code for the integration:
Now, since I am integrating in polar coordinates, which is in drdtheta, I multiplied G by r when running the code to get the appropriate unit of area since the Python integration subroutine does not recognize this (I assume). Thus, I multiplied G by r (i.e. I removed the # at the end of the function in the code) but I also did not multiply G by r to get the result for a separate run as well.
When I did this, the values I got for integration were:
Integral on G*r = 100.530965
Integral on G = 31.49992199
(Just to clarify, I made these values constant to ensure I had a mean on the origin and integrated over a circle of radius 4.)
I also did this integration on WolframAlpha in Cartesian coordinates as shown in the second image attached. As you can see, the value for this integration from WolframAlpha is 39.5559, which does not match either of the integral values I got. I've been looking through this code for a while now and can't seem to figure out what's causing the mistake. Is there a problem in my early substitution when I converted the equation from Cartesian to Cylindrical coordinates? Am I forgetting to change any variables in the integrand?
Also something else I found odd was that if I transpose the indexes for the integration (i.e. :
becomes
I still get the same result. That doesn't seem right...
Any help with regards to where I am going wrong and advice would be greatly appreciated!
Now, I have taken that work and converted it into code to plot in Python. I plotted it in another piece of code not shown here and it looks fine (I can post that here too, if necessary) but am now trying to integrate this but am running into an odd error. Here is the code for the integration:
Code:
import numpy as np
from scipy import integrate
while i < 1: #run once
i = i + 1
sigma0 = 4
r0 = 0
theta0 = 0
def G(r,theta):
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 #NOTE: # before r is also removed in attempt
R1I = integrate.nquad(G, [[0,4],[0,2*np.pi]])
print R1I
Now, since I am integrating in polar coordinates, which is in drdtheta, I multiplied G by r when running the code to get the appropriate unit of area since the Python integration subroutine does not recognize this (I assume). Thus, I multiplied G by r (i.e. I removed the # at the end of the function in the code) but I also did not multiply G by r to get the result for a separate run as well.
When I did this, the values I got for integration were:
Integral on G*r = 100.530965
Integral on G = 31.49992199
(Just to clarify, I made these values constant to ensure I had a mean on the origin and integrated over a circle of radius 4.)
I also did this integration on WolframAlpha in Cartesian coordinates as shown in the second image attached. As you can see, the value for this integration from WolframAlpha is 39.5559, which does not match either of the integral values I got. I've been looking through this code for a while now and can't seem to figure out what's causing the mistake. Is there a problem in my early substitution when I converted the equation from Cartesian to Cylindrical coordinates? Am I forgetting to change any variables in the integrand?
Also something else I found odd was that if I transpose the indexes for the integration (i.e. :
Code:
R1I = integrate.nquad(G, [[0,4],[0,2*np.pi]])
becomes
Code:
R1I = integrate.nquad(G, [[0,2*np.pi],[0,4]])
I still get the same result. That doesn't seem right...
Any help with regards to where I am going wrong and advice would be greatly appreciated!
Attachments
Last edited: