This site is supported by donations to The OEIS Foundation.

Template:Matrix

From OeisWiki
Jump to: navigation, search

The {{matrix}} mathematical formatting template facilitates the typesetting of matrices (parenthesized matrix [default], bracketed matrix, matrix determinant, or raw matrix) for either HTML+CSS or LaTeX.

For single row or single column matrices, i.e. row vectors or column vectors, you may use the more semantically appropriate {{vector}} template, which simply redirects to the {{matrix}} template.

Usage

{{matrix|matrix entries}}

or

{{matrix|matrix entries|format}}

or

{{matrix|matrix entries|form}}

or

{{matrix|matrix entries|form|format}}

where

  • matrix columns are separated by two consecutive ampersand characters &&;
  • matrix rows are separated by two consecutive backslash characters \\ (do not put \\ at the end of the last row);

and form (optional second argument) is from

  • ( ): parenthesized matrix (default);
  • [ ]: bracketed matrix;
  • det: matrix determinant;
  • raw: raw matrix;

and where format (optional last argument) is from (case insensitive)

  • htm: HTML+CSS (default);
  • tex: LaTeX.

Examples

Raw matrix

The code

{{indent}}{{math|

'''A'''{{sub|5,4}} {{=|sp}} <!--
 
-->{{matrix|       
     ''a''{{sub|1,1}} && ''a''{{sub|1,2}} && ''a''{{sub|1,3}} && ''a''{{sub|1,4}} && ''a''{{sub|1,5}} \\       
     ''a''{{sub|2,1}} && ''a''{{sub|2,2}} && ''a''{{sub|2,3}} && ''a''{{sub|2,4}} && ''a''{{sub|2,5}} \\      
     ''a''{{sub|3,1}} && ''a''{{sub|3,2}} && ''a''{{sub|3,3}} && ''a''{{sub|3,4}} && ''a''{{sub|3,5}} \\       
     ''a''{{sub|4,1}} && ''a''{{sub|4,2}} && ''a''{{sub|4,3}} && ''a''{{sub|4,4}} && ''a''{{sub|4,5}}      
   |raw}}

|&&}}

yields the display style HTML+CSS raw matrix

     
A5,4  = 
a1,1   a1,2   a1,3   a1,4   a1,5
a2,1   a2,2   a2,3   a2,4   a2,5
a3,1   a3,2   a3,3   a3,4   a3,5
a4,1   a4,2   a4,3   a4,4   a4,5

while the code

{{indent}}{{math| 

\mathbf{A}_{5,4} {{=}} <!--
 
-->{{matrix|
     a_{1,1} && a_{1,2} && a_{1,3} && a_{1,4} && a_{1,5} \\
     a_{2,1} && a_{2,2} && a_{2,3} && a_{2,4} && a_{2,5} \\
     a_{3,1} && a_{3,2} && a_{3,3} && a_{3,4} && a_{3,5} \\
     a_{4,1} && a_{4,2} && a_{4,3} && a_{4,4} && a_{4,5}
   |raw|tex}}

|$$}}

yields the display style LaTeX raw matrix

     

Parenthesized matrix

The code

{{indent}}{{math|

'''A'''{{sub|5,4}} {{=|sp}} <!--
 
-->{{matrix|       
     ''a''{{sub|1,1}} && ''a''{{sub|1,2}} && ''a''{{sub|1,3}} && ''a''{{sub|1,4}} && ''a''{{sub|1,5}} \\       
     ''a''{{sub|2,1}} && ''a''{{sub|2,2}} && ''a''{{sub|2,3}} && ''a''{{sub|2,4}} && ''a''{{sub|2,5}} \\      
     ''a''{{sub|3,1}} && ''a''{{sub|3,2}} && ''a''{{sub|3,3}} && ''a''{{sub|3,4}} && ''a''{{sub|3,5}} \\       
     ''a''{{sub|4,1}} && ''a''{{sub|4,2}} && ''a''{{sub|4,3}} && ''a''{{sub|4,4}} && ''a''{{sub|4,5}}      
   |( )}}

|&&}}

yields the display style HTML+CSS parenthesized matrix

     
A5,4  = 
a1,1   a1,2   a1,3   a1,4   a1,5
a2,1   a2,2   a2,3   a2,4   a2,5
a3,1   a3,2   a3,3   a3,4   a3,5
a4,1   a4,2   a4,3   a4,4   a4,5

while the code

{{indent}}{{math| 

\mathbf{A}_{5,4} {{=}} <!--
 
-->{{matrix|
     a_{1,1} && a_{1,2} && a_{1,3} && a_{1,4} && a_{1,5} \\
     a_{2,1} && a_{2,2} && a_{2,3} && a_{2,4} && a_{2,5} \\
     a_{3,1} && a_{3,2} && a_{3,3} && a_{3,4} && a_{3,5} \\
     a_{4,1} && a_{4,2} && a_{4,3} && a_{4,4} && a_{4,5}
   |( )|tex}}

|$$}}

yields the display style LaTeX parenthesized matrix

     

The code

{{indent}}{{math|

'''A'''{{sub|''m'',''n''}} {{=|sp}} <!--
 
-->{{matrix|       
     ''a''{{sub|1,1}}      &&  ''a''{{sub|1,2}}      && {{...|cdots}}  && ''a''{{sub|1,''n''}}      \\       
     ''a''{{sub|2,1}}      &&  ''a''{{sub|2,2}}      && {{...|cdots}}  && ''a''{{sub|2,''n''}}      \\      
     {{...|vdots}}         &&  {{...|vdots}}         && {{...|ddots}}  && {{...|vdots}}             \\ 
     ''a''{{sub|''m'',1}}  &&  ''a''{{sub|''m'',2}}  && {{...|cdots}}  && ''a''{{sub|''m'',''n''}}       
   }}

|&&}} 

yields the display style HTML+CSS parenthesized matrix

     
Am,n  = 
a1,1   a1,2     a1,n
a2,1   a2,2     a2,n
     
am,1   am,2     am,n

while the code

{{indent}}{{math| 

\mathbf{A}_{m,n} {{=}} <!--

-->{{matrix| 
     a_{1,1}           && a_{1,2}           && {{...|cdots|tex}} & a_{1,n}            \\
     a_{2,1}           && a_{2,2}           && {{...|cdots|tex}} & a_{2,n}            \\
     {{...|vdots|tex}} && {{...|vdots|tex}} && {{...|ddots|tex}} & {{...|vdots|tex}}  \\
     a_{m,1}           && a_{m,2}           && {{...|cdots|tex}} & a_{m,n}
   |tex}}

|$$}}

yields the display style LaTeX (rendered as .PNG image) parenthesized matrix

     

Bracketed matrix

The code

{{indent}}{{math|

'''A'''{{sub|5,4}} {{=|sp}} <!--

-->{{matrix|       
     ''a''{{sub|1,1}} && ''a''{{sub|1,2}} && ''a''{{sub|1,3}} && ''a''{{sub|1,4}} && ''a''{{sub|1,5}} \\       
     ''a''{{sub|2,1}} && ''a''{{sub|2,2}} && ''a''{{sub|2,3}} && ''a''{{sub|2,4}} && ''a''{{sub|2,5}} \\      
     ''a''{{sub|3,1}} && ''a''{{sub|3,2}} && ''a''{{sub|3,3}} && ''a''{{sub|3,4}} && ''a''{{sub|3,5}} \\       
     ''a''{{sub|4,1}} && ''a''{{sub|4,2}} && ''a''{{sub|4,3}} && ''a''{{sub|4,4}} && ''a''{{sub|4,5}}      
   |[ ]}}

|&&}} 

yields the display style HTML+CSS [square] bracketed matrix

     
A5,4  = 
a1,1   a1,2   a1,3   a1,4   a1,5
a2,1   a2,2   a2,3   a2,4   a2,5
a3,1   a3,2   a3,3   a3,4   a3,5
a4,1   a4,2   a4,3   a4,4   a4,5

while the code

{{indent}}{{math| 

\mathbf{A}_{5,4} {{=}} <!--

-->{{matrix|       
     a_{1,1} && a_{1,2} && a_{1,3} && a_{1,4} && a_{1,5} \\
     a_{2,1} && a_{2,2} && a_{2,3} && a_{2,4} && a_{2,5} \\
     a_{3,1} && a_{3,2} && a_{3,3} && a_{3,4} && a_{3,5} \\
     a_{4,1} && a_{4,2} && a_{4,3} && a_{4,4} && a_{4,5}
   |[ ]|tex}}

|$$}}

yields the display style LaTeX (rendered as .PNG image) [square] bracketed matrix

     

Matrix determinant

The code

{{indent}}{{math|

det '''A'''{{sub|1,1}} {{=|sp}} <!-- 

-->{{matrix|       
     ''a''{{sub|1,1}}     
   |det}} <!-- 

-->{{=}} {{det|''a''{{sub|1,1}}}}

|&&}} 

yields the display style HTML+CSS matrix determinant (use the {{det}} template for better results with 1 × 1 matrices)

     
det A1,1  = 
a1,1
= | a1,1 |

while the code

{{indent}}{{math| 

\operatorname{det} ~ \mathbf{A}_{1,1} {{=}} <!-- 

-->{{matrix|
     a_{1,1}
   |det|tex}} <!-- 

-->{{=}} {{det| a_{1,1} |tex}}

|$$}}

yields the display style LaTeX (rendered as .PNG image) matrix determinant

     

The code

{{indent}}{{math|

det '''A'''{{sub|''n'',''n''}} {{=|sp}} <!--

-->{{matrix|       
     ''a''{{sub|1,1}}      &&  ''a''{{sub|1,2}}      && {{...|cdots}}  && ''a''{{sub|1,''n''}}      \\       
     ''a''{{sub|2,1}}      &&  ''a''{{sub|2,2}}      && {{...|cdots}}  && ''a''{{sub|2,''n''}}      \\      
     {{...|vdots}}         &&  {{...|vdots}}         && {{...|ddots}}  && {{...|vdots}}             \\ 
     ''a''{{sub|''n'',1}}  &&  ''a''{{sub|''n'',2}}  && {{...|cdots}}  && ''a''{{sub|''n'',''n''}}      
   |det}}

|&&}} 

yields the display style HTML+CSS matrix determinant

     
det An,n  = 
a1,1   a1,2     a1,n
a2,1   a2,2     a2,n
     
an,1   an,2     an,n

while the code

{{indent}}{{math| 

\operatorname{det} ~ \mathbf{A}_{n,n} {{=}} <!--

-->{{matrix|
     a_{1,1} && a_{1,2} && \cdots && a_{1,n} \\
     a_{2,1} && a_{2,2} && \cdots && a_{2,n} \\
     \vdots  && \vdots  && \ddots && \vdots  \\
     a_{n,1} && a_{n,2} && \cdots && a_{n,n}
   |det|tex}}

|$$}}

yields the display style LaTeX (rendered as .PNG image) matrix determinant

     

Matrix inverse formula

The code

{{indent}}{{math|<!-- 

-->'''A'''{{^|{{sp|-3}}{{op|-}}1}} {{=|sp}} {{frac|'''C'''{{sp|1}}{{sup|T}}|{{det|'''A'''}}}} {{=|sp}} <!-- 

-->{{frac|
     {{matrix|       
       ''C''{{sub|1,1}}      &&  ''C''{{sub|1,2}}      && {{...|cdots}}  && ''C''{{sub|1,''n''}}      \\       
       ''C''{{sub|2,1}}      &&  ''C''{{sub|2,2}}      && {{...|cdots}}  && ''C''{{sub|2,''n''}}      \\      
       {{...|vdots}}         &&  {{...|vdots}}         && {{...|ddots}}  && {{...|vdots}}             \\ 
       ''C''{{sub|''n'',1}}  &&  ''C''{{sub|''n'',2}}  && {{...|cdots}}  && ''C''{{sub|''n'',''n''}}      
     }} {{sup|{{sup|{{sup|{{sup|{{sup|{{sup|{{sup|T|100%}}|100%}}|100%}}|100%}}|100%}}|100%}}}}<!-- Yes, kludgy! I'll work out something better... -->
   | 
     {{matrix|       
       ''a''{{sub|1,1}}      &&  ''a''{{sub|1,2}}      && {{...|cdots}}  && ''a''{{sub|1,''n''}}      \\       
       ''a''{{sub|2,1}}      &&  ''a''{{sub|2,2}}      && {{...|cdots}}  && ''a''{{sub|2,''n''}}      \\      
       {{...|vdots}}         &&  {{...|vdots}}         && {{...|ddots}}  && {{...|vdots}}             \\ 
       ''a''{{sub|''n'',1}}  &&  ''a''{{sub|''n'',2}}  && {{...|cdots}}  && ''a''{{sub|''n'',''n''}}      
     |det}}
   |HTM}},

|&&}}{{nl}}

where {{math|{{det|'''A'''}}|&}} is the [[determinant]] of {{math|'''A'''|&}}, {{math|'''C'''|&}} is the [[matrix of cofactors]] of <!--
-->{{math|'''A'''|&}}, and {{math|'''C'''{{sup|T}}|&}} represents the matrix [[transpose]] of {{math|'''C'''|&}}. 
yields the display style HTML+CSS matrix inverse formula (using {{^}} or {{sup}} after large delimiters, e.g. the
T
for matrix transpose, has to be raised, either manually or [hopefully] automatically)
     
A − 1  = 
CT
| A |
 = 
C1,1   C1,2     C1,n
C2,1   C2,2     C2,n
     
Cn,1   Cn,2     Cn,n
T
a1,1   a1,2     a1,n
a2,1   a2,2     a2,n
     
an,1   an,2     an,n
,

where 
| A |
is the determinant of 
A
, 
C
is the matrix of cofactors of 
A
, and 
CT
represents the matrix transpose of 
C
.

The code

{{indent}}{{math|<!-- 

-->\mathbf{A}{{^|\! {{op|-}}1|tex}}  {{=}} {{frac|\mathbf{C}{{sup|{\rm T}|tex}}|{{det|\mathbf{A}|tex}}|tex}} {{=}}  <!--

-->{{frac|
     {{matrix| 
       ''C''{{sub|1,1|tex}}      &&  ''C''{{sub|1,2|tex}}      && {{...|cdots|tex}}  && ''C''{{sub|1,''n''|tex}}      \\       
       ''C''{{sub|2,1|tex}}      &&  ''C''{{sub|2,2|tex}}      && {{...|cdots|tex}}  && ''C''{{sub|2,''n''|tex}}      \\      
       {{...|vdots|tex}}         &&  {{...|vdots|tex}}         && {{...|ddots|tex}}  && {{...|vdots|tex}}             \\ 
       ''C''{{sub|''n'',1|tex}}  &&  ''C''{{sub|''n'',2|tex}}  && {{...|cdots|tex}}  && ''C''{{sub|''n'',''n''|tex}}       
     ||tex}}{{sup|{\rm T}|tex}}
   |
     {{matrix| 
       ''a''{{sub|1,1|tex}}      &&  ''a''{{sub|1,2|tex}}      && {{...|cdots|tex}}  && ''a''{{sub|1,''n''|tex}}      \\       
       ''a''{{sub|2,1|tex}}      &&  ''a''{{sub|2,2|tex}}      && {{...|cdots|tex}}  && ''a''{{sub|2,''n''|tex}}      \\      
       {{...|vdots|tex}}         &&  {{...|vdots|tex}}         && {{...|ddots|tex}}  && {{...|vdots|tex}}             \\ 
       ''a''{{sub|''n'',1|tex}}  &&  ''a''{{sub|''n'',2|tex}}  && {{...|cdots|tex}}  && ''a''{{sub|''n'',''n''|tex}}       
     |det|tex}}
   |TEX}},

|$$}}{{nl}}

where {{math|{{det|\mathbf{A}|tex}}|$}} is the [[determinant]] of {{math|\mathbf{A}|$}}, {{math|\mathbf{C}|$}} is the [[matrix of cofactors]] of <!--
-->{{math|\mathbf{A}|$}}, and {{math|\mathbf{C}{{sup|{\rm T}|tex}}|$}} represents the matrix [[transpose]] of {{math|\mathbf{C}|$}}.

yields the display style LaTeX matrix inverse formula

     

where is the determinant of, is the matrix of cofactors of, and represents the matrix transpose of.

Nested matrices

The code

{{indent}}{{math|

{{matrix|

{{matrix|       
  ''a'' && ''b'' \\       
  ''c'' && ''d''           
}}

&&

{{matrix|       
  ''e'' && ''f'' \\       
  ''g'' && ''h''           
}}

\\

0

&&

{{matrix|       
  ''i'' && ''j'' \\       
  ''k'' && ''l''           
}}

}}

|&&}}

yields the display style HTML+CSS

     
a   b
c   d
 
e   f
g   h

0

 
i   j
k   l

The code

{{indent}}{{math|

{{matrix|

{{matrix|       
  ''a'' && ''b'' \\       
  ''c'' && ''d''           
|tex}}

&&

{{matrix|       
  ''e'' && ''f'' \\       
  ''g'' && ''h''           
|tex}}

\\

0

&&

{{matrix|       
  ''i'' && ''j'' \\       
  ''k'' && ''l''           
|tex}}

|tex}}

|$$}}

yields the display style LaTeX

     

See also

  • {{det}} (matrix determinant template)