1
$\begingroup$

I am working a problem involving colliding particles. I define a list of particle diameters (effectively a bin distribution). I need to know if two particles collide, in what bin diameter should I place the resulting combination?

To do this, I define the bin diameters, and derive the associated volume (a 1D list). The permutations of the combination are then defined as a 2D list, (where the ij element is the combined volume of the ith and jth element of the reference list). I'd thought to then use Nearest to determine the correct volume bin, and then backtrack to the diameter bin. I think I'm close to the right syntax, but I'm getting extra () in the output. How can I get rid of those? I tried Flatten, but I didn't see a change (which tells me I'm probably using it incorrectly).

Bins = {0.523, 0.542, 0.583, 0.626, 0.673, 0.723, 0.777, 0.835, 0.898,
 0.965, 1.037, 1.114, 1.197, 1.286, 1.382, 1.486, 1.596, 1.715, 
1.843, 1.981, 2.129, 2.288, 2.458, 2.642, 2.839, 3.051, 3.278, 
3.523, 3.786, 4.068, 4.371, 4.698, 5.048, 5.425, 5.829, 6.264, 
6.732, 7.234, 7.774, 8.354, 8.977, 9.647, 10.37, 11.14, 11.97, 
12.86, 13.82, 14.86, 15.96, 17.15, 18.43, 19.81}*10^-6;
BinVolume = (4/3)*Pi*Bins^3; 
CombinedVolume = Table[BinVolume[[i]] + BinVolume[[j]], {i, 52}, {j, 52}]; 
TestOutput=MatrixForm[Table[Nearest[BinVolume, CombinedVolume[[i, j]]], {i, 52}, {j, 52}]]

Thanks!

$\endgroup$
  • 2
    $\begingroup$ Try MatrixForm[ Flatten /@ Table[Nearest[BinVolume, CombinedVolume[[i, j]]], {i, 52}, {j, 52}]] or Table[First@Nearest[BinVolume, CombinedVolume[[i, j]]], {i, 52}, {j, 52}] $\endgroup$ – Karsten 7. Mar 17 '15 at 3:33
  • $\begingroup$ Thanks! So if I'm interpreting the code correctly /@ is shorthand for the Map function, which means I'm telling Mm to Flatten each individual entry in the table; thus removing the braces. I think the second variation (First@Nearest) does the same sort of thing, but instead of removing the braces, it's using the table-of-tables thing I was creating. First would pull the first entry of each subtable, so instead of having a table-of-tables, I wind up with a table-of-first-entries-of-a-table? $\endgroup$ – Gordon Smith Mar 17 '15 at 16:58
  • $\begingroup$ Exactly. You've got it. $\endgroup$ – Karsten 7. Mar 17 '15 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.