0

How to add labels as in the following figure:

enter image description here

I found some topics but none of them help my problem:

Text above matrices

Label rows of a matrix by characters

  • 1
    Hello, please post a minimal example of what you have tried so far, this will help others help you. – BambOo Sep 14 '18 at 9:50
3

With proper math spacing in the top line: no intercolumn space in the array, but with empty atoms in order to achieve the right spacing.

I provide two versions, one with the full specification of the operations, one with just the symbols for the matrices, take your pick.

\documentclass{article}
\usepackage{amsmath,array}

\newcolumntype{M}{>{{}}c<{{}}}

\begin{document}

With full specification also in the bottom line
\[
\newcommand{\lhs}{% A shorthand for not repeating three times the same stuff
  \begin{bmatrix}
  y(\mathbf{x}_1)\\
  \vdots\\
  y(\mathbf{x}_N)\\
\end{bmatrix}%
}
\begin{array}{@{}M@{}M@{}l@{}M@{}M@{}M@{}M@{}M@{}M@{}l@{}}
\lhs
&
\sim
&
\mathcal{N}\left(\vphantom{\lhs}\right.\kern-\nulldelimiterspace
&
\begin{bmatrix} 0 \\ \vdots \\ 0 \end{bmatrix}
&
,
&
\begin{bmatrix}
  k(\mathbf{x}_1,\mathbf{x}_1)&\cdots&k(\mathbf{x}_1,\mathbf{x}_N)\\
  \vdots&\ddots&\vdots\\
  k(\mathbf{x}_N,\mathbf{x}_1)&\cdots&k(\mathbf{x}_N,\mathbf{x}_N)\\
  \end{bmatrix}
&
+
&
\sigma^2\begin{bmatrix}
1&\cdots&0\\
\vdots&\ddots&\vdots\\
0&\cdots&1\\
\end{bmatrix}
&
\left.\kern-\nulldelimiterspace\vphantom{\lhs}\right)
\\[5ex]
\mathbf{y} & \sim &
  \mathcal{N}\,( & \mathbf{0} & , & \mathbf{K} & + & \sigma^2\mathbf{I} & )
\end{array}
\]

With just the names of the matrices in the bottom line
\[
\newcommand{\lhs}{% A shorthand for not repeating three times the same stuff
  \begin{bmatrix}
  y(\mathbf{x}_1)\\
  \vdots\\
  y(\mathbf{x}_N)\\
\end{bmatrix}%
}
\begin{array}{@{}M@{}M@{}l@{}M@{}M@{}M@{}M@{}M@{}M@{}l@{}}
\lhs
&
\sim
&
\mathcal{N}\left(\vphantom{\lhs}\right.\kern-\nulldelimiterspace
&
\begin{bmatrix} 0 \\ \vdots \\ 0 \end{bmatrix}
&
,
&
\begin{bmatrix}
  k(\mathbf{x}_1,\mathbf{x}_1)&\cdots&k(\mathbf{x}_1,\mathbf{x}_N)\\
  \vdots&\ddots&\vdots\\
  k(\mathbf{x}_N,\mathbf{x}_1)&\cdots&k(\mathbf{x}_N,\mathbf{x}_N)\\
  \end{bmatrix}
&
+
&
\sigma^2\begin{bmatrix}
1&\cdots&0\\
\vdots&\ddots&\vdots\\
0&\cdots&1\\
\end{bmatrix}
&
\left.\kern-\nulldelimiterspace\vphantom{\lhs}\right)
\\[5ex]
\mathbf{y} & & & \mathbf{0} & & \mathbf{K} & & \sigma^2\mathbf{I} & 
\end{array}
\]
\end{document}

enter image description here

I used a shorthand \lhs in order to avoid repeating three times (in each display) the same stuff. The name is arbitrary and the definition will not survive the display. Its purpose is to form the left hand side and also to give a suitable height to the \left( and \right) parentheses via a vertical phantom.

  • nice answer (+1). i took liberty and remove spurious I in the first solution. where is defines \lhs? – Zarko Sep 14 '18 at 10:45
  • @Zarko Thanks. \lhs is just a single purpose macro set up in order to fix the size of \left( and \right) with a \vphantom and not repeating the whole lot. – egreg Sep 14 '18 at 10:58
  • now i find it definition, thank you! it is (for me hidden) in code for the second equation :-) – Zarko Sep 14 '18 at 11:04
0

this may not look very sophisticated, but using a simple \begin{array}...\end{array}approach may just do what the example shows.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[\begin{array}{*5c}
\begin{bmatrix}
y(x_1)\\
\vdots\\
y(x_N)\\
\end{bmatrix}&\sim\mathcal{N}&\left(\begin{bmatrix}
0\\
\vdots\\
0\\
\end{bmatrix},\right.&\begin{bmatrix}
k(x_1,x_1)&\cdots&k(x_1,x_N)\\
\vdots&\ddots&\vdots\\
k(x_N,x_1)&\cdots&k(x_N,x_N)\\
\end{bmatrix}&+\sigma^2\left.\begin{bmatrix}
1&\cdots&0\\
\vdots&\ddots&\vdots\\
0&\cdots&1\\
\end{bmatrix}\right)\\
y&&0&K&+\sigma^2I
\end{array}\]
\end{document}

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.