我遇到的问题是,当我尝试绘制电子函数时,收到一条错误消息(尺寸太大):
\documentclass[BCOR=3mm,11pt,headsepline,footsepline]{scrbook}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{pgf,tikz}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[dvipdfm]{geometry}
\usepackage{tabulary}
\usepackage{subfigure}
\usepackage{float}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes,snakes}
\usepackage{ntheorem}
\geometry{
inner=2cm,
outer=2cm,
top=2cm,
bottom=2.5cm,
head=2cm,
footnotesep=1cm,
% bindingoffset=1cm,
}
\mdtheorem[%
apptotikzsetting={\tikzset{mdfbackground/.append style=%
{top color=white,
bottom color=white},
mdfframetitlebackground/.append style =%
{top color=gray!10!white,
bottom color=gray!10!white}
}},
,roundcorner=10pt,middlelinewidth=1.3pt,
frametitlerule=true,frametitlerulewidth=1.3pt,
innertopmargin=10pt,%
]{wissen}{Fehlerschwerpunkt}
\begin{document}
\begin{tikzpicture}[scale=0.9, >=latex,y=7cm,x=1cm]
\draw[-angle 45,line width = 0.8pt] (-6,0) -- (6,0) node[right] {\scriptsize $x$};
\draw[-angle 45,line width = 0.8pt] (0,-0.1) -- (0,0.5) node[above] {\scriptsize $y$};
\foreach \x in {-5,-4,...,-1,1,2,...,5} \draw (\x, 3pt) -- (\x,-3pt) node[anchor=north] {\tiny \x};
\foreach \y in {0.1,0.2,0.3,0.4} \draw (3pt,\y) -- (-3pt,\y) node[anchor=east] {\tiny \y};
\draw[color=red, line width = 1pt, domain=-4:5, samples=100] plot (\x,{(9*exp(\x))/(exp(\x)+9)^2});
\end{tikzpicture}
\end{document}
答案1
对于情节你最好使用pgfplots
:
代码:
\documentclass{scrbook}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmax=6.9,
xmin=-5.5,
ymin=-0.05,
ymax=0.35,
xlabel={$x$},
ylabel={$y$},
]
\addplot [domain=-4:5, samples=100, ultra thick, blue] {9*exp(x)/(exp(x)+9)^2};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
PSTricks 解决方案:
\documentclass{article}
\usepackage{pst-plot}
\begin{document}
\psset{
yunit = 20
}
\begin{pspicture}(-5,-0.05)(7.35,0.37)
\psaxes[
dx = 2,
Dx = 2,
dy = 0.1,
Dy = 0.1
]{->}(0,0)(-5,-0.05)(7,0.35)[$x$,0][$y$,90]
\psplot[
algebraic,
plotpoints = 1000, % larger number means smoother curve (and longer compile time)
linewidth = 1.5pt,
linecolor = blue
]{-4}{5}{9*Euler^x/(Euler^x+9)^2}
\end{pspicture}
\end{document}
答案3
PGF-Manual 写道:
需要注意的是,所有计算在任何时候都不能超过 ±16383.99999,因为底层计算依赖于 TeX 维度。这意味着许多底层计算必然是近似的,而且速度也不是很快。毕竟,TeX 是一种排版语言,不太适合相对高级的数学运算。但是,可以按照第 76 节中的描述更改计算。
因此我将代码改为:
\begin{tikzpicture}[scale=0.9, >=latex,y=9cm,x=0.8cm]
\draw[-angle 45,line width = 0.8pt] (-6,0) -- (6,0) node[right] {\scriptsize $x$};
\draw[-angle 45,line width = 0.8pt] (0,-0.1) -- (0,0.5) node[above] {\scriptsize $y$};
\foreach \x in {-5,-4,...,-1,1,2,...,5} \draw (\x, 3pt) -- (\x,-3pt) node[anchor=north] {\tiny \x};
\foreach \y in {0.1,0.2,0.3,0.4} \draw (3pt,\y) -- (-3pt,\y) node[anchor=east] {\tiny \y};
\draw[color=red, line width = 1pt, domain=-4:5, samples=100] plot (\x,{(9*exp((\x)))/(exp((\x))+9)/(exp((\x))+9)});
\end{tikzpicture}
因此,对于较大的数字,不需要计算项 (exp(x)+9)^2
答案4
在这种特殊情况下,您可以通过更改来避免较大的分母项
plot (\x,{(9*exp(\x))/(exp(\x)+9)^2})
对此
plot (\x,{(9*exp(\x))/(exp(\x)+9)/(exp(\x)+9})
通过此更改,您的示例可以无错误地进行编译并生成以下内容(在我的系统上):