MathGroup Archive 2011

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

Search the Archive

Re: Incredible slow Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120150] Re: Incredible slow Plot
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sun, 10 Jul 2011 05:00:44 -0400 (EDT)
  • References: <201107091135.HAA13652@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

We need details, so this is just a guess... but make sure NDSolve isn't  
being solved all over again for each plot point.

That is, you compute an Interpolation function, you Set (not SetDelayed) a  
function equal to it, and you use that function in the Plot.

Here's one way to do it right (for the first example in Help for NDSolve):

f = y /. First@
     NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}];
t1 = First@Timing[Plot[f@x, {x, 0, 30}, PlotRange -> All];]

0.012584

and here's a simple way to do it wrong:

f := y /.
    First@NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1},
      y, {x, 0, 30}];
t2 = First@Timing[Plot[f@z, {z, 0, 30}, PlotRange -> All];]

2.29799

t2/t1

182.612

That's a big difference in speed, you'll have to agree.

Bobby

On Sat, 09 Jul 2011 06:35:00 -0500, Iván Lazaro <gaminster at gmail.com>  
wrote:

> Hi!
>
> I'm trying to Plot a result from NDSolve. The problem is that when I
> pass this solution to Plot it takes an incredible long time (four
> hours for times between 0 and 1200) to plot. I tried generating an
> image file (.jpg, .eps, etc.) but that doesn't change anything. I
> tried also giving to Plot the option PerformanceGoal -> "Speed", but
> it gives me only half an hour less of waiting time. The other options
> (like PlotPoints -> Number, MaxRecursion -> 0 ) give an improvement
> but the image is ugly unless PlotPoints is high, which at the end is
> the same.
>
> I tried also asking for Plot only the last 200 units of time, trying
> to avoid the most oscillating part of the graphic, but that really
> doesn't help (and really it's not what I need).
>
> Finally, the resulting InterpolatingFunction, when evaluated outside
> Plot, evaluates fast, and a ListPlot using points returned by a Table
> works well, but the resulting graphic is insanely big (35, 36 Mb) if I
> put the points necessary to give account of the features of the
> dynamic.
>
> Unfortunately I can't give you an example because the equations I'm
> solving are too long, but I wonder if there is someway to generate the
> graphic, either on the interface or in a file, to not be so slow.
>
> Thanks in advance, and sorry for this vague question (which, by the
> way, without examples, is useless... by I had to give it a try).
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Bug 1+4/10
  • Next by Date: Enterprise level Mathematica idea
  • Previous by thread: Incredible slow Plot
  • Next by thread: Re: Incredible slow Plot