# Creating matrices using a Do-loop

Here is an image of current assignment; I am not able to do step 6 to 8

When I try to do the Do-loop, it states that the {i, j} does not have appropriate bounds.

This is what I did for step 6:

Do[i + j = figueroaMat[[i, j]], {i > j}, {i, 0, 9}, {j, 0, 9}]


My question is about how to do step 6 to step 8.

• Please do not post images of your work, especially when the images display at a size that make them difficult to read. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. Without such, it will be difficult to reproduce your problem and to experiment with possible solutions. – m_goldberg Feb 18 at 0:20
• Step 1: IdentityMatrix[10] Step 2: IdentityMatrix[10] // MatrixForm Step 3: figueroaMat = IdentityMatrix[10] Step 4: figueroaMat[[1, 1]] figueroaMat[[9, 9]] figueroaMat[[4, 5]] Step 5: when I executed step 4, my outputs were 1,1 and 0. Step 5 states that figueroaMat[[i,j]] repsent the (i,j) entry of the matrix figueroaMat – Laura Figueroa Feb 18 at 0:37
• Step 6: By using the Do loop, assign i+j to (i,j) entry of figueroaMat if i>j. Then execute figueroaMat//Matrix form. Do[i + j = figueroaMat[[i, j]], {i > j}] figueroaMat // MatrixForm Step 7: By using the Do loop, assign 0 to (i,j) entry of figueroaMat if i=j. Then execute figueroaMat//Matrix form. Do[0 = figueroaMat[[i, j]], {i = j}] figueroaMat // MatrixForm – Laura Figueroa Feb 18 at 0:41
• Step 8: By using the Do loop, assign i-j to (i,j) entry of figueroaMat if i<j. Then execute figueroaMat//Matrix form.Do[figueroaMat[[i, j]] = i - j, {i < j}] figueroaMat // MatrixForm – Laura Figueroa Feb 18 at 0:41
• Alternative: SparseArray[{{i_, j_} /; i < j :> i + j, {i_, i_} :> 0, {i_, j_} /; i > j :> i - j}, {10, 10}] // MatrixForm. You could also use Table to generate the array instead of using IdentityMatrix merely to pre-allocate an array that you then overwrite with a Do[] loop. – Michael E2 Feb 18 at 0:41

Step 6 is done by testing for i > j with If at each iteration of the loop. Also, figueroaMat must on the lefthand side of the assignment experssion. Like so:
 If[i > j, figueroaMat[[i, j]] = i + j]

• In your Do loop replace i + j = figueroaMat[[i, j]], {i > j} by If[i > j, figueroaMat[[i, j]] = i + j] and index, i.e, i and j should start from 1 – OkkesDulgerci Feb 18 at 3:13