New answers tagged

3

The reason you end up in an infinite loop is that you are reusing i as iteration variable. After executing vectorBasis[perm], arrayToVec has set i to $2$. Therefore, every time the condition i <= Length[vectorBasis[perm]] is checked, i is reset to $2$, and the condition will always be satisfied. An easy fix would be to make i in arrayToVec a local ...


0

I didn't install the specified packages you mentioned but by replacing vectorBasis with DiagonalMatrix I could produce the exact result: perm = {2, 3, 4} (*Out: {2, 3, 4} *) DiagonalMatrix[{1, 1, 1}] (*Out: {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}} *) Length[DiagonalMatrix[{1, 1, 1}]] (*Out: 3 *) Finally: For[i = 1, i <= Length[DiagonalMatrix[{1, 1, 1}]], i++, ...


Top 50 recent answers are included