6

I am trying to print the following equation in an article

H = \begin{pmatrix}
1 & x_{11} & \cdots & x_{1p} \\
1 & x_{21} & \cdots & x_{2p} \\
\cdots & \cdots & \cdots & \cdots \\
1 & x_{n1} & \cdots & x_{np} \\
\end{pmatrix}

\begin{pmatrix}
q_{11} & q_{12} & \cdots & q_{1p+1} \\
q_{21} & q_{22} & \cdots & q_{2p+1} \\
\cdots & \cdots & \cdots & \cdots \\
q_{p+11} & q_{p+12} & \cdots & q_{p+1p+1} \\
\end{pmatrix}

\begin{pmatrix}
1 & 1 & \cdots & 1 \\
x_{11} & x_{21} & \cdots & x_{n1} \\
\cdots & \cdots & \cdots & \cdots \\
x_{1p} & x_{2p} & \cdots & x_{np} \\
\end{pmatrix}

=

\begin{pmatrix}
x_{1}^{t}q_{1} & x_{1}^{t}q_{2} & \cdots & x_{1}^{t}q_{p+1} \\
x_{2}^{t}q_{1} & x_{2}^{t}q_{2} & \cdots & x_{2}^{t}q_{p+1} \\
\cdots & \cdots & \cdots & \cdots \\
x_{n}^{t}q_{1} & x_{n}^{t}q_{2} & \cdots & x_{n}^{t}q_{p+1} \\
\end{pmatrix}

\begin{pmatrix}
1 & 1 & \cdots & 1 \\
x_{11} & x_{21} & \cdots & x_{n1} \\
\cdots & \cdots & \cdots & \cdots \\
x_{1p} & x_{2p} & \cdots & x_{np} \\
\end{pmatrix}

I am putting the code like you can see and to between \equation and $$, but the equation is split into a line by matrix, how can solve it and put the equation properly in the code.

8

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{gathered}
H = \begin{pmatrix}
1 & x_{11} & \cdots & x_{1p} \\
1 & x_{21} & \cdots & x_{2p} \\
\cdots & \cdots & \cdots & \cdots \\
1 & x_{n1} & \cdots & x_{np} \\
\end{pmatrix}
%
\begin{pmatrix}
q_{11} & q_{12} & \cdots & q_{1p+1} \\
q_{21} & q_{22} & \cdots & q_{2p+1} \\
\cdots & \cdots & \cdots & \cdots \\
q_{p+11} & q_{p+12} & \cdots & q_{p+1p+1} \\
\end{pmatrix}
%
\begin{pmatrix}
1 & 1 & \cdots & 1 \\
x_{11} & x_{21} & \cdots & x_{n1} \\
\cdots & \cdots & \cdots & \cdots \\
x_{1p} & x_{2p} & \cdots & x_{np} \\
\end{pmatrix}
%
= \\
%
\begin{pmatrix}
x_{1}^{t}q_{1} & x_{1}^{t}q_{2} & \cdots & x_{1}^{t}q_{p+1} \\
x_{2}^{t}q_{1} & x_{2}^{t}q_{2} & \cdots & x_{2}^{t}q_{p+1} \\
\cdots & \cdots & \cdots & \cdots \\
x_{n}^{t}q_{1} & x_{n}^{t}q_{2} & \cdots & x_{n}^{t}q_{p+1} \\
\end{pmatrix}
%
\begin{pmatrix}
1 & 1 & \cdots & 1 \\
x_{11} & x_{21} & \cdots & x_{n1} \\
\cdots & \cdots & \cdots & \cdots \\
x_{1p} & x_{2p} & \cdots & x_{np} \\
\end{pmatrix}
\end{gathered}
\end{equation*}
\end{document}
  • How can i delete the number of the equation? – Tlaloc-ES Nov 23 '19 at 17:12
  • Use \begin{equation*} and \end{equation*} instead, @Tlaloc-ES, if you don't want numbers. Using $$ in LaTeX is wrong. – The Drunken Whaler Nov 23 '19 at 17:13
  • Thanks and is there any way of center the equation? – Tlaloc-ES Nov 23 '19 at 17:14
  • Yes, @Tlaloc-ES. You need to use the gathered environment in that case. I edited my answer. – The Drunken Whaler Nov 23 '19 at 17:19
  • @Tlaloc-ES: How about this code? – Werner Nov 23 '19 at 17:24
10

Some comments about your code:

  • First and foremost, get rid of all blank lines in the math environments.

  • I don't think that it is correct, typographically speaking, to use \cdots as the typographic ellipsis in all places in the matrices. In rows 1, 2, and 4, it should be \dots (or \ldots). In row 3, three of the four \cdots instructions really ought to be \vdots; the 3rd out of four, though, should be \ddots.

  • The subscript notation in the Q matrix in row 1 is not well designed. E.g., instead of 1p+1 and p+12, do write 1,p+1 and p+1,2, etc.

  • The transpose notation you employ in the first matrix in the second row is not well chosen. I suggest you place the transpose symbol -- whether ^t, ^{\prime}, ^{\top}, or whatever strikes your fancy -- between the two vectors.

enter image description here

\documentclass{article}
\usepackage[letterpaper,margin=1in]{geometry} % set page dimensions appropriately
\usepackage{amsmath} % for 'align*' and 'pmatrix' environments
\begin{document}

\begin{align*}
H 
&= \begin{pmatrix}
1 & x_{11} & \dots & x_{1p} \\
1 & x_{21} & \dots & x_{2p} \\
\vdots & \vdots & \ddots & \vdots \\
1 & x_{n1} & \dots & x_{np}
\end{pmatrix}%_{\!\!\!n\times(p+1)}
\begin{pmatrix}
q_{11} & q_{12} & \dots & q_{1,p+1} \\
q_{21} & q_{22} & \dots & q_{2,p+1} \\
\vdots & \vdots & \ddots & \vdots \\
q_{p+1,1} & q_{p+1,2} & \dots & q_{p+1,p+1}
\end{pmatrix}%_{\!\!\!(p+1)\times(p+1)}
\begin{pmatrix}
1 & 1 & \dots & 1 \\
x_{11} & x_{21} & \dots & x_{n1} \\
\vdots & \vdots & \ddots & \vdots \\
x_{1p} & x_{2p} & \dots & x_{np}
\end{pmatrix}%_{\!\!\!(p+1)\times n}
\\
&= \begin{pmatrix}
x_{1}{}'q_{1} & x_{1}{}'q_{2} & \dots & x_{1}{}'q_{p+1} \\
x_{2}{}'q_{1} & x_{2}{}'q_{2} & \dots & x_{2}{}'q_{p+1} \\
\vdots & \vdots & \ddots & \vdots \\
x_{n}{}'q_{1} & x_{n}{}'q_{2} & \dots & x_{n}{}'q_{p+1}
\end{pmatrix}
\begin{pmatrix}
1 & 1 & \dots & 1 \\
x_{11} & x_{21} & \dots & x_{n1} \\
\vdots & \vdots & \ddots & \vdots \\
x_{1p} & x_{2p} & \dots & x_{np}
\end{pmatrix}
\end{align*}
\end{document}
  • 1
    This positive vote was necessary :-) – Sebastiano Nov 23 '19 at 20:30
  • 1
    @Sebastiano - Thanks so much! :-) – Mico Nov 23 '19 at 20:34
  • @Sebastiano - In fact, your upvote raised my year-to-date rep count to over 40K! :-) – Mico Nov 23 '19 at 20:44
  • 1
    I like to vote for everyone :-) especially for the elegance of the answer. What do we have left of this life at the end? – Sebastiano Nov 23 '19 at 20:47

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.