Re: Plot, Cursor and Spelling Errors questions
- To: mathgroup at smc.vnet.net
- Subject: [mg14497] Re: Plot, Cursor and Spelling Errors questions
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Fri, 23 Oct 1998 20:59:15 -0400
- Organization: University of Western Australia
- References: <70k5b2$eou@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ranko Bojanic wrote:
> I still do not understand why anh how your module works.
>
> PrecisionPlot[f_,{x_,xmin_,xmax_},opts___?OptionQ]/;
> Head[f]=!=List:=
> Module[{g,h},
> g=Evaluate[f/.x->#]&;
> h=g[SetPrecision[#,17]]&;
> Plot[h[x],{x,xmin,xmax}, opts]
> ]
Here is another approach: instead of modifying Plot, modify your
function instead. E.g., the following plot generates garbage (since
LegendreP[n, x] are bounded in the range [-1,1]):
In[1]:= Plot[Evaluate[LegendreP[50, x]], {x, 0.95, 1},
PlotRange -> All];
Modify the function to use SetPrecision:
In[2]:= p[n_, x_, prec_:40] := LegendreP[n, SetPrecision[x, prec]]
Now plot the function:
In[3]:= Plot[p[50, x], {x, 0.95, 1}, PlotRange -> All];
> The program I posted is
> just the first step in the construction of the polynomial of best
> approximation to Exp[x] on [-1,1], of degree 14. If you want a
> polynomial of degree 30, set n=31 and the precision 50 istead of 17
> since the magnitude of the error curve is 10^(-42). The PrecisionPlot
> module works fine in this case as well.
Why restrict attention to polynomial approximations? You can, in
general, do much better with rational approximations. Also, you might
want to look at the NumericalMath`Approximations` and Calculus`Pade`
packages. For example, after loading
In[4]:= << "NumericalMath`Approximations`"
you can compute the best approximation to Exp[x] on [-1,1] of degree 14
using MiniMaxApproximation. Here we compute the _exact_ difference
between the MiniMaxApproximation and Exp[x]:
In[5]:= Delta[x_] = Exp[x] - MiniMaxApproximation[Exp[x],
{x, {-1, 1}, 14, 0}, WorkingPrecision -> 30][[2,1]]
Now we overload this function so that a second argument indicates the
precision:
In[6]:= Delta[(x_)?NumericQ, prec_] := Delta[SetPrecision[x, prec]]
Now we can plot the difference:
In[7]:= Plot[Delta[x, 40], {x, -1, 1}];
Cheers,
Paul
____________________________________________________________________
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia Nedlands WA 6907
mailto:paul at physics.uwa.edu.au AUSTRALIA
http://www.physics.uwa.edu.au/~paul
God IS a weakly left-handed dice player
____________________________________________________________________