MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Precision Problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19239] RE: [mg19210] Precision Problems
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Wed, 11 Aug 1999 02:06:51 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Holger Strauss  wrote:
----------------------

I have some numerical precision problems (Mathematica 3.0)
with the following code:

<<Graphics`Graphics`
f3[x_] := (*....<snip>.....*)

LogLinearPlot[f3[x], {x,0.05,Pi}]

As can be seen from the plot, evaluating f3 doesn't work for
small arguments. It seems to me that this is the result of large
numbers being subtracted from each other resulting in a very
small difference.
It it possible to increase the precision of the calculation adequatly?
I already tried to encapsulate the whole function with N[..., 50000],
however, without success...
Is there any other way of successfully evaluating and plotting
f3 for small arguments?

------------------------
REPLY:

That isn't enough to force the use of arbitrary precision arithmetic.

On page 142 of The Mathematica Book (4th edition) it says 
"If the function you are plotting requires higher-precision operations, you
may have to switch off compilation in Plot.  You can do this by setting the
option Compiled->False".  Well LogLinearPlot has a Compiled option.

In[1]:=
Options[LogLinearPlot,Compiled]

Out[1]=
{Compiled->True}

use the option Compiled->False.  Try it and you will see it doesn't make a
difference.  In fact it contrary to what the book says (Compiled->False)
doesn't make Plot use arbitrary precision either!

One must be more clever than that to force the use of arbitrary precision.
The code below will solve your problem.

----------------

In[1]:=
<<Graphics`Graphics`
f3[x_] := 20 Log[10,
  1/(15120 x^4)*
  (-90720 - 15120 x^2 + 13424 x^4 +
     9(13440 + 2240  x^2 + 257 x^4) Cos[x]-
     72(420 + 70  x^2 + 9 x^4) Cos[2x]+
      31 x^4 Cos[3x]
   )]


In[2]:=
LogLinearPlot[
  SetPrecision[f3[SetPrecision[x,Infinity]],4],
  {x,0.05,Pi}];

----------------------

I wrote a package that will do everything Plot can do, except with arbitrary
precision arithmetic.  Programming the function so you can do things like
plot a list of functions with different styles was not at all easy!  The
package is available at:

http://www.mathsource.com/Content/Enhancements/Graphics/2D/0209-887

Included with the package is extensive discussion on how and why it works.

I hope the plot functions in a future version will allow us to use a simple
option to force the use of arbitrary precision.

-------------
Regards,
Ted Ersek


  • Prev by Date: Importing graphics into mathematica-Addition
  • Next by Date: Re: Mathematica Link for Excel and Excel 2000
  • Previous by thread: Precision Problems
  • Next by thread: Re: Precision Problems