Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3640

Re: Incredible slow Plot

From DrMajorBob <btreat1@austin.rr.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Incredible slow Plot
Date 2011-07-10 09:01 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ivbppv$o2o$1@smc.vnet.net> (permalink)
References <201107091135.HAA13652@smc.vnet.net>

Show all headers | View raw


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@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@yahoo.com

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Incredible slow Plot DrMajorBob <btreat1@austin.rr.com> - 2011-07-10 09:01 +0000

csiph-web