       NDSolve -- n-body indexing ([[]]) problem

• To: mathgroup at smc.vnet.net
• Subject: [mg112204] NDSolve -- n-body indexing ([[]]) problem
• From: Greylander <greylander at gmail.com>
• Date: Sat, 4 Sep 2010 04:02:24 -0400 (EDT)

```Hello.

I am attempting to some very simple 2-D, n-body problems.  Here is an
example.

s = NDSolve[{y''[t] == Table[Table[Max[(y[t][[i]][[j]] + .001)^-3 - .
001, 0], {j, 1, 2}], {i, 1, 100}],
y' == Table[{RandomReal[], RandomReal[]} - .5, {100}],
y == Table[{RandomReal[], RandomReal[]}, {100}]},
y[t],
{t, 0, 20}]

The details of the y'' equation are not important.  This could just as
easily be an n-body gravitation problem.  As you can see from y, y
is a list of form { {x1,y1}, {x2,y2}, ... }, a list of N points --
coordinates of the N bodies.  y'' for each coordinate of each point
can be a function of any/all of the other coordinates of the same
point or of the other particles.

The problem is that Mathematic applies the Part[] function prematurely
in y[t][[i]][[j]], which makes the y'' equation incorrect.  I have
tried numerous approaches, some where I use Part[] on y[t], as above,
and others where I apply listable operations to y[t] as a whole.  The
latter results in dimension mismatch error between the y'' equation
and the initial conditions.  I have also tried Hold and ReleaseHold,
but if there is a way to get them to work here, I have not found it.

I have tried finding demo examples that do something like this, but
the only examples I have found so far treat each coordinate of each
body as a separate variable:  x1, y1, x2, y2, x3, y3... and so forth.
This is not feasible for N=100s of particles, especially where I may
want N itself to be a parameter.

This is such a simple problem, that I am sure I am just overlooking
some aspect of the Mathematica language which makes this easy.  Or
perhaps there is a somewhat different approach that achieves the same
(desired) result.

I need to understand the general approach to solving n-body problems
with NDSolve, with n large and arbitrary, so that making the dependent
variable a list or list-of-lists is necessary (unless there is some
other trick).  The specific equations above are not important.

For example, when I specify the dependent variable y[t] -- is there
some way to specify it's list structure before it is otherwise
defined?

Hope someone out there can help.  Thanks!

```

• Prev by Date: Re: nonlinearfit for data with errors in both coordinates
• Next by Date: Re: syntax-aware selection in palette notebook
• Previous by thread: Re: Time Series Data in Quarters [correction]
• Next by thread: Re: NDSolve -- n-body indexing ([[]]) problem