MathGroup Archive 2006

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

Search the Archive

Re: Plot resolution


Laurentiu Caramete wrote:
> Hi,
> 
> I got a problem with a plot of a function. The function 'pressure' should
> decrease monotonically with r. The Plot function is giving a non-monotonic
> plot at big r, this is a problem with the resolution of the plot or with the
> function? How can I check that?
> 
> \!\(Clear[r]\[IndentingNewLine]
>   \(ro = 10\^3;\)\[IndentingNewLine]
>   \(pressure =
>       p[r] /. \(DSolve[{D[p[r], r] ==
>                 1\/\(\(r\^2\) \((1 + r)\)\^3\) -
>                   Log[1 + r]\/\(\(r\^3\) \((1 + r)\)\^2\),
>               p[ro] == 10\^\(-7\)}, p[r],
>             r]\)[\([1]\)];\)\[IndentingNewLine]\[IndentingNewLine]
>   Plot[pressure, {r, ro, 10\^4}, PlotRange -> All]\)
> 
> 
> Thanks
> 

The problem is that Plot uses machine numbers as arguments to your 
function, and evaluation of the function is running into numerical 
cancellation errors. You need to figure out some way to use higher 
precision. One idea is to change your pressure definition so that 
pressure is a function instead of an expression:

pressure = p /.
   DSolve[
     {
       D[p[r], r] == 1/(r^2*(1 + r)^3) - Log[1 + r]/(r^3*(1 + r)^2),
       p[ro] == 1/10^7
     },
     p,
     r][[1]];

Notice that I used p instead of p[r]. Now, we create a new function, 
npressure, which increases the precision of its argument before 
computing the pressure:

npressure[r_?NumericQ] := pressure[SetPrecision[r, 30]]

Plotting npressure experiences no numerical instability:

Plot[npressure[r],{r,ro,10^4},PlotRange->All]

Carl Woll
Wolfram Research


  • Prev by Date: Re: Graphics3D polygon face colors
  • Next by Date: FileDate, or rather Microsoft
  • Previous by thread: Plot resolution
  • Next by thread: Re: Plot resolution