Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Lists and speed

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30142] Lists and speed
  • From: Stuart Humphries <s.humphries at bio.gla.ac.uk>
  • Date: Tue, 31 Jul 2001 04:27:14 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

About a month ago I submitted a question about lists  and received some 
very useful help (summarised below). However, although my program (a 
coupled map lattice for population dynamics) now works well with Ted 
Ersek's modifications, it still takes over 20 minutes (compared to the 
original 40 minutes) to run.
A colleague has just coded the same thing in another system, which runs in around 40 _seconds_...is this unusual?
I was happy to trade-off speed for faster development time compared to 
Pascal etc, but the difference here seems so huge that I'm concerned that 
my Mathematica programming is still way-off.
Any thoughts welcome.
Thanks
Stuart


>The program considers a 10 by 10 lattice of populations, and implements 
>equations for population growth and then manipulated the lattice (list) to 
>incorporate dispersal between populations, the whole process is repeated 
>for about 1200 'generations' , and this itself form part of a larger (100+ 
>) repetition.

>Stuart Humphries had a Mathematica program that was running rather slow.
>The poor performance was most likely do to the use of  AppendTo[data, ..]
>inside a Do loop.
>Instead of using AppendTo[data, ...] use the following:
>
>
>Do[  (
>    blah; blah; ....;
>    data = {data, stuff}
>), {n, 500}]
>Flatten[data]
>------------------------
>However, that will not work if the final result is supposed to be a matrix.
>In that case do the following instead.
>
>
>Module[{h},
>    Do[  (
>       blah; blah; ....;
>       data = h[data, stuff]
>    ), {n, 500}]
>    List@@Flatten[data]
>]
>
>
>--------------
>Cheers,
>Ted Ersek



Dr Stuart Humphries
FBA/NERC Research Fellow

Division of Environmental and Evolutionary Biology
Graham Kerr Building
University of Glasgow
Glasgow G12 8QQ
Tel: +44 (0)141 330 6621
Fax: +44 (0)141 330 5971
http://www.gla.ac.uk/Acad/IBLS/DEEB/sh



  • Prev by Date: Re: Two factors of (10^71-1)/9 = R71
  • Next by Date: Re: Pattern matching "on the fly"
  • Previous by thread: Solving linear equations with symbolic RHS