Precision Plot
- To: mathgroup at smc.vnet.net
- Subject: [mg19246] Precision Plot
- From: Ranko Bojanic <bojanic at math.ohio-state.edu>
- Date: Wed, 11 Aug 1999 02:06:55 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Hi Holger!
I just read your Mathematica related question.
I have some numerical precision problems (Mathematica 3.0)
with the following code:
> <<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])]
> 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.
In cases like this, I use a variant of Dave Withoff and Ted Ersek's
precision plot method:
prf[f_,x_,p_]:=Module[{t},f[t]/.t->SetPrecision[x,p]]
Then use ordinary Plot function (increase number of PlotPoints
if necessary) to plot your function:
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])]
Plot[prf[f3,x,50],{x,0.1,2},PlotRange->All]
On my computer (PowerMacintosh 7500/100, OS 8.6, Mathematica 3.0)
this works fine.
Best regards
Ranko
Ranko Bojanic
bojanic at math.ohio-state.edu