2

我正在尝试绘制乳胶中各种正态分布的概率密度函数。均值为 0,标准差为:0.4339、0.4931 和 0.3665。

我使用这段代码:

\documentclass[titlepage]{article}

\usepackage[obeyspaces]{url}
\usepackage{caption}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{listings}
\usetikzlibrary{calc}
\lstset{
    showstringspaces=false,
    commentstyle=\color{red},
    keywordstyle=\color{blue},
    basicstyle=\small,
    breaklines=true
}
\usepackage{amsmath}
\usepackage{subcaption}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}
\begin{figure}[h]
\centering
\begin{subfigure}[h]{0.45\linewidth}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[every axis plot post/.append style={
  mark=none,domain=-2:2,samples=50,smooth},
  xmin=-1.6,
  xmax=1.6,
  ymin=0,
  xtick={},
  %ytick=\empty,
  enlargelimits=auto
  ],
  \addplot {gauss(0, 0.4339)};
  \addplot {gauss(0, 0.4931)};
  \addplot {gauss(0, 0.3665)};
  \addlegendimage{empty legend}
  \addlegendentry{$x$}
  \addlegendentry{$y$}
  \addlegendentry{$z$}
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}
\end{document}

结果如下图:

乳胶输出

您可以看到 y 轴上升到 ~1.1。这没有任何意义,对吧?它的概率应该低于 1。此外,据我所知,函数的积分应该有 1 的总和。因此,这些值通常应该低得多。

我做错了什么,我是不是误会了什么?

4

1 回答 1

0

改变

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

进入

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{exp(-((x-(#1))*((x-(#1)))/(2*(#2)*(#2)))/((#2)*sqrt(2*pi))}%
}

^2不使用实际调用的 power 函数,pow(#1,2)并使用所有括号:也许你的发行版仍然有这个错误

于 2021-09-01T14:34:26.343 回答