Professional Documents
Culture Documents
Usually we are interested in some output signal that comes out of a system. In N-body problems
interaction between many bodies is calculated
E ( x, y ) = Q(r ) / r 2 dr
r = ( x u ) 2 + ( y v) 2
(u, v)
E ( x, y ) = Q(rij ) / rij
i
rij = ( x ui ) 2 + ( y v j ) 2
(ui , v j )
E ( x, y ) = Q(rij ) / rij
i
rij = ( x ui ) + ( y v j ) 2
2
i.
Select a radius R around each particle as shown in the figure for the first particle, so that there will be m
particle inside the circle and N-m outside the circle
ii.
Calculate effect of only those particles that are inside the circle on the selected particle (see diagram). This
will require m-1 calculation
iii. Now do the steps i and ii for all particles total N*(m-1). Obviously if R is so large that it contains all the
particles then it will be N2-N calculations
Important point is that the size of radius R will determine m hence number of calculations, as
well as the accuracy of the resultant calculation
2. Exact Methods
a. Use Fast Fourier Transform (FFT) to get Order(N Log N) Calculations
Consider the case of N charges distributed evenly in n dimensions. The position of each charge
can be denoted by and n dimensional vector xk and charge qk then electric field E at a position
Vector x is
N
q
E ( x ) = k ; d k = x xk
k =1 d k
Compare above equation for E with the following equation for a discrete convolution
1
g k w there calculation of field at each point is also a convolution
X Xk
Before taking the DFT the discrete vector of size N is padded with N zeroes
k w; qk f w ;
Algorithm
Given: N point charges uniformaly distributed
1.
2.
Vector q = q = {q0, q1,, qN-1) representing charge values of the given point charges
Position Vectors x = {x0, x1,, xN-1) representing position of the given point charges
Step 1: Add N zeroes to vector q = {q0, q1,, qN-1) to get vector q = {q0, q1,, qN-1,0,0,.0} of
size 2N
Step 2: Calculate Vector z = 1/|x| = { 1/|x0|, |x1|,, |xN-1|}and Add N zeroes to vector z to get
vector z = {z0, z1,, zN-1,0,0,.0} of size 2N
Step 3: Take Discrete Fourier Transform (DFT) of the vector q = {q0, q1,, qN-1,0,0,0}
DFT(q) = Q = {Q0 , Q1 ,.., Q2 N 1}
Qw =
2 N 1
qk e
i 2 w k
2N
k =0
Step 4: Take Discrete Fourier Transform (DFT) of the vector z = {z0, z1,, zN-1,0,0,0}
DFT(z) = Z = {Z 0 , Z1 ,.., Z 2 N 1}
Zw =
2 N 1
z e
k =0
i 2 w k
2N
h = {h0 , h1 ,.., h2 N 1}
InverseDFT ( H w ) = hk =
2 N 1
H we
i 2 w k
2N
w=0
X u = xk e
i 2
N
u k
set
k =0
N 1
X u = xk W
k =0
M 1
yW
=
k =0
ku
M
WN = e
M 1
+W
u 2k
2M
k =0
i = 1
M 1
= x2 kW
uk
N
i 2
N
+ x2 k +1W2uM( 2 k +1)
k =0
M 1
z W
u
M
k =0
ku
M where we denote the points with even indices with vector
y = {y0, y1, yM-1}where yi = x2k and points with odd indices with vector
z ={z0, z1, zM-1}where zi = x2k+1, and
i 2 2
i 2
2
N
N /2
N
N /2
W =e
=e
=W
M 1
yW
Actually
k =0
M 1
ku
M is DFT of vector y and
z W
k =0
ku
M is DFT of vector z
X u = Yu + W Z u . but Y and Z has only N/2 values whereas X needs N values therefore
u
M
For u = 0, 1, M
X u = Yu + WMu Z u . and
For u = M,M+1,..2M-1
Because
And
Eq. 1
X u = Yu WMu Z u .
Eq. 2
WMu + M = e
i 2
(u + M )
M
=e
i 2 M
M
.e
i 2
M
= e
i 2
M
= WMu
Conclusion: Any N point DFT can be done using 2 (even and odd) N/2
point DFTs, using Eq. 1 (for first N/2 points) and Eq. 2 (for rest of N/2
points)
Example
Let x = {x0, x1,x2,x3} and X = DFT(x) = {X0,X1,X2,X3} is needed
Step 1: Divide x in 2 part using even and odd indices
x = a,b where a = {x0,x2} and b = {x1,x3} and DFT of a is A = {A0, A1} and of b is B =
{B0,B1}
Step 2: further split a and b in even and odd indices
a = c, d where c ={x0},d = {x2} and b = e, f where e = {x1}, f = {x3}
Step 3: C = DFT(c) = x0; D = DFT(d) = x2; E = DFT(e) = x1 and F = DFT(f) = x3
Step 4: now calculate the DFT(a) = A = {A0,A1} and DFT(b) = {B0,B1}
Where A is calculated using C and D
A0 = C0 + W02*D0 = x0 + x2
A1 = C0 W02*D0 = x0 - x2
Similarly using E and F
B0 = E0 + W02*F0 = x1 + x3
B1 = E0 W12*F0 = x1 - x3
Step 5: Now we can apply Eq. 1 and 2 for N = 4 because we have 2 DFTs (A and B) of N/2 = 2
points each
X0 = A0 + W04B0
X1 = A1 + W14B1
X2 = A0 W04B0
X3 = A1 W14B0
Example: x = {0.1, 0.2, 0.3, 0.4}
Step 1: even = {0.1,0.3} and odd = {0.2, 0.4} remember even and odd is by the array indices
Step 2:
even_even = {0.1}; even_odd = {0.3}
odd_even = {0.2}; odd_odd = {0.4}
Step 3:
DFT(even_even) = 0.1 and DFT(even_odd) = 0.3
DFT(odd_even) = 0.2 and DFT(odd_odd) = 0.4
Step 4:
DFT({0.1, 0.3}) = {A0, A1} and DFT({0.2, 0.4}) = {B0, B1}
8 Point DFT
F0 = A0 + W
x0
x0
A0 = x 0 + W
x1
x2
A1 = x0 W * x 2
x2
x4
x3
x6
x4
x1
C0 = x1 + W
x5
x3
C1 = x1 W * x3
G1 = C1 + W * D1
x6
x5
D0 = x5 + W2
* x7
G2 = C 0 W4
* D0
x7
x7
D1 = x5 W2
* x7
G3 = C1 W4
* D1
WNk = e
* x2
0
2
0
4
* B0
F1 = A1 + W * B1
1
4
B0 =
x 4 + W * x6
F2 = A0 W * B 0
B1 =
x 4 W * x6
F3 = A1 W
0
2
0
2
0
2
* x3
0
2
j 2k
N
X0 = F 0 + W8
0
2
and X = DFT(x)
0
4
1
4
X1 = F1 + W8 * G1
1
X2 = F 2 + W8 * G 2
2
X3 = F 3 + W8
* G3
X4 = F 0 W8
* G0
* B1
G0 = C 0 + W
0
4
* D0
1
4
* G0
X5 = F1 W8 * G1
1
X6 = F 2 + W8
* G2
X7 = F 3 W8
* G3