I want to create a matrix with each element updated as per the formula, whose inputs are dependent on the location of element in the matrix.
Zphat[t] = ConstantArray[0, {4, 2, 2}]
The assignment is done using this:
For[i = 1, i < 5, i++, For [j = 1, j < 3, j++ , For [n = 1, n < 3, n++, For[k = 1, k < 5, k++, Zphat[t][[1, j, n]] = Zphat[t][[i, j, n] + D[zdot[t][i,j], {q[t][[1, k]], 1}]*smat[t][[k, n]]]]]]
I have checked the matrix dimensions used. zdot and smat are the appropriate matrices derived earlier.
Error message: Set::setps: Zphat[t] in the part assignment is not a symbol.
For
is going to make your life much, much worse. In fact using procedural code in Mathematica will just generally be slow and more work than using the built in functional constructs. There's a very good Q/A here on good alternatives toFor
. $\endgroup$