4
$\begingroup$

When I plotted an undefined function, Mathematica also spends considerable time to process it. It returns a blank figure necessarily. What confuses me is where the Plot spends the time.

For example, assuming that I forgeted to define the function f, I execute the code below. After a moment, I will get a blank graphics.

Plot3D[Im@f[1/4, u + I v], {u, -2, 2}, {v, -2, 2}, Mesh -> None,  
       PlotStyle -> Directive[Opacity[0.7], Orange], ImageSize -> Large, PlotPoints -> 50]

During this moment, what happened to Mathematica?

$\endgroup$

1 Answer 1

3
$\begingroup$

If you enclose the Plot command with Timing, you can see that it does take some time, on my computer, about 0.05 seconds.

 Timing[Plot3D[ ... ]]

You can see what it's doing using

 Trace[Plot3D[ ... ]]

The answer is that it's doing a lot! It's going through lots of possible options, lots of system calls, lots of Charting, some Legends, and then some Graphics3D=$fail. Then you get the empty plot. All that in only 0.05 seconds!

$\endgroup$
7
  • 1
    $\begingroup$ It takes 20 seconds for me! $\endgroup$
    – cmc
    Apr 3, 2013 at 13:51
  • $\begingroup$ It takes 20 seconds in Mathematica 8 and 0.04 second in Mathematica 9. $\endgroup$
    – cmc
    Apr 3, 2013 at 13:54
  • 1
    $\begingroup$ @cmc I get 2.1 and 0.03, respectively. It runs faster on 9 because it processes the function differently, figuring out it is undefined pretty quickly. $\endgroup$
    – rcollyer
    Apr 3, 2013 at 14:02
  • $\begingroup$ @rcollyer Those 2 seconds still seem quite excessive, and if the function is defined as f[x_, y_] /; x > 0 && y > 0 := 1, then it takes 2 seconds on v9 too. Also, these 2 seconds are measured on a relatively fast computer. I can imagine that a 5-6 year old laptop or a netbook would take 20 seconds. $\endgroup$
    – Szabolcs
    Apr 3, 2013 at 14:38
  • $\begingroup$ @bill s, thanks for the Trace. I have always wondered if such a command was available (yet, never went to look for it). $\endgroup$
    – Sos
    Apr 3, 2013 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.