MathGroup Archive 2001

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

Search the Archive

List problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29568] List problems
  • From: Stuart Humphries <s.humphries at bio.gla.ac.uk>
  • Date: Mon, 25 Jun 2001 20:42:23 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I'm very new to Mathematica, but I've cobbled together some code for a 
coupled map lattice model to look at population dynamics. My problem is 
that although the code generates the results I'm interested in, it runs 
incredibly slowly. I think I've narrowed the problem down to the way in 
which I handle the arrays (lists) of population densities, but I'm stumped 
as to how to code a faster implementation.
At present my code does the following:

Do[
(*Apply reproduction function to popn matrix, and remove dispersing 
individuals*)
popn1 = Map[remain, Map[f, popn]];
(*generate array holding dispersing individuals*)
dispersers = Map[m, Map[f, popn]];
(*divide all dispersers by 4 to get single direction dispersers*)
dispersers = dispersers/4;
(*distribute dispersers*) z = Table[z, {z, 1, 9}];
y = Table[y, {y, 2, 10}];
popn1[[1, All]] = dispersers[[10, All]] + popn1[[1, All]];
(*add bottom row to top*)
popn1[[10, All]] = dispersers[[1, All]] + popn1[[10, All]];
(*add top row to bottom*)
popn1[[All, 1]] = dispersers[[All, 10]] + popn1[[All, 1]];
(*add right col to left*)
popn1[[All, 10]] = dispersers[[All, 1]] + popn1[[All, 10]];
(*add left col to right*)
popn1[[z, All]] = dispersers[[y, All]] + popn1[[z, All]];
(*add to next row up from last 3 rows*)
popn1[[y, All]] = dispersers[[z, All]] + popn1[[y, All]];
(*add to next row down from first 3 rows*)
popn1[[All, z]] = dispersers[[All, y]] + popn1[[All, z]];
(*add to next col left from right 3 cols*)
popn1[[All, y]] = dispersers[[All, z]] + popn1[[All, y]];
(*add to next col right from left 3 cols*) popn = popn1;
(*If generations is between range specified, add total population size to 
ensemble array, and patch population size to patch array*)
If[g1 <= g <= g2, {AppendTo[ensemblesize, {Apply[Plus, Flatten[popn]]}], 
AppendTo[patchsize, {popn[[5, 5]]}]}]; Unset[popn1]; Unset[dispersers];
, {g, gmax}];



which is repeated for about 1200 'generations' (gmax), and this itself form 
part of a larger 100+ repetition.

I hope this makes sense to someone out there.
Any suggestions would be very welcome.

Thanks,
Stuart


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: How do I really get rid of previous results?
  • Next by Date: Re: FW: How to use Rules on Sequences?
  • Previous by thread: Re: Re: Unappropiate context in a package
  • Next by thread: Any ANOVA packages around?