MathGroup Archive 2010

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

Search the Archive

Re: local variables - Module, For loop

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113092] Re: local variables - Module, For loop
  • From: Sebastian Schmitt <sschmitt at physi.uni-heidelberg.de>
  • Date: Tue, 12 Oct 2010 13:51:23 -0400 (EDT)

Bill Rowe wrote:
> In[5]:= Timing[Sum[k, {k, n}]]
> 
> Out[5]= {0.393106,500000500000}
> 
> In[6]:= Timing[Sum[k, {k, m}] /. m -> n]
> 
> Out[6]= {0.08371,500000500000}
> 
> Each code snippet does exactly the same thing and produces
> exactly the same sum. But as you can see, using For is the
> slowest method.

Dear Bill!

Thank you very much for your detailed answer!

Interesting that the last version is so much faster. Is it only due to
numeric vs. algebraic?

Cheers,

Sebastian


  • Prev by Date: Re: How to solve this differential equation? (harmonic
  • Next by Date: Re: Graphics3D. How to join random points with a single
  • Previous by thread: Re: local variables - Module, For loop
  • Next by thread: Re: local variables - Module, For loop