MathGroup Archive 2012

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

Search the Archive

Re: dynamically generating options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126091] Re: dynamically generating options
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Mon, 16 Apr 2012 06:09:25 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jmb89l$r6p$1@smc.vnet.net>

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:

n=4;
evac=Table[mySow[j,t],{j,1,n}]
NDSolve@@(With[{evac=evac},Hold[something,"EventAction":>evac]]/.mySow->Sow)

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
http://www.dbaileyconsultancy.co.uk



  • 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