如何在 Latex Pgfplots 中绘制方程组?

如何在 Latex Pgfplots 中绘制方程组?

我在 Latex 中绘制了一个效果很好的函数:

\begin{figure}[htbp!]
  \centering
  \begin{tikzpicture}
     \begin{axis}[
      legend pos=north east,
      title = {},
      xlabel = {x},
      ylabel = {y},
      xmin = 0, xmax = 5,
      ymin = -0.5, ymax = 1,
      xtick = {0, 1, 2, 3, 4, 5},
      ytick = {-0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0},
      height=6cm,
      width=10cm
      ]
      \addplot[black, no marks, domain=0.0:5, smooth]
      {(x-1)*(exp(-x+2)/(1+exp(-x+2)))};
    \end{axis}
  \end{tikzpicture}
\end{figure}

生成:

上面编码的一个方程的图

但现在我必须绘制一个方程组:

需要编码的方程组

关于如何在 Latex PgfPlots 中绘制方程组有什么想法吗?

非常感谢!

答案1

作为一种可能的不同方法,如果复杂性增加则特别有用,考虑pgfmath具有三元运算符(x<a ? case true : case false),并且您可以在一个站点中很自然地定义函数并使用它们。

\documentclass{article}
\usepackage{pgfplots}\pgfplotsset{compat=1.18}

\begin{document}
\tikzset{declare function={
        s(\x)=exp(-\x+2)/(1+exp(-\x+2));
        f(\x)=(\x<2)?((\x-1)*s(\x-0.5)):((\x-1)*s(\x));
}}
\begin{tikzpicture}
     \begin{axis}[
      legend pos=north east,
      title = {},
      xlabel = {x},
      ylabel = {y},
      xmin = 0, xmax = 5,
      ymin = -0.5, ymax = 1,
      xtick = {0, 1, 2, 3, 4, 5},
      ytick = {-0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0},
      height=6cm,
      width=10cm
      ]
      \addplot[black, no marks, domain=0.0:5, smooth] {(x-1)*s(x)};
      \addplot[red, no marks, domain=0.0:5, smooth] {(f(x)};
    \end{axis}
  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我找到了答案,也许对某些人有帮助:

\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=newest}
\begin{document}

\begin{figure}[htbp!]
  \centering
  \begin{tikzpicture}
     \begin{axis}[
      legend pos=north east,
      title = {},
      xlabel = {x},
      ylabel = {y},
      xmin = 0, xmax = 5,
      ymin = -0.5, ymax = 1,
      xtick = {0, 1, 2, 3, 4, 5},
      ytick = {-0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0},
      height=6cm,
      width=10cm
      ]
  

\plot[black, no marks, domain=0:2, smooth]
  function{(x-1)*(exp(-(x-0.5)+2)/(1+exp(-(x-0.5)+2)))};
  
  \plot[black, no marks, domain=2:5, smooth]
  function{(x-1)*(exp(-x+2)/(1+exp(-x+2)))};


    \end{axis}
  \end{tikzpicture}
\end{figure}
\end{document}

答案3

比较渐近线,另见.asy代码可以嵌入到 .tex 文档中

在此处输入图片描述

// http://asymptote.ualberta.ca/
unitsize(1cm,2cm);
import graph;
real s(real x){return exp(2-x)/(1+exp(2-x));}
real f(real x){
if (x<-2) 
  return (x-1)*s(x-.5);
else  
  return (x-1)*s(x);
}

path gs=graph(s,0,5);
path gf=graph(f,0,5);
draw(gs,red);
draw(gf,blue);
xaxis("$x$",BottomTop,LeftTicks(Step=1));
yaxis("$y$",LeftRight,RightTicks(Step=.5));
shipout(bbox(5mm,invisible));

相关内容