1
$\begingroup$

Even after, not only seeing, but understanding on Mathematica SE and also using Table. I am afraid, if I still understand it.

Here is one example, which I couldn't understand. I am using Table to display a matrix subject to the condition as mentioned below:

In[257]:= 
res1 = Table[KroneckerDelta[j - (1 + i)], {j, 0, 10}, {i, 0, 10}];

MatrixForm[res1]

This is the output:

\begin{array}{ccccccccccc} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{array} Which I couldn't understand is, KroneckerDelta[j-(1 + i)] is a constrain. Now as per Table definition(where @WReach has used to display matrix with indices, to show the working of Table). First, j should run for every fix value of i i.e. j should run from 0 to 10 for each value of i and keep on untill i=i_max, analogous to Do loop first of j then of i. By making use of, all of this, assuming i = 0 to begin with, so KroneckerDelta[j-(1 + 0)] = KroneckerDelta[j-1]. Which means a value( i.e. 1) at position (0,1), instead I am getting at (1,0). Are things just the other way round?

Mathematica 11.0.1
Ubuntu16.04

$\endgroup$
  • 2
    $\begingroup$ Does this help? res1 = Table[ToString[{i, j}], {j, 0, 10}, {i, 0, 10}]; MatrixForm[res1] $\endgroup$ – Nicholas G Feb 9 '17 at 16:32
  • 3
    $\begingroup$ I don't see how the working of Table can be made more clear than e.g. Table[Row[{"(i=", i, "; j=", j, ")"}], {j, 0, 10}, {i, 0, 10}] // MatrixForm. $\endgroup$ – Mr.Wizard Feb 9 '17 at 16:33
  • $\begingroup$ @NicholasG Thanks for this. I got it. $\endgroup$ – L.K. Feb 9 '17 at 16:37
  • $\begingroup$ @Mr.Wizard Thanks to you also. Now I see the things are other way round first all the rows increment then the columns, unlike the Do loop $\endgroup$ – L.K. Feb 9 '17 at 16:45
  • 1
    $\begingroup$ iterator handling in Table and Do is exactly the same. Of course there is no sense of rows and columns in a Do loop. $\endgroup$ – george2079 Feb 9 '17 at 17:38