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!

Writing a Matrix

  1. Feb 22, 2012 #1
    My apologies if this is in the wring place, but is there any way that I can write a matrix out on this forum? Maybe set up a table in excel or word and copy over? Any suggestions?
     
  2. jcsd
  3. Feb 22, 2012 #2

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    You can use plain text, like this: A = [[a,b],[c,d]] (and explain that this means [row1,row2]), or you can use tex, like this:
    [tex] A = \left[ \begin{array}{cc} a & b \\ c & d \end{array} \right]. [/tex]

    The instructions used for the latter are:
    "[t e x] A = \left[ \b e g i n{a r r a y}{cc} a & b \\ c & d \e n d{a r r a y} \right]. [/ t e x]"
    When you type it out, remove the quotation marks and remove the spaces within words, so type 'tex' instead of 't e x', type 'begin' instead of 'b e g i n', type 'array' instead of 'a r r a y', etc. You don't need to remove spaces inside formulas, so it is OK to type a & b \\ c & d, etc. If you prefer rounded brackets, change '\left[' to '\left(', and similarly for '\right'. That would give
    [tex] A = \left( \begin{array}{cc} a & b \\ c & d \end{array} \right). [/tex]

    RGV
     
  4. Feb 22, 2012 #3

    Mark44

    Staff: Mentor

    The nicest way is to use LaTeX. Here's an example with the tags showing (with extra spaces in the tags so that they will show).

    [ tex] \ begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \ end{bmatrix}[ /tex]

    Removing the extra spaces in the tex tags and the begin and end statements produces this 3 x 3 matrix:
    [tex] \begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \end{bmatrix}[/tex]
     
  5. Feb 22, 2012 #4
    Thank you gentlemen.
     
  6. Feb 22, 2012 #5
    [tex]\begin{bmatrix}2&0&6\\6&8&8\\0&6&8\end{bmatrix}[/tex]
     
  7. Feb 22, 2012 #6
    \ begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \ end{bmatrix}
     
  8. Feb 22, 2012 #7
    begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \ end{bmatrix}
     
  9. Feb 22, 2012 #8
    begin{bmatrix}2&0&6\\6&8&8\\0&6&8\end{bmatrix}
     
  10. Feb 22, 2012 #9
    [tex] A = \left[ \begin{array}{cc} 3&4\\ 2&2\end{array}\right]. [/tex]
     
  11. Feb 22, 2012 #10
    [ tex]\begin{bmatrix} 2&6&0\\0&2&0\\0&0&3\end{bmatrix}[ /tex]
     
  12. Feb 22, 2012 #11
    \begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \end{bmatrix}
     
  13. Feb 22, 2012 #12

    Mark44

    Staff: Mentor

    Looks good.

    As you can see, the LaTeX that Ray Vickson and I wrote, both produce matrices. For simple matrices, the \begin{bmatrix} ... \end{bmatrix} style is easier, IMO.

    The b in bmatrix stands for bracket - []. There's also a pmatrix style that uses parentheses () to surround the matrix. There's another form that I don't recall at the moment - I think it surrounds the matrix with vertical lines, like you would use for a determinant.

    There are lots of summaries and tutorials on the Web, so a search for "latex tutorial" will get you a bunch of links. There's also a sticky post in Forum Feedback and Announcements here at PF (https://www.physicsforums.com/showthread.php?t=546968) that gives an overview of the things you can do.

    If you need to do more complicated matrices, then the style that Ray showed is more versatile, allowing you to write augmented matrices and other stuff.
     
  14. Feb 22, 2012 #13
    Appreciated. Definitely something I'll probably have to use in the future when it comes to programming too, so i might as well get a fix on it.

    Cheers
     
  15. Feb 22, 2012 #14

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    It might not have been obvious to you, but between the column separators " & " you can put any formula; and, if you use the "array" form you can justify the columns (separately); for example, "{ccc}" means "center" the items in each column; "lcr" means left-justify column 1, center column 2 and right-justify column 3; you might want to do this for something like:
    [tex]
    A = \left[ \begin{array}{lcr}
    abba & a_{11}x_1^2 + \ln(x_2) & 12.0 \\
    aaabbbaa & \sqrt{x_1^2 + x_2^2} & 125.4 \end{array} \right]. [/tex]

    RGV
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook