This is fixed in version 9.
This came up on MathGroup before. Since it hasn't been fixed for so long, I wasn't sure if it was really a bug, so I did some spelunking (and some speculation) today to find out what's happening. To jump to the end: I think it's a bug.
First, let's see what arguments does LogLinearPlot
really pass to the function:
Reap@LogLinearPlot[Sow[x], {x, 1, 10}]
(* ==>
{x, 0.0000470385, 1., 1.04623, 1.09877, 1.15021, ... }
*)
Indeed, it does sample outside the domain (0.000047
). If you try the EvaluationMonitor
option, you'll see that this strange value won't show up there.
Now let's try a plain Plot
:
Reap@Plot[Sow[x], {x, 1, 2}]
(* ==>
{1.00002, x, 1., 1.01963, 1.04091, 1.06078, ... }
*)
Notice a strange value at the beginning again, 1.00002
. It seems that Plot[f[x], {x, min, max}]
always starts by evaluating the function with a numerical value that is midway between min
and max
, approximately (but not always exactly) at min + 0.00002 (max-min)
. After this, Plot
will evaluate the argument symbolically.
My guess is that Plot
does this to discover some information about the function, and also to decide whether the evaluate it or not. Plot
is HoldAll
, and we know that often it is necessary to use Plot[f[x] // Evaluate, ...]
. In my experience, Plot
actually tries to be smart and decide whether it should do this automatically. It also has an undocumented Evaluated
option with the default value being Automatic
, which I believe controls this behaviour. You can set it to True
or False
and see what happens.
Now let's see what LogLogPlot
does. A little spelunking reveals that it calls the functions scaledPlot2
and scaledPlot
(in the Graphics`LogPlotDump`
context), which then call Plot
with the following Method
options (simplified):
Reap@Plot[
Sow[x], {x, Log[1], Log[10]},
{Method -> {"MappingFunctions" -> {{#1, #2} &, {#1, #2} &},
"DomainMappingFunctions" -> {Exp[#1] &}}}]
Note that the bounds have been transformed using Log
(in scaledPlot2
), and the "MappingFunctions"
and "DomainMappingFunctions"
options tell Plot
about this transformation.
It'll evaluate the function with these arguments:
{0.0000470385, x, 1., 1.04623, 1.09877, 1.15021, ... }
Note that even though the bounds are given as Log[1]
and Log[10]
, Plot
will transform these values before passing it to its argument function for all value except the first two special ones.
My conclusion: Plot
fails to transform x
using the "DomainMappingFunction"
when passing the function the first two "discovery values". I'd call this a bug.
It's not a serious bug though unless your function does something really bad and unexpected when called with wrong arguments (hang, crash, format your hard drive).
Reap@LogLinearPlot[Sow[x], {x, 2, 10}]
will show that this evaluation happens only once.EvaluationMonitor
does not reveal this evaluation. The value is not precisely the logartihm of the lower bound, it is slightly larger than that and also depends on the upper bound. $\endgroup$version-8
. What is the policy in such situations? I don't even know whether it was introduced in v8, v7 or v6. $\endgroup$