以下矩阵乘积如何

以下矩阵乘积如何

我对在 LaTeX 中起草以下内容很感兴趣。我对此并不十分擅长,我将附上生成向量和矩阵的代码,然后附上我想要的输出。

代码:

\begin{align}
  \begin{pmatrix}a_1\\a_2\\\vdots\\a_k\end{pmatrix}
  \begin{pmatrix}\varepsilon_1&0&\ldots&0\\ 0&\varepsilon_2&\ldots&0\\0&0&\ldots&0\\0&0&\ldots&\varepsilon_N\\ 
   \end{pmatrix}
\end{align}

输出:

在此处输入图片描述

所以我想要的是向量 (a1,..,ak) 的第一个和最后一个元素上的一个圆,以及一个从 a1 指向矩阵第一行矩形的箭头,最后一行也是一样。如果圆的画法不好,我很抱歉,我已经手动完成了,当然最好用更好的方式绘制圆草图。

答案1

使用{NiceArray}nicematrixTikz。

\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{fit}

\begin{document}

$\begin{NiceArray}{(c)(cccc)}[create-medium-nodes,nullify-dots]
a_1    & \epsilon_1 & 0          & \cdots & 0 \\
a_2    & 0          & \epsilon_2 & \cdots & 0 \\
\Vdots & 0          & 0          & \cdots & 0 \\
a_k    & 0          & 0          & \cdots & \epsilon_n \\
\CodeAfter
  \begin{tikzpicture} [cyan,inner sep=1pt]
    \node [circle,draw,fit=(1-1)] (A) {} ;
    \node [circle,draw,fit=(4-1)] (B) {} ;
    \node [draw,rounded corners, fit = (1-2-medium) (1-5-medium)] (C) {} ;
    \node [draw,rounded corners, fit = (4-2-medium) (4-5-medium)] (D) {} ;
    \draw [->] (A.north) to [bend left] (C.north west) ; 
    \draw [->] (B.south) to [bend right] (D.south west) ; 
  \end{tikzpicture}
\end{NiceArray}$

\end{document}

您需要多次编译(因为nicematrix在后台使用 PGF/Tikz 节点)。

上述代码的输出

答案2

采用纯 TiZ:

在此处输入图片描述

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                fit,
                matrix,
                positioning}
                
\begin{document}
    \begin{tikzpicture}[
node distance = 7mm,
FIT/.style = {inner sep=1pt, draw=red, fit=#1},
arr/.style = {draw=blue, -Straight Barb,semithick},
M/.style = {matrix of math nodes,
            nodes= {minimum size=1em, inner sep=1pt, anchor=base},
            column sep=0pt,
            row sep=3pt,
            left delimiter=(,
            right delimiter=),
            inner sep=2pt}    
                        ]
\matrix (m) [M] 
{|[circle,draw=red]| a_1\\
    a_2\\ \vdots \\ 
 |[circle,draw=red]|a_k\\};
%
\matrix (n) [M,right=of m]
{\varepsilon_1  & 0             & \ldots    & 0             \\
    0           &\varepsilon_2  & \ldots    & 0             \\
    0           & 0             & \ldots    & 0             \\
    0           & 0             & \ldots    & \varepsilon_N \\
};
\node (n1) [FIT=(n-1-1) (n-1-4)] {};
\node (n2) [FIT=(n-4-1) (n-4-4)] {};
%
\draw[arr] (m-1-1) to[bend  left=45] (n1);
\draw[arr] (m-4-1) to[bend right=45] (n2);
    \end{tikzpicture}
\end{document}

答案3

现在有了简单的 TiZ 解决方案,使用tikzmark库,正如我的评论所建议的那样(注意:需要编译几次才能计算然后正确显示)。

矩阵上的节点

\documentclass[12pt]{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{tikzmark,fit}

\begin{document}
    
    \begin{align}
        \begin{pmatrix}\tikzmarknode{A1}{a_1}\\a_2\\\vdots\\\tikzmarknode{AK}{a_k}\end{pmatrix}
        \begin{pmatrix}
            \tikzmarknode{E1}{\varepsilon_1}&0&\ldots&\tikzmarknode{0A}{0}\\
            0&\varepsilon_2&\ldots&0\\
            0&0&\ldots&0\\
            \tikzmarknode{0B}{0}&0&\ldots&\tikzmarknode{EN}{\varepsilon_N}\\ 
        \end{pmatrix}
    \end{align}
    
    \tikzset{
        circ/.style={inner sep=6pt, outer sep=0pt, line width=1pt, circle, draw=cyan},
        rect/.style={inner sep=2pt, outer sep=0pt, line width=1pt, rounded corners=5pt, draw=cyan}
        }
    
    \begin{tikzpicture}[remember picture,overlay,cyan]
        \node[circ] (a1) at (A1) {};
        \node[circ] (ak) at (AK) {};
        
        \node[rect,fit=(E1)(0A)] (line1) {};
        \node[rect,fit=(EN)(0B)] (line4) {};
        
        \draw[-latex,line width=1pt] (a1.north) to[out=60,in=120] (line1.160);
        \draw[-latex,line width=1pt] (ak.south) to[out=-60,in=-120] (line4.-160);
        
    \end{tikzpicture}

\end{document}

答案4

以下是使用简单代码的可能性pstricks

\documentclass[svgnames]{article}
\usepackage{amsmath}
\usepackage{pst-node} 

\begin{document}

    \[ \psset{linecolor=LightSteelBlue, linearc=0.1, boxsize=0.25, nodesep=1.5pt, arrowinset=0.12} \begin{pmatrix}\circlenode{a1}{a_1}\\a_2\\\vdots\\\circlenode{ak}{a_k}\end{pmatrix}
    \begin{pmatrix}\,\Rnode{e1}{\varepsilon_1}&0&\ldots&\Rnode{f1}{0}\\ \, 0 & \varepsilon_2&\ldots&0\\ \,0&0&\ldots&0\\ \,\Rnode{fN}{0}&0&\ldots&\Rnode{eN}{\varepsilon_N}\\
    \end{pmatrix}
    \ncbox{e1}{f1}\ncbox{eN}{fN}
    \nccurve[angle=90, nodesepA=0, nodesepB=5pt]{->}{a1}{e1}
    \nccurve[angle=-90, nodesepA=0, nodesepB=3pt]{->}{ak}{fN}
    \]%

\结束{文档} 在此处输入图片描述

相关内容