MathGroup Archive 2006

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

Search the Archive

Re: Plot resolution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65081] Re: [mg65064] Plot resolution
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Tue, 14 Mar 2006 05:59:57 -0500 (EST)
  • References: <200603130459.XAA26855@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • References:
    • Plot resolution
      • From: "Laurentiu Caramete" <laurentiu.caramete@googlemail.com>
  • 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