MathGroup Archive 2012

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

Search the Archive

Re: dynamically generating options

  • To: mathgroup at
  • Subject: [mg126091] Re: dynamically generating options
  • From: David Bailey <dave at>
  • Date: Mon, 16 Apr 2012 06:09:25 -0400 (EDT)
  • Delivered-to:
  • References: <jmb89l$r6p$>

On 14/04/2012 08:17, Jason wrote:
> I would like to generate options for the differential equation solver
> dynamically.  For example, in an n-body system where I don't know
> ahead of time how many bodies are in the system---the equations for
> the integrator are generated based upon how long the list of objects
> is.
> I would like to create the following option in NDSolve:
> Method->{"EventLocator", "Event"->{x[1][t],x[2][t],...,x[n][t]},
> "Direction"->{1,1,1,...},
> "EventAction":>{Sow[{1,t}],Sow[{2,t}],...,Sow[{n,t}]}
> But, after many different attempts I'm stumped.  The delayed rule
> causes some problems, the "Sow" or "AppendTo" (which I used before)
> also causes problems because it evaluates when I generate the table
> for the "EventAction"
> I can't get this to work and am currently just doing it by hand on a
> case-by-case basis (which is not ideal).
> Any help is appreciated.
Try something along these lines:


Note that the Sow command is created inside a Hold - so it doesn't 
evaluate ahead of time - then we swap the head to NDSolve, and the 
action starts.

Disclaimer: Ideally, I like to check code suggestions with Mathematica, 
but you didn't present a complete example!

David Bailey

  • Prev by Date: Re: What characters are allowed in mathematica variable names? i.e. how
  • Next by Date: Re: Replace a vertical line in ListPlot
  • Previous by thread: Re: dynamically generating options
  • Next by thread: How to call Mathematica Boolean functions from non-Mathematica apps