[Tex/LaTex] Array command in Latex

errorsmarkdownmath-moder

I wonder may I ask about why I received the error note from R-Markdown that

! 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!

Best Answer

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}

enter image description here

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.