3

I have the following line of code:

\begin{equation}
X= \begin{bmatrix}
 ($1 - a_{11}$) & -a_{12} & -a_{13} & -a_{1n} \\
-a_{21} & (1-$a_{22}$) & -a_{23} & -a_{2n} \\
-a_{31} & -a_{32} & (1-$a_{33}$) & -a_{34} \\
-a_{41} & -a_{42} & -a_{43} & (1-$a_{nn}$)
\end{bmatrix}  
\end{equation}

($1 - a_{11}$)

Which compiles to:

enter image description here

Whereas (1-a11) compiles properly outside the matrix, it does not work inside.

Can anyone give me a hint what I am missing here?

2
  • 1
    Remove all $ inside matrix. It is already in math environment!
    – Zarko
    Feb 19 at 16:15
  • Off-topic: Why do you encase the diagonal elements in parentheses?
    – Mico
    Feb 19 at 16:44

2 Answers 2

4
  • Please always provide MWE (Minimal Working Example), a smallest complete document that reproduces the problem. It should contain all necessary packages and definitions required to run the example, but nothing more than that.
  • Your matrix is already in math environment, therefore $ just discontinue this environment. So, you get wrong result (errors).
  • As I noted in my comment, juste remove all $ from matric and you will get:

enter image description here

MWE:

\documentclass[margin=3mm, varwidth]{standalone}
\usepackage{amsmath}

\begin{document}
\begin{equation}
X = \begin{bmatrix}
 (1 - a_{11}) & -a_{12}     & -a_{13}    & -a_{1n} \\
      -a_{21} & (1-a_{22})  & -a_{23}    & -a_{2n} \\
      -a_{31} & -a_{32}     & (1-a_{33}) & -a_{34} \\
      -a_{41} & -a_{42}     & -a_{43}    & (1-a_{nn})
    \end{bmatrix}
\end{equation}
\end{document}

Edit:

  • I wonder, why terms in matrix diagonal are in parent (also see @Mico comment below). Do you have some special reason for this?
  • Without them matrix is just fine:

enter image description here

MWE:

\documentclass[margin=3mm, varwidth]{standalone}
\usepackage{amsmath}

\begin{document}
\begin{equation}
X = \begin{bmatrix}
 1 - a_{11} & -a_{12}   & -a_{13}   & -a_{1n} \\
    -a_{21} & 1-a_{22}  & -a_{23}   & -a_{2n} \\
    -a_{31} & -a_{32}   & 1-a_{33}  & -a_{34} \\
    -a_{41} & -a_{42}   & -a_{43}   & 1-a_{nn}
    \end{bmatrix}
\end{equation}
\end{document}
3
  • Thank you very much! Feb 19 at 16:29
  • +1. I'd also remove the parentheses placed around the elements on the main diagonal.
    – Mico
    Feb 19 at 16:45
  • 1
    @Mico, I wonder why diagonal terms are in parenthesis. I agree with you. I'll add version washout them, ASAP.
    – Zarko
    Feb 19 at 16:52
4

In addition to applying the fix suggested in @Zarko's answer, you should also fix the following issue: You should either a 4x4 matrix and replace all intances of n with 4, or display a more general nxn matrix, replace all instances of 4 with n, and add a row and a column to the matrix.

enter image description here

\documentclass{article}
\usepackage{mathtools} % for \shortintertext macro
\begin{document}

\begin{align}
X &= \begin{bmatrix}
1-a_{11} &  -a_{12} &  -a_{13} &  -a_{14} \\
 -a_{21} & 1-a_{22} &  -a_{23} &  -a_{24} \\
 -a_{31} &  -a_{32} & 1-a_{33} &  -a_{34} \\
 -a_{41} &  -a_{42} &  -a_{43} & 1-a_{44}
\end{bmatrix}  \\
\shortintertext{or}
X &= \begin{bmatrix}
1-a_{11} &  -a_{12} &  -a_{13} & \dots  & -a_{1n} \\
 -a_{21} & 1-a_{22} &  -a_{23} & \dots  & -a_{2n} \\
 -a_{31} &  -a_{32} & 1-a_{33} & \dots  & -a_{3n} \\
 \vdots  &  \vdots  &  \vdots  & \ddots &  \vdots \\
 -a_{n1} &  -a_{n2} &  -a_{n3} & \dots  & 1-a_{nn}
\end{bmatrix}  
\end{align}
\end{document}
1
  • good point! +1!
    – Zarko
    Feb 19 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .