# Writing a Matrix

1. Feb 22, 2012

### trap101

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. Feb 22, 2012

### Ray Vickson

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:
$$A = \left[ \begin{array}{cc} a & b \\ c & d \end{array} \right].$$

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
$$A = \left( \begin{array}{cc} a & b \\ c & d \end{array} \right).$$

RGV

3. Feb 22, 2012

### 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:
$$\begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \end{bmatrix}$$

4. Feb 22, 2012

### trap101

Thank you gentlemen.

5. Feb 22, 2012

### trap101

$$\begin{bmatrix}2&0&6\\6&8&8\\0&6&8\end{bmatrix}$$

6. Feb 22, 2012

### trap101

\ begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \ end{bmatrix}

7. Feb 22, 2012

### trap101

begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \ end{bmatrix}

8. Feb 22, 2012

### trap101

begin{bmatrix}2&0&6\\6&8&8\\0&6&8\end{bmatrix}

9. Feb 22, 2012

### trap101

$$A = \left[ \begin{array}{cc} 3&4\\ 2&2\end{array}\right].$$

10. Feb 22, 2012

### trap101

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

11. Feb 22, 2012

### trap101

\begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \end{bmatrix}

12. Feb 22, 2012

### 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.

13. Feb 22, 2012

### trap101

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

14. Feb 22, 2012

### Ray Vickson

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:
$$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].$$

RGV