TikZ 的 MIMO(多输入,多输出)框图

TikZ 的 MIMO(多输入,多输出)框图

我正在开发一个控制系统项目,需要一些帮助来使用 LaTeX 中的 TikZ 创建框图。我附上了一张我试图重新创建的框图的图片。如您所见,它包括一个具有多个输入和输出的反馈回路,并且有两个矩阵 G(s) 和 C(s) 需要在块中表示。

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}
\tikzstyle{block} = [draw, fill=white, rectangle, 
    minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=white, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum, node distance=4cm] (controller) {$C(s)= \begin{bmatrix}     c_{11}(s) & c_{12}(s) & \cdots & c_{1n}(s) \\ c_{21}(s) & c_{22}(s) & \cdots & c_{2n}(s) \\ \vdots & \vdots & \ddots & \vdots \\ c_{n1}(s) & c_{n2}(s) & \cdots & c_{nn}(s) \end{bmatrix}$};
    \node [block, right of=controller, node distance=7cm] (system) {$G(s)= \begin{bmatrix} g_{11}(s) & g_{12}(s) & \cdots & g_{1n}(s) \\ g_{21}(s) & g_{22}(s) & \cdots & g_{2n}(s) \\ \vdots & \vdots & \ddots & \vdots \\ g_{n1}(s) & g_{n2}(s) & \cdots & g_{nn}(s) \end{bmatrix}$};

    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system, node distance=5cm] (output) {};
    \coordinate [below of=u] (measurements) {};

    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {$e$} (controller);
    \draw [->] (system) -- node [name=y] {$y$}(output);

    \draw [-] (y) |- (measurements);

    \draw [->] (measurements) -| node [near end] {$y_m$} (sum);

\end{tikzpicture}
\end{document}

以下是我仅使用一输入一输出的尝试: 在此处输入图片描述

但我想要如下图所示的多输入、多输出框图: 在此处输入图片描述

答案1

tikz 的特色之一是绘制重复的事物,这里有一个带有一些其他嵌套选项和样式定义的实现,有几种方法可以做这件事或另一件事。

结果:

在此处输入图片描述

梅威瑟:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{shapes,arrows,positioning,calc}
\usepackage{circuitikz}

\begin{document}
    \begin{tikzpicture}[
        %Tikz picture environment CFG
        >=latex',
        %Styles
        block/.style={
            draw,
            fill=white,
            rectangle, 
            minimum height=3em,
            minimum width=6em
        },
        sum/.style={
            draw,
            circle,
            fill=white,
            minimum size=2em,
            scale=0.75,
            transform shape,
            label={[label distance=-1.25em,scale=0.7]180:+},
            label={[label distance=-1em,scale=1]-90:-}
        }
    ]
    %Define some variables to reuse.
    \def\Xdist{1cm}
    \def\Ydist{1cm}
    \def\Controller{
        $C(s)=
        \begin{bmatrix}
            c_{11}(s) & c_{12}(s) & \cdots & c_{1n}(s) \\
            c_{21}(s) & c_{22}(s) & \cdots & c_{2n}(s) \\
            \vdots & \vdots & \ddots & \vdots \\
            c_{n1}(s) & c_{n2}(s) & \cdots & c_{nn}(s)
        \end{bmatrix}
        $
    }
    \def\System{
        $G(s)=
        \begin{bmatrix}
            g_{11}(s) & g_{12}(s) & \cdots & g_{1n}(s) \\
            g_{21}(s) & g_{22}(s) & \cdots & g_{2n}(s) \\
            \vdots & \vdots & \ddots & \vdots \\
            g_{n1}(s) & g_{n2}(s) & \cdots & g_{nn}(s)
        \end{bmatrix}
        $
    }
    %Starting to draw the thing.
    %\node[node style, position= distance of node_id](node_id) at (cartesian_or_polar_coordinate){node_content}; %Another of standard node definitions
    %\node[node style, position= distance of node_id](node_id){node_content}; %using positioning
    \node [block] (CTRL) at (0,0) {\Controller};
    \node [block, right=\Xdist of CTRL] (SYS) {\System};
    %Put some sum nodes
    \node [sum](S1) at ($(CTRL.180)+(-\Xdist,\Ydist*0.75)$){}; % $(CTRL.180)+(-\Xdist,\Ydist*0.75)$ by calc library
    \node [sum](S2) at ($(CTRL.180)+(-\Xdist*2,\Ydist*0.25)$){};
    \node [rotate=30](S3) at ($(CTRL.180)+(-\Xdist*3,-\Ydist*0.25)$){$\dots$};
    \node [sum](Sn) at ($(CTRL.180)+(-\Xdist*4,-\Ydist*0.75)$){};
    \node [left=\Xdist*4.5 of S1.center](IN){};
    \node [](OUT) at ($(S1-|SYS.0)+(\Xdist*2.5,0)$){}; 
    %Drawing arrows with some nodes and labels
    \foreach \i [count=\j from 0]in {1,2,\dots,n}{% Special condition drawing when \j counter is equial to 2
        \ifnum \j=2{
            \draw(S3-|IN) node[rotate=90] {\i};
            \draw(S3-|OUT) node[rotate=90] {\i};
            \draw(S3-|CTRL.0)++(1.5em,0.5em) node[rotate=90](temp) {\i};
            \draw(S3-|SYS.0)++(1em+\Xdist*0.4*\j,0) node[rotate=135] (temp2) {\i};
            \path(temp2)--++(0,-\Ydist*2.5) coordinate (temp3) (temp3-|temp)node[rotate=90]{\i};

        }
        \else{
            \draw[<-](S\i) -- (S\i-|IN) node[label={[label distance=1em,yshift=-0.4em]3:$r_\i$},anchor=0](IN-1){$Input_\i$};
            \draw[->](S\i) -- (S\i-|CTRL.180)node[label={[label distance=0.1em,yshift=-0.2em]175:$e_\i$},anchor=180](){};
            \draw[->](S\i-|CTRL.0)node[label={[label distance=\Xdist*0.2,yshift=-0.2em]5:$u_\i$},anchor=0](){} -- (S\i-|SYS.180);
            \draw[->](S\i-|SYS.0) -- (S\i-|OUT)node[label={[label distance=\Xdist*0.2,yshift=-0.3em]175:$y_\i$},anchor=180](OUT-1){$Output_\i$};
            \draw(S\i-|SYS.0)++(1em+\Xdist*0.4*\j,0)
                to [short,*-] ++ (0,-\Ydist*2.5) -| (S\i);
        }
        \fi
    }       
    \end{tikzpicture}
\end{document}

答案2

一个快速的解决方法是将信号(和线路)解释为矢量,并且如果需要,将总和块解释为由重复项组成的矢量分量。

如果您想将其添加到此绘图中(顺便说一句,这很不错),这里有一种方法可以做到。除此之外,我只是清理了您的代码,以便更容易理解发生了什么。

结果

\documentclass[border=1mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

% ~~~ shortcuts ~~~~~~~~~~~~~~
\newcommand\Cs[0]{$C(s)= \begin{bmatrix}%
                c_{11}(s) & c_{12}(s) & \cdots & c_{1n}(s) \\%
                c_{21}(s) & c_{22}(s) & \cdots & c_{2n}(s) \\%
                \vdots & \vdots & \ddots & \vdots \\%
                c_{n1}(s) & c_{n2}(s) & \cdots & c_{nn}(s) \end{bmatrix}$}

\newcommand\Gs[0]{$G(s)= \begin{bmatrix}%
                g_{11}(s) & g_{12}(s) & \cdots & g_{1n}(s) \\%
                g_{21}(s) & g_{22}(s) & \cdots & g_{2n}(s) \\%
                \vdots & \vdots & \ddots & \vdots \\%
                g_{n1}(s) & g_{n2}(s) & \cdots & g_{nn}(s) \end{bmatrix}$}

\begin{document}
\tikzstyle{block}    = [draw, fill=white, rectangle, 
                        minimum height=3em, minimum width=6em]
\tikzstyle{sum}      = [draw, fill=white, circle, node distance=1cm]
\tikzstyle{input}    = [coordinate]
\tikzstyle{output}   = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[
    auto, 
    node distance=2cm,
    >=latex',
    lgnd/.style={anchor=north west,align=left},
]
    % ~~~ blocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node [input]                                          (input)      {};
    \node [sum,    right of=input]                         (sum)        {};
    \node [block,  right of=sum,        node distance=4cm] (controller) {\Cs{}};
    \node [block,  right of=controller, node distance=7cm] (system)     {\Gs{}};
    \node [output, right of=system,     node distance=5cm] (output)     {};

    % ~~~ connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \coordinate [below of=u] (measurements); % !!! this is not a node ... % {};

    \draw [->] (input)        -- node {$r$} (sum);
    \draw [->] (sum)          -- node {$e$} (controller);
    \draw [->] (system)       -- node (y)   {$y$}           (output);

    \draw [-] (y)            |- (measurements);
    \draw [->] (measurements) -| node [near end] {$y_m$}    (sum);

    % ~~~ legend ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    \node[lgnd] at ([yshift=-26mm]input) {
        $r = (r_1, \dots r_n)$\\
        $sum = (sum_1,\dots sum_n)$ // vector component\\
        $e = (e_1, \dots e_n)$\\
        $y_m = (y_{m1}, \dots y_{mn})$\\
    };
    
    \node[lgnd] at ([yshift=-26mm]u) {
        $u = (u_1, \dots u_n)$\\
        $y = (y_1, \dots y_n)$\\
    };
\end{tikzpicture}
\end{document}

相关内容