Say you start with 2 sets of 3D numbers: position & velocity.  You can
guess that one of your most common tasks might be calculating the next
position based on these, something like adding the current position to the
current velocity.  This might lead us to set it up this way for this use
case:
   pv=. <:+:2 10 3?@$0   NB. 2 quantities (position & velocity), for 10
points in 3-space.
   $+/pv                 NB. Add p to v -> 10 new 3D positions
10 3
   newposn=. +/pv        NB. We could assign this but
   pv=. newposn 0}pv     NB.   we only use the name once to update the
position plane
   pv=. (+/pv) 0}pv      NB. Update positions (avoiding the unnecessary
name)
It sounds like you want to model collisions so of course it would be more
complex than this but if you start this way and find it's no good for going
forward, it's easy to throw it away and try something else.  You probably
want to make the most commonly done things the easiest to do as I've tried
to demonstrate above for this simple problem; by ordering the array the way
we did, we made this operation simple.







On Sat, Jul 15, 2023 at 11:03 PM Ak O <akin...@gmail.com> wrote:

> Hi Marcin,
>
> Have you considered using the Fold Family Operators (F.)?
>
>
> Ak
>
>
> On Sat., Jul. 15, 2023, 07:53 Marcin Żołek, <
> marcin.zo...@students.mimuw.edu.pl> wrote:
>
> > Thanks, your approach is the most convincing.
> >
> > Martin
> >
> > > On Jul 15, 2023, at 3:15 PM, Raul Miller <rauldmil...@gmail.com>
> wrote:
> > >
> > > I think the approaches you described are fine.
> > >
> > > That said, another approach would be to think of your dataset as a
> > > table -- one row for each atom, with each column having different
> > > significance. coordinate x,y, z; velocity x,y,z; force x,y,z,  So, if
> > > you had 42 atoms, your data would be a 42 by 9 matrix.
> > >
> > > Or, perhaps it would be better to distinguish x,y,z from
> > > coordinate/velocity/force (the 42 atom example being represented with
> > > a 42 by 3 by 3 array or perhaps more conveniently a 3 by 42 by 3
> > > array).
> > >
> > > This last approach might have an implementation something like:
> > >
> > > do_step=: positions_update, velocities_update,: forces_update
> > >
> > > where each of the update verbs obtains the requisite information from
> > > its y argument.
> > >
> > > I hope this makes sense,
> > >
> > > --
> > > Raul
> > >
> > >
> > > On Sat, Jul 15, 2023 at 8:18 AM Marcin Żołek
> > > <marcin.zo...@students.mimuw.edu.pl> wrote:
> > >>
> > >> I am learning J and writing a program in this language to simulate a
> > physical phenomenon of interactions between atoms (each atom is described
> > by coordinates, velocities, forces, etc.). I am wondering how to store
> data
> > in such a simulation.
> > >>
> > >> The simulation involves applying a function that performs a single
> > simulation step several times:
> > >>
> > >> do_step^:42 initial_data
> > >>
> > >> Simulation step consists of several substeps. Which storage option is
> > better or is there other way than the ones listed below?
> > >>
> > >> 1) Data stored in public nouns (one noun is a matrix of coordinates of
> > atoms, another noun is a matrix of velocities of atoms, etc.). Then
> do_step
> > calls substep functions that overwrites these public nouns:
> > >>
> > >> do_step =: monad define
> > >>    velocities =: forces update_velocities velocities
> > >>    positions =: velocities update_positions positions
> > >>    ...
> > >> )
> > >>
> > >> 2) Data stored in an array of boxes (in the first box an array of
> > coordinates of atoms, in the second box an array of velocities of atoms,
> > etc.). Then do_step is the composition of all substep functions and each
> > substep function is a monad that creates modified array of boxes using
> m} :
> > >>
> > >> do_step =: monad : 'do_substep_k ... do_substep_2 do_substep_1 y'
> > >>
> > >> Martin
> > >> ----------------------------------------------------------------------
> > >> For information about J forums see
> http://www.jsoftware.com/forums.htm
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


-- 

Devon McCormick, CFA

Quantitative Consultant
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to