You've got an error in your for
loop. j
goes from 0
to 2
, so j+1
can take the value 3
, which is an invalid index for the matrix (it is a 3x3 matrix, not a 4x4 one). Hence the "invalid index" out-of-bounds access error.
Your outer for
loop will cause an out-of-bounds access error too, even if you fix this, because i
goes from 1
to 3
.
If you weren't aware of that, matrices (and vectors) in Mathcad are indexed beginning with 0
, just like in any other programming language. So, the valid indexes for your matrix are from 0
to 2
inclusive in both dimensions.