在 Tikz 中的矩形内写方程

在 Tikz 中的矩形内写方程

我正在尝试绘制附图中的图表。几个小时后我仍无法完成两项任务。感谢您的帮助

  1. 在植物矩形框中写下如下所示的方程式。
   \dot{x} = f(x, \alpha(x, \theta)) \\
   y = h(x)
\end{align*}
  1. 如附图所示,在连接“总和”和“时间”节点的线的中间附加一条直线。

我想要绘制的图形: 在此处输入图片描述

我目前的结果 在此处输入图片描述

我的代码

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{backgrounds,fit,shapes}
\begin{document}
\begin{figure}[ht]
    \centering
        \begin{tikzpicture}

            % Sum shape
        \node[draw=black, 
            circle,
            minimum size=0.8cm,
           % fill=green!10
            ] (sum) at (0,0){$\large + $};
 
            % Integrator
            \node [draw=black, 
%    fill=green, 
            minimum width=1.5cm, 
             minimum height=1.2cm,
              right=1cm of sum,
            ] (Integrator) {\large $\frac{k}{s}$};

         % low pass filter
            \node [draw=black, 
%    fill=green, 
            minimum width=1.5cm, 
             minimum height=1.2cm,
              right=1cm of Integrator,
            ] (lowfilter) {\large $\frac{\omega_l}{s + \omega_l}$};

      % times shape
        \node[draw=black, 
            circle,
            minimum size=0.8cm,
            right=1cm of lowfilter,
            ] (times){$\large \times$} ;

             % High pass filter
            \node [draw=black, 
%    fill=green, 
            minimum width=1.5cm, 
             minimum height=1.2cm,
              right=1.5cm of times,
            ] (highfilter) {\large $\frac{s}{s + \omega_h}$};
%======================================================================
% I want to write equation inside this rectangle
%\begin{align*}
 %   \dot{x} = f(x, \alpha(x, \theta)) \\
%    y = h(x)
%\end{align*}
        % Plant
            \node [draw=black, 
%    fill=green, 
            minimum width=4cm, 
             minimum height=2cm,
              above=2cm of times,
            ] (plant) {\large $\dot{x} = f(x, \alpha(x, \theta))  $ };  
           % ] (plant) {\begin{align*}
           %    \dot{x} = f(x, \alpha(x, \theta))
         %   \end{align*}}; % $\dot{x} = f(x, \alpha(x, \theta))  $ }; 


    \draw[-stealth] (highfilter.west) -- (times.east)
    node[midway,above]{$y -\eta $};

     \draw[-stealth] (times.west) -- (lowfilter.east);
   % node[midway,above]{};

    \draw[-stealth] (lowfilter.west) -- (Integrator.east)
    node[midway,above]{$\xi$};

      \draw[-stealth] (Integrator.west) -- (sum.east)
    node[midway,above]{$\hat{\theta}$};

        \draw[-stealth] (sum.north) |-  (plant.west);

\draw[-stealth] (plant.east) -- ++ (4,0) 
    node[near end](output){}node[near end,above]{$y$};
    
       \draw[-stealth] (output.center) |-  (highfilter.east);

       \draw[stealth-stealth] (times.south) --++ (0, -1) -| (sum.south)
       node[midway](connector){};

       %\draw[-stealth] (connector.center) --++ (0, -1);


       

        \end{tikzpicture}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}
\end{document}

答案1

像这样:

在此处输入图片描述

编写植物方程系统最简单的方法是使用包aligned的环境amsmath。我擅自定义了方案元素的样式,并稍微重新设计了其输入部分。通过这种方式,方案代码更短,(希望)更清晰。

编辑:添加的是方案中缺少的输入部分。

%\documentclass{article}
\documentclass[margin=3mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                backgrounds,
                fit,
                positioning,
                quotes}
\newcommand\ppbb{path picture bounding box}

\begin{document}
%    \begin{figure}[ht]
%    \centering
\begin{tikzpicture}[auto=right,
    node distance = 8mm and 12mm,
       dot/.style = {circle, fill, minimum size=3pt, inner sep=0pt,
                     node contents={}},
shorten <>/.style = {shorten <=#1, shorten >=#1},
       sum/.style = {circle, draw=black, minimum size=6mm,
                     path picture={\draw[very thick,shorten <>=1mm]
                        (\ppbb.north) edge[-] (\ppbb.south)
                        (\ppbb.west)  -- (\ppbb.east);},
                    node contents={}},
                % Sum shape
       mul/.style = {circle, draw=black, minimum size=6mm,
                     path picture={\draw[very thick,shorten <>=1mm]
                        (\ppbb.north west) edge[-] (\ppbb.south east)
                        (\ppbb.south west) -- (\ppbb.north east);},
                    node contents={}},
         N/.style = {draw, minimum size=12mm, align=center, font=\large},
every edge/.append style = {draw, -Stealth}
                ]
% blocks
\node (sum) [sum];
\node (int) [N, right=of sum]   {$\frac{k}{s}$};
\node (LPF) [N, right=of int]   {$\frac{\omega_l}{s + \omega_l}$};
\node (mul) [mul, right=of LPF];
\node (HPF) [N, right=of mul]   {$\frac{s}{s + \omega_h}$};
%
\node (plant) [N, above=of mul] {$\begin{aligned}  % <----
                                 \dot{x} & = f(x, \alpha(x,\theta))\\
                                      y & = h(x)
                                \end{aligned}$};
\node (out) [dot, right=of plant-| HPF.east, label=$y$];
%
\node (in) [dot, below=of sum];
%% lines
\path   (HPF) edge["$y-\eta$"]          (mul)
        (mul) edge (LPF)
        (LPF) edge["$\xi$"]             (int)
        (int) edge["$\hat{\theta}$"]    (sum)
        (in)  edge   (sum)
        (out) edge ++ (1.2,0);
%
\draw[-Stealth] (sum) |- (plant) node[pos=0.9, above] {$\theta$};
\draw[-Stealth] (plant) -- (out) |- (HPF);
%
\draw   (in) to["$a\sin\omega t$"] ++ (-2,0);
\draw[-Stealth] (in) -| (mul);
\end{tikzpicture}
%    \caption{Caption}
%    \label{fig:my_label}
%    \end{figure}
\end{document}

相关内容