8

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)

enter image description here

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

enter image description here

Thank you very much for your help.

johnny09
  • 395
  • 2
  • 13

3 Answers3

11

You can just type it in. Like so

example

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).

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
9

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[[1]], cols = dims[[2]]},
    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[3], m], Append[Range[5], n]];

MatrixForm[insertDots@array]

matrix with dots

Pillsy
  • 18,498
  • 2
  • 46
  • 92
8

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[5]

Mathematica graphics

MatrixForm@shortm@f[10]  

Mathematica graphics


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]
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453