# Dimension too large-errors by TikZ datavisualization

This question is a continuation of a similar one.

My task is to draw two hysteresis loops in one graph. I took the function (which represents my hysteresis loops) from here.

My code:

\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}


However I get many

! Dimension too large. \pgfmath@iterate ...\pgfmath@xa \ifdim \pgfmath@x

errors. How can I fix it?

The evaluation of exp(-2 * \value x - 1.5) for x=-6 and x=-7, and likewise of exp(-2 * \value x + 1.5) for x=-5,-6,-7 results in an overflow. The easiest fix is to omit these values since this part of the graph is covered by the other curves anyway. Otherwise you can define the function piece-wise by setting it to zero for the bad values of 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}

• Hello @gernot! Thank you for your answer! If I understand correctly there is no general solution (like fpu) for this task? – Su-47 Feb 16 '17 at 12:21
• @Su-47 Sorry, I have no experience with fpu. It may well be that the calculations can be done with a higher precision/bigger range. – gernot Feb 16 '17 at 12:24