这个问题是类似的。
我的任务是在一个图中绘制两个磁滞回线。我从以下函数(代表我的磁滞回线)中获取这里。
我的代码:
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage[per-mode = fraction]{siunitx}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization[
scientific axes = {clean, end labels},
all axes = {ticks and grid = {major at = 0}},
x axis = {label = $\frac{H}{\si{\A\per\m}}$},
y axis = {label = $\frac{B(H)}{\si{\tesla}}$},
data/format = function,
visualize as smooth line/.list = {left_soft, right_soft, left_hard, right_hard},
left_soft = {style = dashed,
label in legend = {text = weichmagnetisch}
},
right_soft = {style = dashed},
left_hard = {label in legend = {text = hartmagnetisch}}
]
data[set = left_soft] {
var x : interval [-7 : 7];
func y = 5 / (1 + exp(-2 * \value x - 1.5)) - 2.5;
}
data[set = right_soft] {
var x : interval [-7 : 7];
func y = 5 / (1 + exp(-2 * \value x + 1.5)) - 2.5;
}
data[set = left_hard] {
var x : interval [-7 : 7];
func y = 5 / (1 + exp(-.75 * \value x - 1.5)) - 2.5;
}
data[set = right_hard] {
var x : interval [-7 : 7];
func y = 5 / (1 + exp(-.75 * \value x + 1.5)) - 2.5;
};
\end{tikzpicture}
\end{document}
然而我得到很多
!尺寸太大
\pgfmath@iterate
。...\pgfmath@xa \ifdim \pgfmath@x
错误。我该如何修复?
提前谢谢你的帮助!
答案1
对于 x=-6 和 x=-7的求值exp(-2 * \value x - 1.5)
,以及exp(-2 * \value x + 1.5)
对于 x=-5、-6、-7 的求值都会导致溢出。最简单的解决方法是忽略这些值,因为图形的这一部分无论如何都被其他曲线覆盖了。否则,您可以通过将 x 的错误值设置为零来分段定义函数。
\documentclass{scrartcl}
\usepackage{tikz}
\usepackage[per-mode = fraction]{siunitx}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization[
scientific axes = {clean, end labels},
all axes = {ticks and grid = {major at = 0}},
x axis = {label = $\frac{H}{\si{\A\per\m}}$},
y axis = {label = $\frac{B(H)}{\si{\tesla}}$},
data/format = function,
visualize as smooth line/.list = {left_soft, right_soft, left_hard, right_hard},
left_soft = {style = dashed,
label in legend = {text = weichmagnetisch}
},
right_soft = {style = dashed},
left_hard = {label in legend = {text = hartmagnetisch}}
]
data[set = left_soft] {
var x : interval [-5 : 7];
func y = 5 / (1 + exp(-2 * \value x - 1.5)) - 2.5;
}
data[set = right_soft] {
var x : interval [-4 : 7];
func y = 5 / (1 + exp(-2 * \value x + 1.5)) - 2.5;
}
data[set = left_hard] {
var x : interval [-7 : 7];
func y = 5 / (1 + exp(-.75 * \value x - 1.5)) - 2.5;
}
data[set = right_hard] {
var x : interval [-7 : 7];
func y = 5 / (1 + exp(-.75 * \value x + 1.5)) - 2.5;
}
;
\end{tikzpicture}
\end{document}