[Tex/LaTex] Creating a Big Matrix

matricestabu

I need to create this

enter image description here

but I have no idea how because I'm just a beginner.

\usepackage{tabu}   
\begin{document}                                                                                                              \[{\tiny \left(
\tabulinestyle{on 4pt off 4pt}
\begin{tabu}{cccc|cccc|cccc}
 d_{1,1} & -AX_{1+\frac{1}{2},1} & 0 & 0 & -AY_{1,1-\frac{1}{2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
-AX_{1+\frac{1}{2},1} & d_{2,1} & -AX_{2+\frac{1}{2},1} & 0 & 0 & -AY_{2,1-\frac{1}{2}} & 0 & 0 & 0 & 0 & 0 & 0 \\
 0 & -AX_{2+\frac{1}{2},1} & d_{3,1} & -AX_{3+\frac{1}{2},1} & 0 & 0 & -AY_{3,1-\frac{1}{2}} & 0 & 0 & 0 & 0 & 0 \\
 0 & 0 & -AX_{3+\frac{1}{2},1} & d_{4,1} & 0 & 0 & 0 & -AY_{4,1-\frac{1}{2}} & 0 & 0 & 0 & 0 \\
-AY_{1,1-\frac{1}{2}} &0 & 0 & 0 & d_{1,2} & -AX_{1+\frac{1}{2},2} & 0 & 0 & -AY_{1,2-\frac{1}{2}} & 0 & 0 & 0 \\ \tabucline-

0 & -AY_{2,1-\frac{1}{2}} & 0 & 0 & -AX_{1+\frac{1}{2},2} & d_{2,2} & -AX_{2+\frac{1}{2},2} & 0 & 0 & -AY_{2,2-\frac{1}{2}} & 0 & 0 \\
0 & 0 & -AY_{3,1-\frac{1}{2}} & 0 & 0 & -AX_{2+\frac{1}{2},2} & d_{3,2} & -AX_{3+\frac{1}{2},2} & 0 & 0 & -AY_{3,2-\frac{1}{2}} & 0 \\
0 & 0 & 0 & -AY_{4,1-\frac{1}{2}} & 0 & 0 & -AX_{3+\frac{1}{2},2} & d_{4,2} & 0 & 0 & 0 & -AY_{4,2-\frac{1}{2}} \\ \tabucline-
0 & 0 & 0 & 0 & -AY_{1,2-\frac{1}{2}} & 0 & 0 & 0 & d_{1,3} & -AX_{1+\frac{1}{2},3} & 0 & 0 \\

0 & 0 & 0 & 0 & 0 & -AY_{2,2-\frac{1}{2}} & 0 & 0 & -AX_{1+\frac{1}{2},3} & d_{2,3} & -AX_{2\frac{1}{2},3} & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & -AY_{3,2-\frac{1}{2}} & 0 & 0 & -AX_{2+\frac{1}{2},3} & d_{3,3} & -AX_{3+\frac{1}{2},3} \\ 
0 & 0 & 0 & 0 & 0 & 0 & 0 & - AY_{4,2-\frac{1}{2}} & 0 & 0 & -AX_{3+\frac{1}{2},3} & d_{4,3} 
\end{tabu}\right)
\left( \tabulinestyle{on 1pt off 1pt}
\begin{tabu}{c}
P_{1,1}\\ P_{2,1}\\ P_{3,1}\\ P_{4,1}\\ \tabucline-
P_{1,2}\\ P_{2,2}\\ P_{3,2}\\ P_{4,2}\\ \tabucline-
P_{1,3}\\ P_{2,3}\\ P_{3,3}\\ P_{4,3}\end{tabu}
\right)}
\]

enter image description here

Best Answer

An approach using TikZ, which produces a result which is easier to read, imho:

Matrix

This is the code:

\documentclass[a4paper, landscape]{article}
\usepackage[margin=5mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning,calc}
\begin{document}

\def\linebelowrow#1#2{%
  \pgfmathsetmacro{\nextrow}{int(#2+1)}
  \coordinate (aux) at ($(#1-#2-1.center)!.5!(#1-\nextrow-1.center)$);
  \draw[dashed] (#1.west|-aux) -- (#1.east|-aux);
}
\def\lineaftercolumn#1#2{%
  \pgfmathsetmacro{\nextcol}{int(#2+1)}
  \coordinate (aux) at ($(#1-1-#2.center)!.5!(#1-1-\nextcol.center)$);
  \draw[dashed] (#1.north-|aux) -- (#1.south-|aux);
}
\begin{tikzpicture}
\matrix[matrix of math nodes, left delimiter={[},
        right delimiter={]}, nodes={minimum height=5ex, inner sep=0pt}, row sep=1ex] (M) {
 d_{1,1} & -AX_{1+\frac{1}{2},1} & 0 & 0 & -AY_{1,1-\frac{1}{2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
-AX_{1+\frac{1}{2},1} & d_{2,1} & -AX_{2+\frac{1}{2},1} & 0 & 0 & -AY_{2,1-\frac{1}{2}} & 0 & 0 & 0 & 0 & 0 & 0 \\
 0 & -AX_{2+\frac{1}{2},1} & d_{3,1} & -AX_{3+\frac{1}{2},1} & 0 & 0 & -AY_{3,1-\frac{1}{2}} & 0 & 0 & 0 & 0 & 0 \\
 0 & 0 & -AX_{3+\frac{1}{2},1} & d_{4,1} & 0 & 0 & 0 & -AY_{4,1-\frac{1}{2}} & 0 & 0 & 0 & 0 \\
-AY_{1,1-\frac{1}{2}} &0 & 0 & 0 & d_{1,2} & -AX_{1+\frac{1}{2},2} & 0 & 0 & -AY_{1,2-\frac{1}{2}} & 0 & 0 & 0 \\
0 & -AY_{2,1-\frac{1}{2}} & 0 & 0 & -AX_{1+\frac{1}{2},2} & d_{2,2} & -AX_{2+\frac{1}{2},2} & 0 & 0 & -AY_{2,2-\frac{1}{2}} & 0 & 0 \\
0 & 0 & -AY_{3,1-\frac{1}{2}} & 0 & 0 & -AX_{2+\frac{1}{2},2} & d_{3,2} & -AX_{3+\frac{1}{2},2} & 0 & 0 & -AY_{3,2-\frac{1}{2}} & 0 \\
0 & 0 & 0 & -AY_{4,1-\frac{1}{2}} & 0 & 0 & -AX_{3+\frac{1}{2},2} & d_{4,2} & 0 & 0 & 0 & -AY_{4,2-\frac{1}{2}} \\
0 & 0 & 0 & 0 & -AY_{1,2-\frac{1}{2}} & 0 & 0 & 0 & d_{1,3} & -AX_{1+\frac{1}{2},3} & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & -AY_{2,2-\frac{1}{2}} & 0 & 0 & -AX_{1+\frac{1}{2},3} & d_{2,3} & -AX_{2\frac{1}{2},3} & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & -AY_{3,2-\frac{1}{2}} & 0 & 0 & -AX_{2+\frac{1}{2},3} & d_{3,3} & -AX_{3+\frac{1}{2},3} \\ 
0 & 0 & 0 & 0 & 0 & 0 & 0 & - AY_{4,2-\frac{1}{2}} & 0 & 0 & -AX_{3+\frac{1}{2},3} & d_{4,3} \\
};
\matrix [matrix of math nodes, left delimiter={[}, right delimiter={]},
         right=2em of M.east, nodes={minimum height=5.5ex, inner sep=0pt}, 
         row sep=1ex] (P) {
P_{1,1}\\ P_{2,1}\\ P_{3,1}\\ P_{4,1}\\ 
P_{1,2}\\ P_{2,2}\\ P_{3,2}\\ P_{4,2}\\ 
P_{1,3}\\ P_{2,3}\\ P_{3,3}\\ P_{4,3} \\
};

\node[right=1em of P] (equal) {$=$};

\matrix[matrix of math nodes, left delimiter={[}, right delimiter={]},
         right=1em of equal, nodes={minimum height=5.5ex, inner sep=0pt}, 
         row sep=1ex] (O) {
O_{1,1}\\ O_{2,1}\\ O_{3,1}\\ O_{4,1}\\ 
O_{1,2}\\ O_{2,2}\\ O_{3,2}\\ O_{4,2}\\ 
O_{1,3}\\ O_{2,3}\\ O_{3,3}\\ O_{4,3} \\
};

\linebelowrow{M}{4}\linebelowrow{M}{8}
\lineaftercolumn{M}{4}\lineaftercolumn{M}{8}
\linebelowrow{P}{4}\linebelowrow{P}{8}
\linebelowrow{O}{4}\linebelowrow{O}{8}

\end{tikzpicture}
\end{document}

Note that, anyway, this code also produces a matrix too large to fit in a page. But this problem is in the matrix, not in the tool you use to typeset it. If you reduce the figure too much, the subindexes will be unreadable. I would go for a landscape page to show this matrix, or alternatively, to a more compact way to represent it, via submatrices, which can be shown separately in different formulae.

Related Question