1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help with Matrix in Latex

  1. Apr 28, 2009 #1
    Hi,

    I am trying to produce a matrix in Latex with the following code:
    Code (Text):
    \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
     
  2. jcsd
  3. Apr 28, 2009 #2
    I create matrices like this

    Code (Text):
    \begin{equation}

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

    \end{equation}
     
  4. Apr 28, 2009 #3

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    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: Apr 28, 2009
  5. Apr 28, 2009 #4
    Thanks, that worked great.

    Ryan
     
  6. Apr 28, 2009 #5

    statdad

    User Avatar
    Homework Helper

    (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.
     
  7. Apr 28, 2009 #6
    Thanks statdad.

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

    Ryan
     
  8. Apr 28, 2009 #7

    statdad

    User Avatar
    Homework Helper

    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.
     
  9. Apr 28, 2009 #8
    Ok thanks
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Help with Matrix in Latex
  1. LaTeX help (Replies: 1)

  2. Matrix help? (Replies: 9)

  3. Latex help (Replies: 4)

  4. LatEX help (Replies: 4)

  5. Help with a matrix (Replies: 2)

Loading...