0
$\begingroup$

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

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – m_goldberg Feb 18 at 0:20
  • $\begingroup$ 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 $\endgroup$ – Laura Figueroa Feb 18 at 0:37
  • $\begingroup$ 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 $\endgroup$ – Laura Figueroa Feb 18 at 0:41
  • $\begingroup$ 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 $\endgroup$ – Laura Figueroa Feb 18 at 0:41
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Feb 18 at 0:41
3
$\begingroup$

Since this is homework, I won't give a complete solution, but here is a strong hint on how to proceed.

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]

For 7 and 8, just change the test.

$\endgroup$
  • $\begingroup$ Can I use Do[] instead of If[]? When I do If[] the way that you stated, I get a matrix 1[0,-1,-2,-3,-4, so on, which is not correct. I tried to do Do[i > j, figueroaMat[[i, j]] = i + j] =. The output tells me that the expression j cannot be used as a part of specification and Do: non-list iterator figueroaMatt[i,j]=i+j at position 2 does not evaluate to a real numeric value. $\endgroup$ – Laura Figueroa Feb 18 at 1:33
  • $\begingroup$ 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 $\endgroup$ – OkkesDulgerci Feb 18 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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