Re: Distance between residues
- To: mathgroup at smc.vnet.net
- Subject: [mg41321] Re: [mg41288] Distance between residues
- From: Bobby Treat <drmajorbob at mailblocks.com>
- Date: Wed, 14 May 2003 08:18:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
If you mean to calculate distances between rows of a matrix, this works. (The first two lines are only for making examples.) f = Which[3# < 1, a, 3# < 2, b, True, c] &; m = Table[f@Random[], {3}, {2}] distance[(x_)?VectorQ, (y_)?VectorQ] := (Sqrt[#1.#1] &)[x - y] Outer[distance, m, m, 1] If you mean that the matrix elements are themselves vectors, almost the same thing works. (The first line builds an example matrix.) m = Table[f@Random[], {3}, {4}, {2}]; Outer[distance, m, m, 2] Dimensions@% This result has a structure you may or not find useful, but it's a consequence of the structure of m. Flatten[%,k] may help for k = 1, 2, or 3 -- depending on what you want this to look like. Bobby -----Original Message----- From: rchoy at ula.ve To: mathgroup at smc.vnet.net Subject: [mg41321] [mg41288] Distance between residues Hi, I'm trying to calculate the euclidean distances between elements of a matrix, for example: d=Sqrt[(x[i]-x[j])^2+(y[i]-y[j])^2], (and i is the element [[1,1]] and j is the element [[1,2]], as an example). Also the code in Mathematica (that i have) would be: d=Sqrt[(m[[i,1]]+m[[k,1]])^2+(m[[i,2]]+m[[k,2]])^2]. I have tried with Do, For, Table and While, but I haven't been able to do this (in a iterative way), any ideas? Thanks a lot, Rebeca