pmatrix 方程中的编号

pmatrix 方程中的编号
    \par Here is an example with solving equation using the Gauss elimination method\newline
\emph{Example: Solve this  system of linear equations using the method of gaussian elimination} \cite{Analyze-math}\newline
\begin{equation}
\left\{
\begin{array}{lcl}   
    x  + y  - z & = & -3 \\
    -x  + 3y  + 2z  & = & 5 \\
    x + 5z  & = & 9
\end{array}
\right.
\end{equation}
\emph{first i will start to write it in operation row}
\begin{equation}
A
\begin{pmatrix}
1 & 1 & - 1 \\
-1 & 3 & 2 \\
1 & 5 & 0
\end{pmatrix}
X
\begin{pmatrix}
x \\ y \\ z \\ 
\end{pmatrix}
B
\begin{pmatrix}
-3 \\ 5 \\ 9 \\ 
\end{pmatrix}
\end{equation}
\\ 

\begin{enumerate}
    \item First you can write it in augmented matrix 
    \begin{equation}
    \begin{bmatrix}
        1 & 1 & - 1 &|& -3\\
        -1 & 3 & 2  &|& 5 \\
        1 & 0 & 5  &|& 9
    \end{bmatrix}
     \end{equation}
    \item Add (1) to row (2) \textcolor{red}{$R_1+R_2$}
   \begin{equation}
    \begin{bmatrix}
     1 & 1 & - 1 &|& -3\\
     0 & 4 & 1  &|& 2 \\
     1 & 0 & 5  &|& 9
     \end{bmatrix}
      \end{equation}    
      \item Add -1 times row (1) to row (3)
    \[
    \begin{equation}
     \begin{bmatrix}
      1 & 1 & - 1 &|& -3\\
      0 & 4 & 1  &|& 2 \\
      0 & -1 & 6  &|& 12
      \end{bmatrix}
      \color{red}{\begin{matrix}
        \\
        \\
        R_3 - R_1\\}
        \end{matrix} 
        \end{equation}  


      \item Interchange rows (2) and (3)
      \[\begin{bmatrix}
        1 & 1 & - 1 &|& -3\\
        0 & -1 & 6  &|& 12\\
        0 & 4 & 1  &|& 2        
      \end{bmatrix}
      \color{red}{\begin{matrix}
        \\
        R_3\\
        R_2\\
        \end{matrix}}\]
      \item Add 4 times row (2) to row (3)
     \[ \begin{bmatrix}
        1 & 1 & - 1 &|& -3\\
        0 & -1 & 6  &|& 12\\
        0 & 0 & 25  &|& 50  
      \end{bmatrix}
      \color{red}{\begin{matrix}
        \\
        \\
        R_3 + 4R_2\\
        \end{matrix}}\]
      \item Multiply all terms in row (2) by -1
     \[ \begin{bmatrix}
        1 & 1 & - 1 &|& -3\\
        0 & 1 & - 6  &|& - 12\\
        0 & 0 & 25  &|& 50  
      \end{bmatrix} 
     \color{red}{\begin{matrix}
        \\
        -R_2\\
        \\
        \end{matrix}}\]
     And finally:
     \item  Multiply all terms in row (3) by 1/25
     \[\begin{bmatrix}
        1 & 1 & - 1 &|& -3\\
        0 & 1 & - 6  &|& - 12\\
        0 & 0 & 1  &|& 2    
     \end{bmatrix}
   \color{red}{\begin{matrix}
        \\
        \\
        (1/25)R_3\\
   \end{matrix}}\]

我使用 TeX Studio。我尝试给 pmatrix 提供一个数字,但它没有接受。它说你忘记了一个额外的 '}' 我的代码有什么问题?+

答案1

在删除代码中的错误(虚假\]等;请参阅问题下方的评论)并使用该nicematrix包后,我将您的文档示例重写为以下 MWE(最小工作示例):

\documentclass{article}
\usepackage{geometry} % enable to write all document example on one page
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}
\begingroup
\NiceMatrixOptions{code-for-last-col  = \color{red}}
%%%%
Here is an example with solving equation using the Gauss elimination method\newline
\emph{Example: Solve this  system of linear equations using the method of Gaussian elimination} \cite{Analyze-math}
    \begin{equation}
    \setlength\arraycolsep{1pt}
\left\{
    \begin{array}{lcr}
 x +  y -  z    & = & -3 \\
-x + 3y + 2z    & = &  5 \\
 x + 5z         & = &  9
\end{array}
\right.
\end{equation}
\emph{first i will start to write it in operation row}
    \begin{equation}
A   \begin{pNiceArray}{RRR}
 1 & 1 & -1 \\
-1 & 3 &  2 \\
 1 & 5 &  0
    \end{pNiceArray}   
 X  \begin{pNiceArray}{RRR}
    x \\ y \\ z \\
    \end{pNiceArray}    
B   \begin{pNiceArray}{RRR}
    -3 \\ 5 \\ 9 \\
    \end{pNiceArray}
    \end{equation}

    \begin{enumerate}
\item First you can write it in augmented matrix
    \begin{equation}
\begin{bNiceArray}{RRRCR}
        1 & 1 & - 1  &|& -3 \\
       -1 & 3 &   2  &|&  5 \\
        1 & 0 &   5  &|&  9
\end{bNiceArray}
     \end{equation}
\item Add (1) to row (2) \textcolor{red}{$R_1+R_2$}
    \begin{equation}
\begin{bNiceArray}{RRRCR}
     1 & 1 & - 1 &|& -3 \\
     0 & 4 &  1  &|&  2 \\
     1 & 0 &  5  &|&  9
\end{bNiceArray}
    \end{equation}
\item Add -1 times row (1) to row (3)
    \begin{equation}
\begin{bNiceArray}{RRRCR}[last-col]
      1 &  1 & - 1 &|& -3 & \\
      0 &  4 &   1 &|&  2 & \\
      0 & -1 &   6 &|& 12 & R_3 - R_1
\end{bNiceArray}
    \end{equation}
\item Interchange rows (2) and (3)
      \[
\begin{bNiceArray}{RRRCR}[last-col]
    1 &  1 & -1 &|& -3 &        \\
    0 & -1 &  6 &|& 12 & R_3    \\
    0 &  4 &  1 &|&  2 & R_2
\end{bNiceArray}
    \]
\item Add 4 times row (2) to row (3)
     \[ 
\begin{bNiceArray}{RRRCR}[last-col]
1 &  1 & -1 &|& -3  &           \\
0 & -1 &  6 &|& 12  &           \\
0 &  0 & 25 &|& 50  & R_3 + 4R_2
\end{bNiceArray}
      \]
\item Multiply all terms in row (2) by -1
     \[
\begin{bNiceArray}{RRRCR}[last-col]
1 & 1 & -1  &|&  -3 &           \\
0 & 1 & -6  &|& -12 & -R_2      \\
0 & 0 & 25  &|&  50 &           
\end{bNiceArray}
    \]     
     \item  And finally multiply all terms in row (3) by 1/25
     \[
\begin{bNiceArray}{RRRCR}[last-col]
1 & 1 & -1  &|& - 3 &           \\
0 & 1 & -6  &|& -12 &           \\
0 & 0 &  1  &|&   2 & (1/25)R_3
\end{bNiceArray}
    \]
\end{enumerate}
\endgroup
\end{document}

从您的文档示例中可以看出,您只对前五个矩阵进行了编号。上面的 MWE 遵循此编号。如果您希望对所有矩阵进行编号,那么在其余矩阵中,您需要分别将\[和替换\]\begin{equation}\end{equation}

使用包bNiceArray中定义的nicematrix可以更简洁地将带有标签的矩阵写入行,这表明已执行的操作。

在此处输入图片描述

为了获得上述结果,您需要至少编译 MWE 两次。

相关内容