The problem arises when function
returns a number smaller than $MinMachineNumber
:
function[t_] := Exp[-9 t^2];
LogLogPlot[function[t], {t, 8.8718, 8.872}, PlotRange -> All,
GridLines -> {{{Sqrt[Log[1/$MinMachineNumber]]/3,
Directive[Thick, Dashed]}}, None}]
Show[%, Ticks -> Automatic]
For some reason LogLogPlot
considers numbers smaller than $MinMachineNumber
as having logarithm equal to 0
, which is incorrect of course.
The workaround suggested in the comments is to abandon machine numbers by switching to arbitrary precision arithmetics. Even if one sets WorkingPrecision
much smaller than $MachinePrecision
this bug completely disappears, but now another bug arises: the plot produced is not logarithmic in vertical scale and has incorrect vertical tick labels:
LogLogPlot[{function[t], Exp[-9 t^2]}, {t, .01, 100}, WorkingPrecision -> 3]
It is easy to see that the line computed with non-MachinePrecision
WorkingPrecision
is identical to the one generated by LogLinearPlot
:
LogLogPlot[t^3, {t, 1/100, 100}, WorkingPrecision -> 3][[1]] ===
LogLinearPlot[t^3, {t, 1/100, 100}, WorkingPrecision -> 3][[1]]
True
Note that numbers which cannot be expressed as machine numbers are not affected when one tries to convert them to machine numbers:
SetPrecision[function[8.872], MachinePrecision] // Precision
12.9256
So another workaround would be to perform conversion of non-machine-size real numbers manually:
function[t_?NumberQ] :=
If[$MinMachineNumber < Exp[-9 t^2] < $MaxMachineNumber, Exp[-9 t^2],
Indeterminate]
Now LogLogPlot
behaves as expected.
Even better way is to switch off generation of non-machine numbers:
SetSystemOptions["CatchMachineUnderflow" -> False]
This way completely removes discussed bug and does not introduce new bugs but it is strongly advisable to localize the effect of this setting as explained here.
Another workaround is suggested by halirutan.
And of course it is possible to switch to another function which has no bugs. In this case LogLinearPlot
adaptive plotting capabilities can be utilized:
function[t_?NumberQ] := Exp[-9 t^2]
points = Reap[
LogLinearPlot[
Log@Last@Sow[{t, {function[t], Exp[-9 t^2]}}], {t, .01, 100}]][[2,
1]]
ListLogLogPlot[Sort /@ Transpose[Thread /@ points], Joined -> True]
HoldAll
together with the veeeery small numbers is causing this, thus:LogLogPlot[Evaluate@{function[t], Exp[-t^2]}, {t, .01, 100}, PlotRange -> All]
works. I am afraid I cannot offer any better explanation at the moment. $\endgroup${LogLogPlot[function[t],{t, .01, 100}], LogLogPlot[Exp[-t^2], {t, .01, 100}]}
gives different results. Of course the difference is almost infinitesimal, but I don't expect such difference. Furthermore, ifg = Exp[-9 #^2] &
is used,LogLogPlot[g@t, {t, .01, 100}]
also displays correctly. AndLogLogPlot
does not seem to react to different vertical plot ranges... $\endgroup$LogPlot
(for example see here) but can't come up a way to analyze it. A workaround for your problem isLogLogPlot[{function[t],Exp[-9 t^2]}, {t,.01,100}, WorkingPrecision -> 100]
$\endgroup$