我如何绘制以下描述某些向量和矩阵运算的图形。
更新:我稍微修改了@rpapa 的解决方案并得到以下内容。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit,backgrounds}
\usepackage{float}
\usepackage{caption}
\begin{document}
\tikzstyle{background}=[rectangle, fill=green!85, inner sep=0.1cm, rounded corners=2.5mm, line width=0.3mm]
\newcommand{\Vcol}[2]{
\foreach \nn in {1,2,...,5}{
\node[circle,draw,fill=#2, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\newcommand{\VcolS}[3]{
\foreach \nn in {1,2,...,5}{
\node[circle,draw, shade, left color=#2, right color=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\newcommand{\VcolD}[3]{
\node[circle,draw,fill=#2, line width=0.25mm] (#1-1) at (0,{-1.5*1 em}) {};
\foreach \nn in {2,...,5}{
\node[circle,draw,fill=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\newcommand{\Mat}[2]{
\foreach \nr in {1,2,...,5}{
\foreach \nc in {1,2,...,5}{
\node[circle,draw,fill=#2, line width=0.25mm] (#1-\nr-\nc) at ({1.5*\nr em},{-1.5*\nc em}) {};
}
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1-1) (#1-5-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\begin{tikzpicture}
\begin{scope}[xshift=0]
\Vcol{a}{yellow!85}
\end{scope}
\begin{scope}[xshift=3em]
\Vcol{b}{red!85}
\end{scope}
\begin{scope}[xshift=6em]
\VcolS{c}{yellow}{red}
\end{scope}
\begin{scope}[xshift=9em]
\Mat{e}{yellow!85}
\end{scope}
\begin{scope}[xshift=19.5em]
\Vcol{b}{red!85}
\end{scope}
\begin{scope}[xshift=22.5em]
\VcolD{b}{brown!85}{red!45}
\end{scope}
\end{tikzpicture}
\end{document}
答案1
以下是 tikz 的开头
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fit}
\usepackage{caption}
\begin{document}
\newcommand{\Vcol}[2]{
\foreach \nn in {1,2,...,5}{
\node[circle,draw, fill=#2](#1-\nn) at (0,{-1.5*\nn em}){};
}
\node[fit=(#1-1) (#1-5), draw](col-#1){};
}
\begin{tikzpicture}
\begin{scope}[xshift=0]
\Vcol{a}{red}
\end{scope}
\begin{scope}[xshift=3em]
\Vcol{b}{green}
\end{scope}
\begin{scope}[xshift=6em]
\Vcol{b}{green!50!red}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这是绘制箭头的代码的补充
\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit,backgrounds}
\usepackage{float}
\usepackage{caption}
\begin{document}
\tikzstyle{background}=[rectangle, fill=green!85, inner sep=0.1cm, rounded corners=2.5mm, line width=0.3mm]
\newcommand{\Vcol}[2]{
\foreach \nn in {1,2,...,5}{
\node[circle,draw,fill=#2, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\newcommand{\VcolS}[3]{
\foreach \nn in {1,2,...,5}{
\node[circle,draw, shade, left color=#2, right color=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\newcommand{\VcolD}[3]{
\node[circle,draw,fill=#2, line width=0.25mm] (#1-1) at (0,{-1.5*1 em}) {};
\foreach \nn in {2,...,5}{
\node[circle,draw,fill=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\newcommand{\Mat}[2]{
\foreach \nr in {1,2,...,5}{
\foreach \nc in {1,2,...,5}{
\node[circle,draw,fill=#2, line width=0.25mm] (#1-\nr-\nc) at ({1.5*\nr em},{-1.5*\nc em}) {};
}
}
\begin{pgfonlayer}{background}
\node [background, fit=(#1-1-1) (#1-5-5), draw] (col-#1) {};
\end{pgfonlayer}
}
\begin{tikzpicture}
\begin{scope}[xshift=0]
\Vcol{a}{yellow!85}
\end{scope}
\begin{scope}[xshift=3em]
\Vcol{b}{red!85}
\end{scope}
\begin{scope}[xshift=6em]
\VcolS{c}{yellow}{red}
\end{scope}
\begin{scope}[xshift=9em]
\Mat{e}{yellow!85}
\end{scope}
\begin{scope}[xshift=19.5em]
\Vcol{f}{red!85}
\end{scope}
\begin{scope}[xshift=22.5em]
\VcolD{g}{brown!85}{red!45}
\end{scope}
\foreach \i in{1,2,...,5}{
\draw[<->,blue,thick](a-\i)--(b-\i);}
\node [font=\large\bfseries] at ($(b-3)!0.5!(c-3)$){=};
\node [font=\large\bfseries] at ($(f-3)!0.5!(g-3)$){=};
\draw[->,blue,thick](e-5-1.center)--(e-5-5.center)--(f-5);
\draw[->,blue,thick](e-4-1.center)--(e-4-4.center)--($(e-5-4.center)+(-0.05,0)$)arc(180:00:0.05)--(f-4);
\draw[->,blue,thick](e-3-1.center)--(e-3-3.center)--($(e-4-3.center)+(-0.05,0)$)arc(180:00:0.05)--($(e-5-3.center)+(-0.05,0)$)arc(180:00:0.05)--(f-3);
\draw[->,blue,thick](e-2-1.center)--(e-2-2.center)--($(e-3-2.center)+(-0.05,0)$)arc(180:00:0.05)--($(e-4-2.center)+(-0.05,0)$)arc(180:00:0.05)--($(e-5-2.center)+(-0.05,0)$)arc(180:00:0.05)--(f-2);
\draw[->,blue,thick](e-1-1.center)--+(0,0.5)-|(f-1.center);
\end{tikzpicture}
\end{document}