2

I have a 15x15 matrix which is large and impractical to format. All the elements except the main diagonal and the one under that diagonal is zero. How to format it correctly? Like I want to use two vectors instead.

Here is the matrix.

\begin{bmatrix}
1.4142 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
-0.7071 & 1.2247 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & -0.8165 & 1.1547 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & -0.8660 & 1.1180 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & -0.8944 & 1.0954 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & -0.9129 & 1.0801 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & -0.9258 & 1.0690 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & -0.9354 & 1.0607 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & -0.9428 & 1.0541 & 0 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -0.9487 & 1.0488 & 0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -0.9535 & 1.0445 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -0.9574 & 1.0408 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -0.9608 & 1.0377 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -0.9636 & 1.0351 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & -0.9661 & 1.0328\\
\end{bmatrix}
Juan Castaño
  • 28,426
Bepo-san
  • 29
  • 1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 21 '23 at 11:09

1 Answers1

3

You can use a vector-like expression by making a list (using the listofitems package) and then retrieving the elements individually.

The list are created using the \readlist command.

The list is comma separated and the elements are recovered using the notation

\ListName[<order of the element>]

For convenience, two lists of 15 items were defined for this example. (Makes it easier to write the rows)

a

As a refinement, you can replace multiple zeros with a large zero.

b

\documentclass[11pt, landscape]{article}

\usepackage[left=2.00cm]{geometry}

\usepackage{listofitems}% added <<< \usepackage{amsmath}% added <<< \setcounter{MaxMatrixCols}{15}% more columns allowed

\begin{document}

\small

\readlist\DA{1.4142, 1.2247, 1.1547, 1.1180, 1.0954, 1.0801, 1.0690, 1.0607, 1.0541, 1.0488, 1.0445, 1.0408, 1.0377, 1.0351, 1.0328} % 15 elements \readlist\DB{0, -0.7071, -0.8165, -0.8660, -0.8944, -0.9129, -0.9258, -0.9354, -0.9428, -0.9487, -0.9535, -0.9574, -0.9608, -0.9636, -0.9661}% 15 elements

$\begin{bmatrix} \DA[1] & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ \DB[2] & \DA[2] & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\ 0 & \DB[3] & \DA[3] & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\ 0 & 0 & \DB[4] & \DA[4] & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\ 0 & 0 & 0 &\DB[5]& \DA[5] & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\ 0 & 0 & 0 & 0 & \DB[6] & \DA[6] & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\ 0 & 0 & 0 & 0 & 0 & \DB[7] & \DA[7] & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\ 0 & 0 & 0 & 0 & 0 & 0 & \DB[8] & \DA[8] & 0 & 0 & 0 & 0 & 0 & 0 & 0\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & \DB[9] & \DA[9] & 0 & 0 & 0 & 0 & 0 & 0\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \DB[10]& \DA[10] & 0 & 0 & 0 & 0 & 0\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \DB[11] & \DA[11] & 0 & 0 & 0 & 0\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \DB[12] & \DA[12] & 0 & 0 & 0\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \DB[13] & \DA[13] & 0 & 0\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \DB[14] & \DA[14] & 0\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \DB[15] &\DA[15] \end{bmatrix}$

\newpage

$\begin{bmatrix} \DA[1] &&&&&&&&&&&&&&\ \DB[2] & \DA[2] &&&&&&&&&&&&& \ & \DB[3] & \DA[3] &&&&&&&&&&&&\ && \DB[4] & \DA[4] &&&&&&&&&&&\ &&&\DB[5]& \DA[5] &&&&&\makebox(0,0){\text{\Huge0}}&&&&&\ &&&& \DB[6] & \DA[6] &&&&&&&&&\ &&&&& \DB[7] & \DA[7] &&&&&&&&\ &&&&&& \DB[8] & \DA[8] &&&&&&&\ &&&&&&& \DB[9] & \DA[9] &&&&&&\ &&&&&&&& \DB[10]& \DA[10] &&&&&\ &&&&&&&&& \DB[11] & \DA[11] &&&&\ &&&\makebox(0,0){\text{\Huge0}}&&&&&&& \DB[12] & \DA[12] &&&\ &&&&&&&&&&& \DB[13] & \DA[13] &&\ &&&&&&&&&&&& \DB[14] & \DA[14] &\ &&&&&&&&&&&&& \DB[15] &\DA[15] \end{bmatrix}$

\end{document}

The final example shows the pmatrix using the nicematrix package and using horizontal, vertical and diagonal dotted lines: \Cdots, \Vdots and \Ddots. (It will compile twice)

c

\documentclass[11pt, landscape]{article}

\usepackage[left=2.00cm]{geometry}

\usepackage{listofitems}% added <<<<< \usepackage{nicematrix}% added <<<<< \setcounter{MaxMatrixCols}{15}% more columns allowed

\begin{document}

\small

\readlist\DA{1.4142, 1.2247, 1.1547, 1.1180, 1.0954, 1.0801, 1.0690, 1.0607, 1.0541, 1.0488, 1.0445, 1.0408, 1.0377, 1.0351, 1.0328} % 15 elements \readlist\DB{0, -0.7071, -0.8165, -0.8660, -0.8944, -0.9129, -0.9258, -0.9354, -0.9428, -0.9487, -0.9535, -0.9574, -0.9608, -0.9636, -0.9661}% 15 elements

$\setlength{\extrarowheight}{0.5ex} % expand the rows \begin{bNiceMatrix}[xdots/shorten=1em] % make line dots with shorter length \DA[1] & 0 & \Cdots & & & & & & & & & & & & 0 \ \DB[2] &\DA[2] & \Ddots & & & & & & & & & & & & \Vdots\ 0 & \DB[3] &\DA[3] & & & & & & & & & & & & \ \Vdots & \Ddots & \DB[4]& \DA[4] & & & & & & & & & & & \ & & & \DB[5] &\DA[5] & & & & & & & & & & \ & & & & \DB[6] & \DA[6] & & & & & & & & & \ & & & & & \DB[7] &\DA[7] & & & & & & & & \ & & & & & & \DB[8] & \DA[8] & & & & & & & \ & & & & & & & \DB[9] &\DA[9] & & & & & & \ & & & & & & & & \DB[10] & \DA[10] & & & & & \ & & & & & & & & & \DB[11] &\DA[11] & & & & \ & & & & & & & & & & \DB[12] & \DA[12] & & & \ & & & & & & & & & & & \DB[13] &\DA[13] & & \ & & & & & & & & & & & & \DB[14] & \DA[14] & 0\ 0 & \Cdots & & & & & & & & & & & 0 & \DB[15] &\DA[15] \end{bNiceMatrix}$

\end{document}

Note. The elements of the lists created here has, for clarity, a leading space, which is irrelevant in a tabular environment. To suppress such space use \readlist*.

Simon Dispa
  • 39,141