Help with Matrix in Latex

  • Thread starter ryan88
  • Start date
  • #1
42
0

Main Question or Discussion Point

Hi,

I am trying to produce a matrix in Latex with the following code:
Code:
\begin{bmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4
\end{bmatrix}
But I keep on getting the following error:
Extra alignment tab has been changed to \cr.<recently read> \endtemplate

This error occurs for each row in that matrix.

I would appreciate any help anyone can give,

Thanks,

Ryan
 

Answers and Replies

  • #2
490
2
I create matrices like this

Code:
\begin{equation}

\left[
 \begin{array}{ccc}
   1 & 0 & 0\\
   0 & 1 & 0\\
   0 & 0 & 1
 \end{array}
\right]

\end{equation}
 
  • #3
HallsofIvy
Science Advisor
Homework Helper
41,792
919
I just copied your code into tex and it gives

[tex]\begin{bmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4
\end{bmatrix}[/tex]
Is there a maximum of 10 columns in a matrix?

If we try to do it "by hand" (using \begin{array})
[tex]\left[\begin{array}{cccccccccccccc}
1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4
\end{array}\right][/tex]

The code for that is
\left[\begin{array}{cccccccccccccc}
1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4
\end{array}\right]

Notice that, using \begin{array}, you need to put in the braces (\left[ and \right]) yourself (so you could use ( ), { }, etc.). The {cccccccccccccc} (14 c's) tells LaTex there are 14 columns.
 
Last edited by a moderator:
  • #4
42
0
Thanks, that worked great.

Ryan
 
  • #5
statdad
Homework Helper
1,495
35
(I believe) There is a default for the maximum number of columns in the matrix environments, and that it is possible to change it in your document.

I don't have the pertinent information at my fingertips now; perhaps a search of tug.org
or some other site would be fruitful.
Edit: spoke too soon: from AMS math documentation, footnote on page 10.

More precisely: The maximum number of columns in a matrix is determined by the
counter MaxMatrixCols (normal value = 10), which you can change if necessary using LATEX’s
\setcounter or \addtocounter commands.
 
  • #6
42
0
Thanks statdad.

Is there any advantage of using \begin{bmatrix} over \left[\begin{array}?

Ryan
 
  • #7
statdad
Homework Helper
1,495
35
Thanks statdad.

Is there any advantage of using \begin{bmatrix} over \left[\begin{array}?

Ryan
That I can't say, as I use the "bmatrix" environment exclusively. As some other posters have shown, it is possible to control column alignment in arrays; I don't know of a similar feature with the matrix environments.
 
  • #8
42
0
Ok thanks
 

Related Threads for: Help with Matrix in Latex

  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
1
Views
7K
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
2K
Top