Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7264 > unrolled thread

Mathematica LogPlot Bug

Started byAntonioP <ant.piniz@gmail.com>
First post2011-12-16 10:58 +0000
Last post2011-12-20 08:03 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Mathematica LogPlot Bug AntonioP <ant.piniz@gmail.com> - 2011-12-16 10:58 +0000
    Re: Mathematica LogPlot Bug "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-12-17 07:55 +0000
      Re: Mathematica LogPlot Bug AntonioP <ant.piniz@gmail.com> - 2011-12-20 08:03 +0000

#7264 — Mathematica LogPlot Bug

FromAntonioP <ant.piniz@gmail.com>
Date2011-12-16 10:58 +0000
SubjectMathematica LogPlot Bug
Message-ID<jcf890$6t1$1@smc.vnet.net>
Hello,

I have to draw some functions in log scale, but LogPlot seems not to
be able to draw them correctly if the y-value is too small.
A simple case:

f[x_] = 10^(-5 x)
LogPlot[f[x], {x, 1, 100}, PlotRange -> Full]

the plot should be a simple straight line for any x value,
while at about x=61.5 there is a step and, for any greater value of x,
the function appears to be constant.
Nevertheless, Mathematica is able to compute the correct value of f[x]
for any x:

N[f[60]]
N[f[65]]
N[f[80]]
N[f[100]]

There is a similar problem for large y-values, as well.
Apparently there is a y-range, about (10^-308, 10^308), outside which
LogPlot doesn't work correctly.

Any idea on how to resolve the problem?


Thanks,

Antonio

[toc] | [next] | [standalone]


#7317

From"Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Date2011-12-17 07:55 +0000
Message-ID<jchht2$im7$1@smc.vnet.net>
In reply to#7264
On Fri, 16 Dec 2011 10:58:40 -0000, AntonioP <ant.piniz@gmail.com> wrote:

>
> Hello,
>
> I have to draw some functions in log scale, but LogPlot seems not to
> be able to draw them correctly if the y-value is too small.
> A simple case:
>
> f[x_] = 10^(-5 x)
> LogPlot[f[x], {x, 1, 100}, PlotRange -> Full]
>
> the plot should be a simple straight line for any x value,
> while at about x=61.5 there is a step and, for any greater value of x,
> the function appears to be constant.
> Nevertheless, Mathematica is able to compute the correct value of f[x]
> for any x:
>
> N[f[60]]
> N[f[65]]
> N[f[80]]
> N[f[100]]
>
> There is a similar problem for large y-values, as well.
> Apparently there is a y-range, about (10^-308, 10^308), outside which
> LogPlot doesn't work correctly.
>
> Any idea on how to resolve the problem?
>
> Thanks,
>
> Antonio
>

Your range looks suspiciously similar to {$MinMachineNumber,  
$MaxMachineNumber}. This is not a bug; it is just that LogPlot by default  
works in machine precision. Of course, defaults are not set in stone, so:

f[x_] = 10^(-5 x)
LogPlot[f[x], {x, 1, 100}, PlotRange -> Full, WorkingPrecision ->  
$MachinePrecision]

Note that MachinePrecision (the default) and $MachinePrecision are  
different. The former signifies literal machine numbers. The latter  
denotes arbitrary precision numbers with the same precision as machine  
reals, but crucially, with precision tracking switched on. This allows  
Plot to adaptively increase the working precision (by up to  
$MaxExtraPrecision base-10 digits) in order to produce an accurate plot,  
whereas without precision tracking it has no way to know when numerical  
errors become significant.

The reason why N obtains the correct answers is that it can trap machine  
underflow and switch to arbitrary precision even without this being  
switched on explicitly. This behaviour is controlled by the system option  
"CatchMachineUnderflow". For example, switching it off, we get:

SetSystemOptions["CatchMachineUnderflow" -> False];
N[f[100], MachinePrecision] (* gives 0. *)
N[f[100], $MachinePrecision] (* gives 1.0*^-500 *)

[toc] | [prev] | [next] | [standalone]


#7362

FromAntonioP <ant.piniz@gmail.com>
Date2011-12-20 08:03 +0000
Message-ID<jcpfgj$qdj$1@smc.vnet.net>
In reply to#7317
On Dec 17, 8:55 am, "Oleksandr Rasputinov"
<oleksandr_rasputi...@hmamail.com> wrote:
> On Fri, 16 Dec 2011 10:58:40 -0000, AntonioP <ant.pi...@gmail.com> wrote:
>
> > Hello,
>
> > I have to draw some functions in log scale, butLogPlotseems not to
> > be able to draw them correctly if the y-value is too small.
> > A simple case:
>
> > f[x_] = 10^(-5 x)
> >LogPlot[f[x], {x, 1, 100}, PlotRange -> Full]
>
> > the plot should be a simple straight line for any x value,
> > while at about x=61.5 there is a step and, for any greater value of x,
> > the function appears to be constant.
> > Nevertheless, Mathematica is able to compute the correct value of f[x]
> > for any x:
>
> > N[f[60]]
> > N[f[65]]
> > N[f[80]]
> > N[f[100]]
>
> > There is a similar problem for large y-values, as well.
> > Apparently there is a y-range, about (10^-308, 10^308), outside which
> >LogPlotdoesn't work correctly.
>
> > Any idea on how to resolve the problem?
>
> > Thanks,
>
> > Antonio
>
> Your range looks suspiciously similar to {$MinMachineNumber,
> $MaxMachineNumber}. This is not abug; it is just thatLogPlotby default
> works in machine precision. Of course, defaults are not set in stone, so:
>
> f[x_] = 10^(-5 x)LogPlot[f[x], {x, 1, 100}, PlotRange -> Full, WorkingPrecision ->
> $MachinePrecision]
>
> Note that MachinePrecision (the default) and $MachinePrecision are
> different. The former signifies literal machine numbers. The latter
> denotes arbitrary precision numbers with the same precision as machine
> reals, but crucially, with precision tracking switched on. This allows
> Plot to adaptively increase the working precision (by up to
> $MaxExtraPrecision base-10 digits) in order to produce an accurate plot,
> whereas without precision tracking it has no way to know when numerical
> errors become significant.
>
> The reason why N obtains the correct answers is that it can trap machine
> underflow and switch to arbitrary precision even without this being
> switched on explicitly. This behaviour is controlled by the system option
> "CatchMachineUnderflow". For example, switching it off, we get:
>
> SetSystemOptions["CatchMachineUnderflow" -> False];
> N[f[100], MachinePrecision] (* gives 0. *)
> N[f[100], $MachinePrecision] (* gives 1.0*^-500 *)


Thanks for all the answers.

I have also found this simple workaround which, I think, exploits the
Mathematica's arbitrary precision arithmetic, and should work for any
y-range:

f[x_] = 10^(-5 x)
ListLogPlot[Table[N[f[x]], {x, 0, 100, 1}], Joined -> True]

to compare with:
LogPlot[f[x], {x, 1, 100}, PlotRange -> Full]

Antonio

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web