5

I have tried to replicate a portion of this matrix decomposition system in LaTeX, but I am unable to draw the first and the last matrices with rectangular boxes.enter image description here

This is what I could do until now, which of course, is easy to write. I can use LatexDraw to draw this figure, but the figure will not look very elegant as this one:

 \begin{equation}
\underbrace{\mathbf{A}}_{W \times D} = \underbrace{\mathbf{U}}_{W \times W} \times \underbrace{\mathbf{\Sigma}}_{W\times D} \times \underbrace{\mathbf{V}^{\text{T}}}_{D \times D} = 
\left(
 \begin{array}{ccccc}
   \sigma_1\\
    & . & & \text{\huge0}\\
    & & .\\
    & \text{\huge0} & & \sigma_r\\
    & & & & 0
 \end{array}
\right)
\end{equation}
2
  • It would be welcomed that the code you provided started with \documentclass and ended with \end{document}.
    – Manuel
    Jun 4 '14 at 15:54
  • @Manuel: I am sorry about this. It has been two times since I have been reminded about it. Next time there won't be any complains, I promise.
    – puser
    Jun 5 '14 at 0:13
4

Using TikZ and some matrix of math nodes:

Matrix factorization by SVD

The code:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning,decorations.pathreplacing}

\DeclareMathOperator{\Mcol}{col}
\DeclareMathOperator{\Mrow}{row}
\DeclareMathOperator{\Mnull}{null}

\begin{document}

\begin{align*}
A &= U\Sigma V^{T} \\
&=
\begin{tikzpicture}[
baseline,
mymat/.style={
  matrix of math nodes,
  ampersand replacement=\&,
  left delimiter=(,
  right delimiter=),
  nodes in empty cells,
  nodes={outer sep=-\pgflinewidth,text depth=0.5ex,text height=2ex,text width=1.2em}
}
]
\begin{scope}[every right delimiter/.style={xshift=-3ex}]
\matrix[mymat] (matu)
{
 \& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
};
\node 
  at ([shift={(3pt,-7pt)}]matu-3-2.west) 
  {$\cdots$};
\node 
  at ([shift={(3pt,-7pt)}]matu-3-5.west) 
  {$\cdots$};
\foreach \Columna/\Valor in {1/1,3/r,4/{r+1},6/m}
{
\draw 
  (matu-1-\Columna.north west)
    rectangle
  ([xshift=4pt]matu-6-\Columna.south west);
\node[above] 
  at ([xshift=2pt]matu-1-\Columna.north west) 
  {$u_{\Valor}$};
}
\draw[decorate,decoration={brace,mirror,raise=3pt}] 
  (matu-6-1.south west) -- 
   node[below=4pt] {$\Mcol(A)$}
  ([xshift=4pt]matu-6-3.south west);
\draw[decorate,decoration={brace,mirror,raise=3pt}] 
  (matu-6-4.south west) -- 
   node[below=4pt] {$\Mnull(A)$}
  ([xshift=4pt]matu-6-6.south west);
\end{scope}
\matrix[mymat,right=10pt of matu] (matsigma)
{
\sigma_{1} \& \& \& \& \& \\
\& \ddots \& \& \& \& \\
\& \& \sigma_{r} \& \& \& \\
\& \& \& 0 \& \& \\
\& \& \& \& \ddots \& \\
\& \& \& \& \& 0 \\
};
%\begin{scope}[every right delimiter/.style={xshift=-3ex}]
\matrix[mymat,right=25pt of matsigma] (matv)
{
 \& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
\& \& \& \& \& \\
};
\foreach \Fila/\Valor in {1/1,3/r,4/{r+1},6/n}
{
\draw 
  ([yshift=-6pt]matv-\Fila-1.north west)
    rectangle
  ([yshift=-10pt]matv-\Fila-6.north east);
\node[right=12pt] 
  at ([yshift=-8pt]matv-\Fila-6.north east) 
  {$v^{T}_{\Valor}$};
}
\draw[decorate,decoration={brace,raise=37pt}] 
  ([yshift=-6pt]matv-1-6.north east) -- 
   node[right=38pt] {$\Mrow(A)$}
  ([yshift=-10pt]matv-3-6.north east);
\draw[decorate,decoration={brace,raise=37pt}] 
  ([yshift=-6pt]matv-4-6.north east) -- 
   node[right=38pt] {$\Mnull(A)$}
  ([yshift=-10pt]matv-6-6.north east);
\end{tikzpicture}
\end{align*}

\end{document}

The few missing elements are easy to add.

4

Not exactly your scheme, but it approximates...

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\newcommand{\vect}{\mathbf}
\newcommand{\nul}{\operatorname{Nul}}
\newcommand{\col}{\operatorname{Col}}
\newcommand{\row}{\operatorname{Row}}

\[
   A= U\Sigma V^T=
  \begin{matrix}
    \underbrace{\left[\begin{matrix}\vect u_1 & \vect u_2 & \dots & \vect u_r\end{matrix}\right.}& 
    \underbrace{\left.\begin{matrix}\vect u_{r+1} & \dots &  \vect u_m\end{matrix}\right]}\\
    \col A & \nul A^T
  \end{matrix}
  \begin{bmatrix}
      \sigma_1 & 0 & \dots & 0 & 0 & \dots & 0 \\
         0 & \sigma_2  & \dots & 0 & 0 & \dots & 0 \\
         \dots& & & & &  \\
         0 & 0 & \dots & \sigma_r  & 0 & \dots & 0 \\
         0 & 0 & \dots & 0 & 0 & \dots & 0 \\
         \dots& & & & &  \\
         0 & 0 & \dots & 0 & 0 & \dots & 0 
  \end{bmatrix}
  \begin{bmatrix}
    \vect v_1^T \\ \vect v_2^T \\ \dots \\ \vect v_r^T \\
    \vect v_{r+1}^T \\ \dots \\ \vect v_n^T
  \end{bmatrix}
  \begin{matrix}
    \left.\vphantom{\begin{bmatrix}
       \vect v_1^T \\ \vect v_2^T \\ \dots \\ \vect v_r^T 
       \end{bmatrix}}\right\}\row A \\ 
    \left.\vphantom{\begin{bmatrix}
      \vect v_{r+1}^T \\ \dots \\ \vect v_n^T 
    \end{bmatrix}}\right\}\nul A
  \end{matrix}
\] 

\end{document}

singular values decomposition

1
  • Your solution seems very good as well. Thanks a lot. But unfortunately, I am forced to accept only one of the two.
    – puser
    Jun 5 '14 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.