以最佳方式对齐多个矩阵?

以最佳方式对齐多个矩阵?

这是我第一次在线性代数和矩阵方面做作业。如何以最佳方式对齐如下所示的矩阵? 在此处输入图片描述

代码如下:

\newenvironment{sysmatrix}[1]
 {\left(\begin{array}{@{}#1@{}}}
 {\end{array}\right)}
\newcommand{\ro}[1]{%
  \xrightarrow{\mathmakebox[\rowidth]{#1}}%
}
\newlength{\rowidth}% row operation width
\AtBeginDocument{\setlength{\rowidth}{4em}}

\begin{equation}
  \begin{array}{rcl}
  {
    \left(\!\!\!\!
    \begin{array}{rrr|r}
     1 &  a & 2 & a \\
     0 &  1 & 0 & \frac{-a^2}{a^2-2} \\
     0 & 3-a & -2 & 2-a 
    \end{array}
    \!\!\right)
  } 
  & 
  \xymatrix@C=15ex{ 
    \ar[r]^-{\small
      \begin{array}{r}
        \mathbf{r}_1 \rightarrow \mathbf{r}_1 - \mathbf{r}_2a \\
         \mathbf{r}_3 \rightarrow \mathbf{r}_3 - \mathbf{r}_2(3-a) \\
      \end{array}        
    } &
  } 
  & 
  {
    \left(\!\!\!\!
    \begin{array}{rrr|r}
     1  &  0 & 2 & -\frac{2a}{a^2-2}  \\
     0 &  1 & 0 & \frac{a^2}{a^2-2} \\
     0 & 0 & -2 & \frac{1}{a^2-2}(-a^2+2a-4)  
    \end{array}
    \!\!\right)
  } 
\end{array}\bigskip
\end{equation}

\begin{equation}
  \begin{array}{rcl}
  {
    \left(\!\!\!\!
    \begin{array}{rrr|r}
     1  &  0 & 2 & -\frac{2a}{a^2-2}  \\
     0 &  1 & 0 & \frac{a^2}{a^2-2} \\
     0 & 0 & -2 & \frac{1}{a^2-2}(-a^2+2a-4)  
    \end{array}
    \!\!\right)
  } 
  & 
  \xymatrix@C=16ex{ 
    \ar[r]^-{\small
      \begin{array}{r}
         \mathbf{r}_1 \rightarrow \mathbf{r}_1 + \mathbf{r}_3 \\
         \mathbf{r}_3 \rightarrow \frac{\mathbf{r}_3}{-2}
      \end{array}        
    } &
  } 
  & 
  {
    \left(\!\!\!\!
    \begin{array}{rrr|r}
     1 &  0 & 0 & -\frac{a^2+4}{a^2-2}  \\
     0 &  1 & 0 & \frac{a^2}{a^2-2} \\
     0 &  0 & 1 & \frac{\frac{a^2}{2}-a+2}{a^2-2}
    \end{array}
    \!\!\right)
  } 
\end{array}
\end{equation}

答案1

\documentclass[a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{array}
\usepackage{amsmath}
\begin{document}

\begin{align}
    \left(\begin{array}{ccc|>{\displaystyle}c}
    1 &  a & 2 & a \\
    0 &  1 & 0 & \frac{-a^2}{a^2-2} \\
    0 & 3-a & -2 & 2-a 
    \end{array}\right) 
& \xrightarrow{\small
        \begin{array}{r}
        \mathbf{r}_1 \rightarrow \mathbf{r}_1 - \mathbf{r}_2a \\
        \mathbf{r}_3 \rightarrow \mathbf{r}_3 - \mathbf{r}_2(3-a) \\
        \end{array}} 
    \left(\begin{array}{ccc|>{\displaystyle}c}
    1  &  0 & 2 & -\frac{2a}{a^2-2}  \\
    0 &  1 & 0 & \frac{a^2}{a^2-2} \\
    0 & 0 & -2 & \frac{1}{a^2-2}(-a^2+2a-4)  
    \end{array}\right)  \\[10pt]
\left(\begin{array}{rrr|>{\displaystyle}r}
    1  &  0 & 2 & -\frac{2a}{a^2-2}  \\
    0 &  1 & 0 & \frac{a^2}{a^2-2} \\
    0 & 0 & -2 & \frac{1}{a^2-2}(-a^2+2a-4)  
    \end{array}\right)
&  \xrightarrow[\hphantom{\textstyle~\mathbf{r}_3 \rightarrow \mathbf{r}_3 - \mathbf{r}_2(3-a)}]%
      {\small
        \begin{array}{r}
        \mathbf{r}_1 \rightarrow \mathbf{r}_1 + \mathbf{r}_3 \\
        \mathbf{r}_3 \rightarrow \frac{\mathbf{r}_3}{-2}
        \end{array}}
\left(\begin{array}{rrr|>{\displaystyle}r}
    1 &  0 & 0 & -\frac{a^2+4}{a^2-2}  \\
    0 &  1 & 0 & \frac{a^2}{a^2-2} \\
    0 &  0 & 1 & \frac{\frac{a^2}{2}-a+2}{a^2-2}
    \end{array}\right) 
\end{align}

\end{document}

在此处输入图片描述

答案2

另一个可能的解决方案是使用包,速度更快一些spalign

在此处输入图片描述

\documentclass[a4paper,12pt]{article}
\usepackage[margin=2.2cm]{geometry}
\usepackage{mathtools}
\usepackage{spalign}

\begin{document}
\begin{equation}
\spalignaugmat[c]{1 a 2 a; 0 1 0 \dfrac{-a^2}{a^2-2}; 0 3-a -2 2-a} \xrightarrow{\begin{matrix}
\mathbf{r}_1 \rightarrow \mathbf{r}_1 - \mathbf{r}_2a \\
        \mathbf{r}_3 \rightarrow \mathbf{r}_3 - \mathbf{r}_2(3-a) 
\end{matrix}}{} 
  \spalignaugmat{1 0 2 -\dfrac{2a}{a^2-2}; 0 1 0 \dfrac{a^2}{a^2-2}; 0 0 -2 \dfrac{1}{a^2-2}(-a^2+2a-4)}    
\end{equation}

\begin{equation}
\spalignaugmat[c]{1 0 2 -\dfrac{2a}{a^2-2}; 0 1 0  \dfrac{a^2}{a^2-2}; 0 0 -2 \dfrac{1}{a^2-2}(-a^2+2a-4)} \xrightarrow{\begin{matrix}
\mathbf{r}_1 \rightarrow \mathbf{r}_1 + \mathbf{r}_3 \\
        \mathbf{r}_3 \rightarrow -\frac{1}{2}\mathbf{r}_3
\end{matrix}}{}    
  \spalignaugmat{1 0 0 -\dfrac{a^2+4}{a^2-2}; 0 1 0 \dfrac{a^2}{a^2-2}; 0 0 1 \dfrac{\frac{a^2}{2}-a+2}{a^2-2}}    
\end{equation}
\[\mathbf{S}^{\ast}=\spalignaugmat[c]{1 0 0 -\frac{a^2+4}{a^2-2};0 1 0 \frac{a^2}{a^2-2};  0 0 1 \frac{\frac{a^2}{2}-a+2}{a^2-2}}\]

\end{document}

相关内容