- #1
uzi kiko
- 22
- 3
In my job, I was given the task of calculating a force that operates an ultrasound transmitter on a receiver. The calculation is made by assuming that each point on the transmitter is a small transmitter and integration should be made on the surface of the transmitter.
Since the transmitter is disc-shaped, it would seem natural to use polar coordinates. But the results I obtained were not relatively accurate compared to the analytical results.
I enclose here a simple Peyton code that compares numeric integration on a unit-sized disk (the area is pi), by a summation of rings, in polar coordinates, and in Cartesian coordinates.
The script results:
rings= [3.1415926535897114, 2000]
polar= [3.143163449916506, 4002000]
cartzian=[3.141529000085212, 4000000]
pi= 3.141592653589793
It can be easily seen that in the calculation in polar coordinates the error is already in the third digit after the dot. To reach the same level of accuracy of the Cartesian coordinates, I need to reduce the resolution to almost 1000 times (which makes the calculation impractical in a commercial system).
Does anyone recognize where my mistake is in calculating the area in polar coordinates?
Since the transmitter is disc-shaped, it would seem natural to use polar coordinates. But the results I obtained were not relatively accurate compared to the analytical results.
I enclose here a simple Peyton code that compares numeric integration on a unit-sized disk (the area is pi), by a summation of rings, in polar coordinates, and in Cartesian coordinates.
The script results:
rings= [3.1415926535897114, 2000]
polar= [3.143163449916506, 4002000]
cartzian=[3.141529000085212, 4000000]
pi= 3.141592653589793
Python:
import numpy as np
import math
# rings
dr = 1.0/2000.0
dang = 2*np.pi/2000.0
radius = 1s=0
r=dr
i=0
while (r<radius):
ang=0
ring = 0
s += np.pi * (2*r*dr -dr*dr)
r+=dr
i+=1
print("rings= " + str([s, i]))# polar
s=0
r=dr
i=0
while (r<radius):
ang = 0
dang_ = dang
while (ang<2*np.pi):
i+=1
ang+=dang_
#ang -= (np.random.rand() - 0.5) * dang * 2;
factor = 2*np.pi/ang
ang *= factor
s += ang * r * dr
r+=dr
print("polar= " + str([s, i]))
# cartesian
dx = 1.0/1000.0
x=-1
y=-1
s1 = 0
i=0
while (x<1):
y= -1
while (y<1):
if math.sqrt(x**2+y**2)<=radius:
s1+=dx*dx
y+=dx
i+=1
x+=dx
print("cartzian=" + str([s1,i]))
print("pi= " + str(np.pi))
Does anyone recognize where my mistake is in calculating the area in polar coordinates?