Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*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 1996

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

Search the Archive

Re: Do loops

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3995] Re: Do loops
  • From: sherod at boussinesq.Colorado.EDU (Scott Herod)
  • Date: Tue, 14 May 1996 02:13:41 -0400
  • Organization: University of Colorado at Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

I've got code that computes solutions to systems of differential-delay
equations using a For loop and restarting things at the ending point of
the last run.  Below is the loop from an old version which shows how I
did it a little more clearly.

========================================================================

delay[num_, cT_, z_] := Block[{T = cT,y},
  f[t_] := 0.8;
  witchargs = {};
  For[k = 0, k <= num, k++,
    sol = NDSolve[{y'[t] + y[t] == f[t] ( 2 - f[t]^z),
        y[T*k] == f[T*(k+1)]}, y, {t,T*k,T*(k+1)}];

    f[t_] := Evaluate[(y /. Flatten[sol])][t-T];

    witchargs = {witchargs, t <= T*(k+1),
        Evaluate[(y /. Flatten[sol])][t]};
  ];

g[t_] = Apply[Which, Flatten[witchargs]];

ParametricPlot[{g[t],g[t-T]}, {t,T,T*k},
    PlotRange -> All]
];

===========================================================================

Notice that the I.C. in the NDSolve routine is found by substituting 
into the saved function f[t_] which was creating by shifting t back
by the delay time.

If you have more questions, please write me.

Scott Herod
Applied Mathematics
University of Colorado, Boulder
(sherod at newton.colorado.edu)



In article <4ms4ok$58v at dragonfly.wolfram.com>, g.kokkoris at ic.ac.uk (Giorgos Kokkoris) writes:
|> Dear fellows,
|> I am having a problem in trying to simulate biological invasions using
|> Lotka-Volterra dynamics.
|> I create a do loop with an NDSolve command at the end of it, in which I have
|> to use results from each iteration as my new initial conditions for the next
|> run of the do loop.
|> Obviously it does not work because I don't know how to do it correctly.
|> In each run the results of the next are independent from the results of the
|> previous run.
|> I can be more specific if I have to.
|> Thanks
|> Giorgos
|> Giorgos D. Kokkoris                  e-mail: g.kokkoris at ic.ac.uk
|> Centre for Population Biology        tel: +44-1344-294472    
|> Imperial College at Silwood Park     fax: +44-1344-873173   
|> Ascot, Berks, SL5 7PY
|> U.K.


==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Plotting 3D Hyperquadric models
  • Next by Date: NonlinearFit
  • Previous by thread: Re: Do loops
  • Next by thread: Question