3
$\begingroup$

Is there a more elegant way of dealing with the following subscripting?

Do[threetest = 
MatrixRank[{{threepoints[[i]][[2]][[1]] - 
threepoints[[i]][[1]][[1]], 
threepoints[[i]][[2]][[2]] - threepoints[[i]][[1]][[2]]},
{threepoints[[i]][[3]][[1]] - threepoints[[i]][[1]][[1]],
threepoints[[i]][[3]][[2]] - threepoints[[i]][[1]][[2]]}}]; 
If[threetest < 2, Break[], 1], {i, Binomial[n, 3]}]
$\endgroup$

closed as off-topic by Roman, Henrik Schumacher, m_goldberg, happy fish, Alex Trounev Apr 27 at 12:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Roman, Henrik Schumacher, m_goldberg, happy fish, Alex Trounev
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ If the last dimension of threePoints is two, then you might try something like MatrixRank[threepoints[[i, 2 ;; 3]] - threepoints[[i, 1]]]. $\endgroup$ – WReach Apr 26 at 18:29
10
$\begingroup$

If threepoints is defined with any kind of regularity, then threepoints[[i]][[2]][[1]] is the same as threepoints[[i,2,1]]. See the documentation of Part.

Further, you can do vector processing with ;;, along the lines of

Do[threetest = 
  MatrixRank[{threepoints[[i, 2, 1 ;; 2]] - threepoints[[i, 1, 1 ;; 2]], 
              threepoints[[i, 3, 1 ;; 2]] - threepoints[[i, 1, 1 ;; 2]]}]; 
  If[threetest < 2, Break[], 1],
  {i, Binomial[n, 3]}]

If the third coordinate of threetest has only two slots (that is, if Dimensions[threetest] returns {something,something,2}), then the above can also be written as

Do[threetest = 
  MatrixRank[{threepoints[[i, 2]] - threepoints[[i, 1]], 
              threepoints[[i, 3]] - threepoints[[i, 1]]}]; 
  If[threetest < 2, Break[], 1],
  {i, Binomial[n, 3]}]
$\endgroup$
6
$\begingroup$

The other thing I do is to use the stylized brackets in all of my MMA code. Stackexchange mangles it, so have to use a picture to demonstrate:

enter image description here

Big difference in readability.

$\endgroup$
  • $\begingroup$ Also, you can put them in the subscript and they work equally. And if it's still not enough, you can use the invisible comma to separate indices. ;-) $\endgroup$ – Veky Apr 27 at 3:53
  • $\begingroup$ It’s probably worth adding how to enter these doubled brackets using the keyboard: Esc–[–[–Esc. $\endgroup$ – Stephen Powell Apr 27 at 9:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.