0

I'm new to programming and scientific computing. Below is some code for evaluating an exponential integral over a grid. The integral is a function of radial distance from a point. I would like to sum the contribution from multiple points (with defined x, y coordinates) over the grid. I realize analytically this is simple superposition, but I'm confused over how to construct the loop summing the contribution from the points and the most efficient approach. If anyone has any suggestions or references, it will be much appreciated. The code setting up the grid and evaluating the function is below:

S=.0004
xi0 = 1.0
dx = 10.0
side = 100.0
points = 500
spacing = side/points
x1 = side/2 + dx/2
y1 = side/2
x2 = side/2 - dx/2
y2 = side/2
xi = empty([points,points],float)
for i in range(points):
y = spacing*i
for j in range(points):
    x = spacing*j
    r1 = sqrt((x-x1)**2+(y-y1)**2)
    r2 = sqrt((x-x2)**2+(y-y2)**2)
    u = (r1*r1*S)
    xi[i,j] = expn(1,u)
Cfree
  • 57
  • 1
  • 6

1 Answers1

1

Maybe something like this can be appropriate

x = np.linspace(0, side, points)
y = np.linspace(0, side, points)
r1 = np.sqrt((x-x1)**2 + (y-y1)**2)
r2 = np.sqrt((x-x2)**2 + (y-y2)**2)
u = (r1 * r2 * s)
xi = np.exp(u)
erthalion
  • 3,094
  • 2
  • 21
  • 28