# How to create a general format of a matrix with specified entries?

I want to create a PNG picture of a matrix where its entries are the following:

n,   n-1,   ..., 1,
2n,  2n-1,  ..., n+1,
3n,  3n-1,  ..., 2n+1,
...
n^2, n^2-1, ..., (n-1)n+1


For example, I was thinking something like the picture below (including the dots) I have tried to use the command mat = {{1, 2}, {3, 4}} but it does not accept {...} as the three dots.

I would really appreciate any suggestions/hints on how to do this.

UPDATE: I have created using the following code

MatrixForm[{{n, -1 + n, -2 + n, \[CenterEllipsis], 1}, {2 n, 2 n - 1,
2 n - 2, \[CenterEllipsis], n + 1}, {3 n, 3 n - 1,
3 n - 2, \[CenterEllipsis],
2 n + 1}, {\[VerticalEllipsis], \[VerticalEllipsis], \\[VerticalEllipsis], \[DescendingEllipsis], \[VerticalEllipsis]}, \{n^2, -1 + n^2, -2 + n^2, \[CenterEllipsis],     HoldForm[(n - 1) n + 1]}}, TableAlignments -> Right] // TraditionalForm


this matrix Thank you very much for your help.

• Try reading the docs for Table[ ] and then for MatrixForm[ ] – Dr. belisarius Nov 5 '15 at 13:42
• @belisariusisforth Thanks, but how one creates the dots in a matrix? – johnny09 Nov 5 '15 at 13:48
• What's a "pgn picture"? Do you mean a PNG image? – m_goldberg Nov 5 '15 at 13:56
• @m_goldberg Yes, sorry. Small typo, I have corrected it now. – johnny09 Nov 5 '15 at 13:58

You can just type it in. Like so The various forms of ellipses are found on the Special Characters palette under the § tab of the Symbols tab. This palette is available from the Palettes menu.

You can get a PNG by selecting the output cell and choosing Save Selection As... from the File Menu (as I did for this post).

• Thanks so much. I didn't know there were any special characters. :) – johnny09 Nov 5 '15 at 14:19

Here's a approach that uses the fact that the various directed dots are spelled SpanFromLeft, SpanFromAbove, and SpanFromBoth.

{hdots, vdots, ddots} =
ToString[#, StandardForm] & /@ {SpanFromLeft, SpanFromAbove, SpanFromBoth};


Here's a function that will replace everything but the upper left $2 \times 2$ block and the last row and column with dots

insertDots[matrix_?MatrixQ] :=
With[{dims = Dimensions@matrix, size = 3},
With[{rows = dims[], cols = dims[]},
With[{dropped =
Map[Drop[#, {3, -2}] &, Drop[matrix, {3, -2}]]},
Insert[
Insert[dropped, hdots, {#, size} & /@ Range@size],
Insert[ConstantArray[vdots, size], ddots, size], size] /;
AllTrue[dims, size <= # &]]]];


We can use it like so:

array = Outer[Subscript[a, ##] &, Append[Range, m], Append[Range, n]];

MatrixForm[insertDots@array] • Nice :). I rewrote my answer using yours :) – Dr. belisarius Nov 5 '15 at 14:40

Edit: Code modified to use @Pillsy's SpanFrom... trick instead of Graphics

shortm[m1_] := Module[{m, s = ConstantArray[ToString[#, StandardForm], 4] &},
m = Drop[m1, {4, Length@m1 - 1}, {4, Length@m1 - 1}];
m[[All, 3]] = s@SpanFromLeft;
m[[3, All]] = s@SpanFromAbove;
m[[3, 3]]   = SpanFromBoth;
m]


Then use it as follows:

f[n_] := Table[n i - j + 1, {i, n}, {j, n}]
MatrixForm@shortm@f MatrixForm@shortm@f Previous code using Graphics[ ]

shortm[m1_] := Module[{m, g},
m = Drop[m1, {4, Length@m1 - 1}, {4, Length@m1 - 1}];
g = Graphics[{PointSize[Small], Point[{{-1, 0}, {0, 0}, {1, 0}}]},
PlotRange -> 2 {{-1, 1}, {-1, 1}}, ImageSize -> 20];
m[[All, 3]] = ConstantArray[g, 4 ];
m[[3, All]] = ConstantArray[Rotate[g, Pi/2], 4 ];
m[[3, 3]]   = Rotate[g, -Pi/4];
m]

• the original graphics approach was a good alternative in case you want to avoid special character font issues. – george2079 Nov 5 '15 at 15:00
• @george2079 True. I re-added at the end – Dr. belisarius Nov 5 '15 at 15:04