MathGroup Archive 2012

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

Search the Archive

Re: dynamically generating options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126075] Re: dynamically generating options
  • From: Christoph Lhotka <christoph.lhotka at fundp.ac.be>
  • Date: Sun, 15 Apr 2012 03:16:36 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201204140713.DAA27793@smc.vnet.net>

Dear Jason,

please take a look on this simplified example:

n = 3;
vars = x[#][t] & /@ Range[n];
equs = x[#]'[t] == -x[#][t] & /@ Range[n];
init = x[#][0] == # & /@ Range[n];
nsys = Join[equs, init];
even = vars;
dirs = Table[1, {n}];
acts := Table[Sow[{i, t}], {i, 1, n}]

which defines n uncoupled first order ode's with different initial 
conditions.

( As you can see I defined acts with set delayed :=  )

Now try

{sols, data} = Quiet[NDSolve[nsys, vars, {t, 0, 10 Pi},
     Method ->
      {"EventLocator",
       "Event" -> even,
       "Direction" -> dirs, "EventAction" :> acts}] // Reap]

which seems to work in a proper way:

data /. {i_Integer, t0_Real} :> (sols[[1, i]] /. t -> t0)

Does it help you with your N-body code?

Best,

Christoph



On 04/14/2012 09:13 AM, 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.
>
>




  • Prev by Date: Re: computing derivatives and limits
  • Next by Date: Re: What characters are allowed in mathematica variable names? i.e. how
  • Previous by thread: dynamically generating options
  • Next by thread: Re: dynamically generating options