图表有误

图表有误
\begin{tikzpicture}[
  declare function={
    func(\x)= (\x < 10) * (3.75*(1-exp(-x/3))) +
              (\x > 10) * (37.5*(exp(-x/3)))
   ;
  },
  scale=0.75
]
\begin{axis}[
    ylabel = {When $Q(\times10^{-5}C)$},
    xlabel = t(sec),
    xmin = 0, xmax = 21,
    ymin = 0, ymax = 4,
    xtick distance = 1,
    ytick distance = 1,
    grid = both,
    axis lines = center,
    minor tick num = 1,
    major grid style = {lightgray},
    minor grid style = {lightgray!25},
    width = \textwidth,
    height = 0.5\textwidth]
    \addplot[
        domain = 0:20,
        samples = 100,
        smooth,
        thick,
        red,
    ] {func{\x}};
\end{axis}
\end{tikzpicture}

在此处输入图片描述 我从这段代码中得到了这个图表,但是当 x>10 时它应该呈指数下降,而不是像这样。我取R=2M\Omega,C=1.5\mu F,V_0=25V,我的函数是V_0Ce^\frac{-t}{RC}

答案1

  • 你的图表呈现指数函数
  • 我猜,你不喜欢 处的超调x=10,它们是由使用 smooth选项(使用样条函数在连续的图点之间平滑地插入)引起的。删除它并稍微重新组织轴选项,我得到以下结果:

在此处输入图片描述

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}[
  declare function={
    func(\x)= (\x < 10) * (3.75*(1-exp(-x/3))) +
              (\x > 10) * (37.5*(exp(-x/3)));
  },
  scale=0.75
                    ]
\begin{axis}[
    width = \textwidth,
    height = 0.5\textwidth,
    axis lines = center,
    grid=both,
    minor tick num = 1,
    xtick distance=1,   
    major grid style = {lightgray},
    minor grid style = {lightgray!25},
    ylabel = {When $Q(\times10^{-5}C)$},
    xlabel = t (sec),
    xmin = 0, xmax = 21,
    ymin = 0, ymax = 4,
            ]
\addplot[
        domain = 0:20,
        samples = 100,
        thick,
        red,
    ] {func{\x}};
\end{axis}
    \end{tikzpicture}
\end{document}

相关内容