Mikkelsen, Christian Ingemann wrote:
> On a Ubuntu 5.10 machine plotting of a simple (but constant) function
> causes gnuplot to hang and use all available CPU resources:
The problem is that, contrary your expectations, this function is *not*
actually constant. You're expecting that an equality found in
infinite-precision arithmetic will be preserved in finite-precision
arithmetic as done by your computers. Well, it's not. As the saying
goes: "In computing 10 times 0.1 is hardly ever 1.0".
The hang is caused indirectly by this: this function is so close to
being constant, that it drives the algorithm trying to determine a
suitable axis range and tic interval face-first into the wall. The
actual range of values will be something like [1-a*DBL_EPS:1+b*DBL_EPS],
for small integers a and b.
If you specify a suitable, fixed axis range, it will no longer hang, and
you'll see the problem:
set yrange [1-1e-15 : 1+1e-15]
plot sin(x/2)**4 + sin(x)**2/2 + cos(x/2)**4
Or you can plot the difference between the supposedly constant result
and the expected, actual constant:
set autoscale y
plot sin(x/2)**4 + sin(x)**2/2 + cos(x/2)**4 - 1
|