MathGroup Archive 2005

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

Search the Archive

Re: Weird Plot problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59789] Re: Weird Plot problem
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sun, 21 Aug 2005 03:51:38 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 8/20/05 at 3:13 AM, h.l.owen at dl.ac.uk (Owen, HL (Hywel)) wrote:

>I'm seeing a weird plot problem. For reference, I'm using
>Mathematica 5.2 on Windows XP.

>First, using the package

><< Statistics`ContinuousDistributions`

>I define a Gaussian function modulated with a Sin[] as:

>ModulatedGaussian[x_, Ã?_, Ã?_, modamp_, modÃ?_] :=
>PDF[NormalDistribution[�, �],x](1 + modamp Sin[2  x/mod�])

I was able to figure out what you are trying to do here, but it would have been much easier had you posted this in Input form.

>I then Plot it using:

>Plot[ModulatedGaussian[x, 0.0, 1.0, 0.3, 0.2], {x, -5, 5}]

>Instead of seeing the modulation properly, I see the plot available
>at: http://www.astec.ac.uk/staff/owen/pictures/graph.png

>Plot[ModulatedGaussian[x, 0.0, 1.0, 0.31, 0.2], {x, -5, 5}] and
>Plot[ModulatedGaussian[x, 0.0, 1.0, 0.29, 0.2], {x, -5, 5}]
>(changing the modulation amplitude) both work fine. Generating the
>data also works:

>ListPlot[Table[{x,ModulatedGaussian[x, 0, 1, 0.3, 0.2]}, {x, -5, 5,
>0.01}], PlotJoined -> True]

>Anyone else get the same behaviour? Is it a bug?

It isn't a bug per se. The issue is the adaptive sampling algorithm Mathematica uses. For any rapidly oscillating function it is should always be possible to find a particular range where Mathematica happens to sample the function in such a way as to miss the oscillations. And this issue will always be there regardless of the sampling algorithm (at least for any deterministic sampling algorithm).

The simplest solution is to increase the number of points where Mathematica samples the function to be plotted, i.e., using PlotPoints->n where n is something larger than the default. But this is not the only solution. Any change in the plot parameters that causes Mathematica to sample at different points can potentially solve the problem. And if the function is time consuming to evaluate, it *may* be preferable to do something other than simply increase the value for PlotPoints. For example, changing {x,-5, 5} to {x, -5.01, 5.01} will cause Mathematica to sample the function at different points and likely will resolve the issue.

Try experimenting with the PlotPoints and the initial sampling range. I cannot tell you exactly what to use to get a specific result since the result produced by Plot is very machine/platform dependent.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: How to specify boundary conditions on all 4 sides of a plate for a steady state heat equation (PDE) using NDSolve? (Laplace equation)
  • Next by Date: Re: How to free memory?
  • Previous by thread: Re: Weird Plot problem
  • Next by thread: Re: Re: Weird Plot problem