[Tex/LaTex] Matrix decomposition

matricestikz-pgf

I am trying to get what's on the image:

Mi example looks bigger than the one in the picture, the latter looks more compact and nicer. Also, the matrices in the picture look sharper, meaning, they have a bold effect or something like that.

\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools, nccmath}
\usepackage{nicematrix}
\usetikzlibrary{fit,
    shapes.geometric}
\tikzset{highlight/.style={ellipse, draw=red, semithick, inner sep=1pt}}

\usepackage{lipsum}
\begin{document}

    \begin{equation*}\medmath{
        \begin{NiceArray}{|C|C|C|C|C|C|C|C|C|C|C|C|}%
            \hline
1& & 3 &  &  & 5 &  &  & 5 &  & 4 &  \\ \hline
&  & 5 & 4  &  &  &  4&  &  & 2 & 1 & 3 \\ \hline
2  & 4 &  & 1 & 2  &  & 3 &  & 4 & 3 & 5 &  \\ \hline
& 2& 4 &  & 5 &  &  & 4 & &  &  2&  \\ \hline
&  & 4 & 3 & 4 & 2 &  &  &  &  & 2 &5  \\ \hline
1 &  & 3 &  & 3 &  &  &  2&  &  &  4& \\
\hline
        \end{NiceArray}
        \quad=\quad
        \begin{NiceArray}{|C|C|C|}%
        \hline
            &  &  \\ \hline
            &  &  \\ \hline
            &  &  \\ \hline
            &  &  \\ \hline
            &  &  \\ \hline
            &  & \\
            \hline
    \end{NiceArray}
        \quad\times\quad
        \begin{NiceArray}{|C|C|C|C|C|C|C|C|C|C|C|C|}%
        \hline
            &  &  &  &  &  &  &  &  &  &  &  \\ \hline
            &  &  &  &  &  &  &  &  &  &  &  \\ \hline
            &  &  &  &  &  &  &  &  &  &  & \\ \hline
            \end{NiceArray}
    }
    \medskip
    \end{equation*}

\end{document}

enter image description here

Best Answer

Just for completeness: some style that allows one to easily draw vertical and horizontal lines, even if the matrix has empty nodes. These additional features are not needed to answer the question, but were very easy to add to the above code. There must, however, be at least one node in every column and row.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,calc,positioning,fit,backgrounds}
\makeatletter
\long\def\ifnodedefined#1#2#3{%
    \@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
\tikzset{matrix vlines/.style={execute at end matrix={
\edef\tikzmatrixname{\tikz@fig@name}
\foreach \XX in {1,...,\the\pgf@matrix@numberofcolumns}
{\xdef\FitList{}
\foreach \YY in {1,...,\the\pgfmatrixcurrentrow}
{\ifnodedefined{\tikzmatrixname-\YY-\XX}{\xdef\FitList{\FitList (\tikzmatrixname-\YY-\XX)}}{}
}
\node[fit=\FitList,draw=none,fill=none,inner sep=0pt,draw=none] (\tikzmatrixname-col-\XX) {};
}
\foreach \XX in {2,...,\the\pgf@matrix@numberofcolumns}
{\draw[#1] ($(\tikzmatrixname-col-\XX.west)!0.5!(\tikzmatrixname-col-\the\numexpr\XX-1\relax.east)$)
coordinate (aux) (aux|-\tikzmatrixname.north)
 --  (aux|-\tikzmatrixname.south);
}
}},matrix hlines/.style={execute at end matrix={
\edef\tikzmatrixname{\tikz@fig@name}
\foreach \YY in {1,...,\the\pgfmatrixcurrentrow}
{\xdef\FitList{}
\foreach \XX in {1,...,\the\pgf@matrix@numberofcolumns}
{\ifnodedefined{\tikzmatrixname-\YY-\XX}{\xdef\FitList{\FitList (\tikzmatrixname-\YY-\XX)}}{}
}
\node[fit=\FitList,draw=none,fill=none,inner sep=0pt,draw=none] (\tikzmatrixname-row-\YY) {};
}
\foreach \XX in {2,...,\the\pgfmatrixcurrentrow}
{\draw[#1] ($(\tikzmatrixname-row-\XX)!0.5!(\tikzmatrixname-row-\the\numexpr\XX-1\relax)$)
coordinate (aux) (aux-|\tikzmatrixname.west)
 --  (aux-|\tikzmatrixname.east);
}
}},
matrix dividers/.style={matrix vlines=#1,matrix hlines=#1},
matrix frame/.style={execute at end matrix={
\draw[#1] (\tikz@fig@name.south west) rectangle (\tikz@fig@name.north east);
}}}
\makeatother
\begin{document}
\begin{tikzpicture}
\matrix[matrix vlines={blue},matrix of math nodes] (mat1) {
1& & 3 &  &  & 5 &  &  & -5 &  & 4 &  \\ 
&  & 5 & 4  &  &  &  4&  &  & 2 & 1 & 3 \\ 
2  & 4 &  & 1 & 2  &  & 3 &  & 4 & 3 & 5 &  \\ 
& 2& 4 &  & -5 &  &  & 4 & &  &  2&  \\ 
&  & 4 & 3 & 4 & 2 &  &  &  &  & 2 &5  \\ 
1 &  & 3 &  & 3 &  &  &  2&  &  &  4& \\
};
\matrix[matrix hlines={red},below=2em of mat1,matrix of math nodes] (mat2) {
1& & 3 &  &  & 5 &  &  & -5 &  & 4 &  \\ 
&  & 5 & 4  &  &  &  4&  &  & 2 & 1 & 3 \\ 
2  & 4 &  & 1 & 2  &  & 3 &  & 4 & 3 & 5 &  \\ 
& 2& 4 &  & -5 &  &  & 4 & &  &  2&  \\ 
&  & 4 & 3 & 4 & 2 &  &  &  &  & 2 &5  \\ 
1 &  & 3 &  & 3 &  &  &  2&  &  &  4& \\
};
\matrix[matrix dividers={thin,dashed},below=2em of mat2,matrix of math nodes] (mat3) {
1& & 3 &  &  & 5 &  &  & -5 &  & 4 &  \\ 
&  & 5 & 4  &  &  &  4&  &  & 2 & 1 & 3 \\ 
2  & 4 &  & 1 & 2  &  & 3 &  & 4 & 3 & 5 &  \\ 
& 2& 4 &  & -5 &  &  & 4 & &  &  2&  \\ 
&  & 4 & 3 & 4 & 2 &  &  &  &  & 2 &5  \\ 
1 &  & 3 &  & 3 &  &  &  2&  &  &  4& \\
};
\begin{scope}[on background layer,fill opacity=0.3]
 \fill[red] (mat3-col-2.west|-mat3.north) rectangle (mat3-col-2.east|-mat3.south);
 \fill[orange] (mat3-row-2.north-|mat3.west) rectangle (mat3-row-2.south-|mat3.east);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here