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


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

Re: dynamically generating options

From Christoph Lhotka <christoph.lhotka@fundp.ac.be>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: dynamically generating options
Date 2012-04-15 07:17 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jmdslt$aar$1@smc.vnet.net> (permalink)
References <201204140713.DAA27793@smc.vnet.net>

Show all headers | View raw


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.
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web