Re: Lists and speed

*To*: mathgroup at smc.vnet.net*Subject*: [mg30171] Re: Lists and speed*From*: "Carl K. Woll" <carlw at u.washington.edu>*Date*: Wed, 1 Aug 2001 02:19:26 -0400 (EDT)*Organization*: University of Washington*References*: <9k5qp5$ha6$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi Stuart, Without knowing the details of your problem, I can only suggest that you should look into using the functions ListConvolve or ListCorrelate. These are very useful functions for lattice problems, and they are extremely quick. Carl Woll Physics Dept U of Washington "Stuart Humphries" <s.humphries at bio.gla.ac.uk> wrote in message news:9k5qp5$ha6$1 at smc.vnet.net... > 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 > >