Table of euclidean distances...

*To*: mathgroup at smc.vnet.net*Subject*: [mg7921] Table of euclidean distances...*From*: "Joel Bock" <jbock at INETWORLD.NET>*Date*: Mon, 21 Jul 1997 03:22:11 -0400*Sender*: owner-wri-mathgroup at wolfram.com

Hello MathGroup: I'm trying to create a table of euclidean distances between coordinates of source and field points in 3-space for an acoustics simulation. What I have done is both grossly brute-force and interminably long-running for large numbers of points. There has to be a better way! Can anyone suggest a better way to do this calculation, say, operating on vectors of points as opposed to one element at a time? Given two tables, "src" and "fld", comprised of elements that each have three Cartesian coordinates: e.g., src[[i]] = { x[[i]], y[[i]], z[[i] }, etc. Then the distance function is eucDist[x1_,x2_]:=Sqrt[ (x1[[1]]-x2[[1]])^2 + (x1[[2]]-x2[[2]])^2 + (x1[[3]]-x2[[3]])^2 ]; and the calculation of the table of distances is R=Table[ eucDist[ src[[i]], fld[[j]] ], {i,nSrc}, {j,nFld} ]; This works, but is inefficient. For scatterers placed in the radiation field of the sources, things grind to a halt, as the scatterers have finite physical dimension and therefore require 2 subscripts- one index for scatterer ID, and the other for each "face" created to discretize the surface. I am observing the familiar "swapping orgy" phenomenon running this on a 486DX2 with 16 MB memory. Buying a new computer is not an option for me at present... Any suggestions or example notebooks to speed this type of calculation up would be very welcome. Thanks!