Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9651 > unrolled thread

Re: dynamically generating options

Started byChristoph Lhotka <christoph.lhotka@fundp.ac.be>
First post2012-04-15 07:17 +0000
Last post2012-04-15 07:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: dynamically generating options Christoph Lhotka <christoph.lhotka@fundp.ac.be> - 2012-04-15 07:17 +0000

#9651 — Re: dynamically generating options

FromChristoph Lhotka <christoph.lhotka@fundp.ac.be>
Date2012-04-15 07:17 +0000
SubjectRe: dynamically generating options
Message-ID<jmdslt$aar$1@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.
>
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web