Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

(I'm using Mathematica 8.)

I have a Taylor series:

poly = Normal[Series[E^x, {x, 0, 10}]]

I want to produce a log-linear plot of the error. This is easy enough with the following code:

LogPlot[Abs[E^x - poly], {x, -1, 1}]

This produces

a log-linear plot

Now, I want to plot even smaller values of the error (in particular I want the plot to be sensible near zero), so I tell LogPlot to use high precision as follows:

LogPlot[Abs[E^x - poly], {x, -1, 1}, WorkingPrecision -> 30]

However this destroys the labeling on the y-axis:

bad behavior of LogPlot[]

Does anyone know what has gone wrong here? How do I fix it?

share|improve this question
2  
No solution, just some comments: WorkingPrecision -> MachinePrecision will use machine precision (default). WorkingPrecision -> $MachinePrecision will not use machine precision, but the built-in arbitrary precision with the same number of digits as machine precision. For high precision you would not want MachinePrecision, but set a higher number in WorkingPrecision (which as you noticed produces a plot with a wrong scale). –  Szabolcs Dec 3 '12 at 17:26
    
Setting WorkingPrecision, as in your example, crashes version 9. Can anyone reproduce this in 9? –  Szabolcs Dec 3 '12 at 17:27
    
@Szabolcs For me it doesn't crash a session but it yields a plot of a constant function, so it is incorrect. –  Artes Dec 3 '12 at 17:30
1  
@Szabolcs it crashes the kernel on macosX 10.7.5 +mma 9.0 –  chris Dec 3 '12 at 19:34
1  
Apparently this bug still exists in MMA 9.0.1...Can't believe such a bug happens and remains unsolved for quite a long time. –  Leo Fang Sep 5 '13 at 13:26

1 Answer 1

up vote 11 down vote accepted

This is not simply a mislabeling of the axes. More than that is going on: the plot produced is not even logarithmic. Let's try to use the default (non-log-transformed tick marks):

First, with MachinePrecision (correct result):

Show[
 LogPlot[Abs[E^x - poly], {x, -1, 1}, WorkingPrecision -> MachinePrecision],
 Ticks -> Automatic
]

Mathematica graphics

Then with higher precision (incorrect result):

Show[
 LogPlot[Abs[E^x - poly], {x, -1, 1}, WorkingPrecision -> 30],
 Ticks -> Automatic
]

Mathematica graphics

I don't think it's worth digging into how LogPlot works, as at this point this clearly seems to be a bug.


You can work around it by using Plot instead of LogPlot:

Plot[Log@Abs[E^x - poly], {x, -1, 1}, WorkingPrecision -> 30]

Mathematica graphics

But then you have to do re-label the axes yourself (CustomTicks / LevelScheme are helpful packages). If you don't mind losing adaptive plotting, you can generate the points to be shown yourself and us ListLogPlot:

ListLogPlot[Table[Evaluate@Abs[E^x - poly], {x, -1, 1, 0.01`30}]]

Mathematica graphics

(You'd probably want Joined -> True here, but seeing where the points are helps you tune the plot, so I didn't include it now.)

share|improve this answer
    
Thanks If you could show how to use Plot with the CustomTicks package, that would be very useful –  aukie Dec 4 '12 at 15:14
2  
Better yet: have Plot[] take care of the adaptive sampling, and pass the points thus generated to ListLogPlot[]. –  J. M. May 4 '13 at 5:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.