# Array command in Latex

## ! LaTeX Error: \begin{array} on input line 569 ended by \end{equation*}.

    #1,

Let X =
$\left(\begin{array}{cc} 1 & X1\\ \dots & \dots\\ 1 & X_n \end{array}\right) %\left(\begin{array}{cc} 10 & 0\\ 0 & 5 \end{array}\right)$

Then, $X^T$ =
$\left(\begin{array}{cc} 1 & \dots & 1\\ X_1 & \dots & X_N \end{array}\right)$

$X \times X^T =$

$\left(\begin{array}{cc} 1 & X1\\ \dots & \dots\\ 1 & X_n \end{array}\right)$
$\left(\begin{array}{cc} 1 & \dots & 1\\ X_1 & \dots & X_N \end{array}\right)$

=

$\left(\begin{array}{cc} n & \sum_{i}^n X_i\\ \sum_{i}^n X_i & \sum_{i}^n X_i^2 \end{array}\right)$

#2,

$(X^TX)^{-1}$=

$1/[n\sum_{i=1}^n X_i^2 - (\sum_{i=1}^n X_i)^2] \left(\begin{array}{cc} \sum_{i=1}^n X_i^2 & -\sum_{i=1}^n Xi\\ - \sum _{i=1}^n X_i & n \end{array}\right)$
=$1/[n \sum _{i=1}^n X_i^2 - ( \sum X_i)^2] [n \sum_{i=1}^n X_i^2 - ( \sum _{i=1} ^n X_i)^2]$
=1


The above are the code I only had about the command{array}, I am sorry I am new to R-Markdown and I cannot find the line 569 since my last line is line 373. Thank you very much for any suggestions! Appreciated!

• Incidentally, you should really check your math. I believe there are two particularly troublesome issues. First, if X is an nx2 matrix, the dimension of XX^T must be nxn, not 2x2. Second, if n>1, the matrix XX^T is not of full rank and its inverse does not exist -- let alone be equal to scalar 1. Are you maybe referring to X^T X and its inverse? By the way, the inverse of X^T X should be a 2x2 matrix, not the number 1. If the math isn't correct, it's not all that productive to try to fix up the LaTeX code, is it? – Mico Oct 4 '18 at 5:38

I made your code compile and also replaced the arrays by matrices where I thought this would be appropriate. Notice also that there are environments like align that allow you to write aligned multiline equations. So here is some modification of your code that can be compiled and has some minor corrections.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Let
$X =\begin{pmatrix} 1 & X_1\\ \dots & \dots\\ 1 & X_n \end{pmatrix} \begin{pmatrix} 10 & 0\\ 0 & 5 \end{pmatrix}$
Then,
$X^T = \begin{pmatrix} 1 & \dots & 1\\ X_1 & \dots & X_N \end{pmatrix}$
and
\begin{align*}
X \times X^T &=
\begin{pmatrix}
1 & X1\\
\dots & \dots\\
1 & X_n
\end{pmatrix}\,
\begin{pmatrix}
1 & \dots & 1\\
X_1 & \dots & X_N
\end{pmatrix} \\
&=
\begin{pmatrix}
n & \sum_{i}^n X_i\\
\sum_{i}^n X_i & \sum_{i}^n X_i^2
\end{pmatrix}
\end{align*}
as well as
\begin{align*}
(X^TX)^{-1}&=
\frac{1}{n\sum_{i=1}^n X_i^2 - \left(\sum_{i=1}^n X_i\right)^2}
\begin{pmatrix}
\sum_{i=1}^n X_i^2 & -\sum_{i=1}^n Xi\\
- \sum _{i=1}^n X_i & n
\end{pmatrix} \\
&=\frac{1}{n \sum _{i=1}^n X_i^2 - ( \sum X_i)^2}
\left[n \sum_{i=1}^n X_i^2 - \left( \sum _{i=1} ^n X_i\right)^2\right]
\\
&=1
\end{align*}
\end{document}


It is not hard to see, though, that the first equation does not make too much sense in view of the equations below it. On the other hand, I did not just dare to remove the right-most matrix, but I am sure you will know what to do with it.

• A heroic try! :-) See the comment I just left under the initial posting... – Mico Oct 4 '18 at 5:40
• @Mico Thanks! I agree with you except that I think one may partly save this by arguing that the notation indicates a dyadic product and X^T is a column and X a row vector. But yes, the notation is very unclear. – marmot Oct 4 '18 at 5:46
• My guess is that X represents the regressors from a bivariate regression: a constant term (1) and the "independent variable" x. We may never know for sure... – Mico Oct 4 '18 at 5:50
• @Mico Could very well be. No idea. My only intention here was to provide something that runs through and to inform the OP that array may not be the way to go. – marmot Oct 4 '18 at 5:54