![矩阵向量乘法的 tikz 可视化](https://linux22.com/image/450360/%E7%9F%A9%E9%98%B5%E5%90%91%E9%87%8F%E4%B9%98%E6%B3%95%E7%9A%84%20tikz%20%E5%8F%AF%E8%A7%86%E5%8C%96.png)
答案1
以下是使用以下方法进行的可视化tikz
:
您可以调整这些值来获得更大或更小的向量等等。以下是代码:
\documentclass{article}
\usepackage{mathtools,amssymb}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}
\begin{document}
\begin{tikzpicture}[scale=1]
\filldraw[color=gray!60] (0,0) rectangle (0.6,2); % y vector box
\draw[color=black] (0.9,1.05) -- (1.2,1.05); % equal sign
\draw[color=black] (0.9,0.95) -- (1.2,0.95); % equal sign second line
\filldraw[color=gray!60] (1.4,-0.5) rectangle (3.4,2.5); % matrix box
\filldraw[color=gray!60] (3.8,0) rectangle (4.4,2); % x vector box
\begin{scope}[transparency group,opacity=.6] % blue lines
\filldraw[color=blue!40] (3.8,0) rectangle (4.4,2);
\filldraw[color=blue!40] (1.4,2.5) rectangle (3.4,1.9);
\filldraw[color=blue!40] (1.4,1.3) rectangle (3.4,0.7);
\end{scope}
% letters y, x and A:
\node at (0.3,1){y};
\node at (4.1,1){x};
\node at (2.4,1){A};
% curly braces to illustrate vector and matrix size:
\draw[decoration={brace,mirror,raise=5pt},decorate]
(4.5,0) -- node[right=6pt] {$n$} (4.5,2); % x vector size (vertical)
\draw[decoration={brace,mirror,raise=5pt},decorate]
(1.4,-0.6) -- node[below=6pt] {$n$} (3.4,-0.6); % A matrix size (horizontal)
\end{tikzpicture}
\end{document}
我按照要求说明了矩阵和向量之间的乘法,而不是图中所示的稀疏性。要更改这一点,只需更改蓝线即可。