The idea is to create a simulation for ideal gas motion in a container that have a hole and then find the speed distribution for the gas particles that leave the box through the hole. I have a seminar work tomorrow and any help would be very appreciated.

  • 2
    $\begingroup$ Is this question about visualizing the phenomenon, or also simulating it? Also, are you after a three-dimensional, or two-dimensional diagram? What have you tried this far? $\endgroup$ – kirma Jun 22 '15 at 16:26
  • 1
    $\begingroup$ …and can you show us anything you've attempted? $\endgroup$ – J. M.'s technical difficulties Jun 22 '15 at 16:26
  • $\begingroup$ It is a 3D animation. Up to now i have drawn only a container with some random points in it. Im trying to figure out how to make them move. I haven't used mathematica before for such seminar works and I new in this stuffs $\endgroup$ – BIA NKA Jun 22 '15 at 16:30
  • 1
    $\begingroup$ This kind of problem is not trivial by most standards -- it goes well beyond the scope of this Q/A. However if you encounter any specific problems along the way feel free to ask. $\endgroup$ – Sektor Jun 22 '15 at 16:34
  • $\begingroup$ Related:Creating an animation illustrating the time-evolution of a pre-computed orbit $\endgroup$ – Jens Jun 22 '15 at 17:20

I'll provide an starting point for 2D case with single particle. Collisions with other particles are likely to be hard to model (or at least require adding an massive amount of WhenEvent rules if implemented this way), since NDSolve and WhenEvent tend to miss discrete events. Also, 3D case would be considerably more complicated to build; likely to take more time than you have.

In this case improvements, or rather, improvisation is literally left as an exercise to the reader. This code requires v10 for its use of RegionMember.

Module[{line, eventactions, sol},
 (* the box boundary *)
 line = {{-1, 1/4}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}, {-1, -1/4}};
 (* actions at the boundary built from box *)
 eventactions =
      (* BooleanMinimize somehow compensates flimsiness of WhenEvent.
         also, evaluate and simplify equations here before run of NDSolve. *)
        (* is the particle on the line segment? *)
         Line[{##}], {x[t], y[t]}], (x[t] | y[t]) \[Element] Reals], 
     (* action at boundary for each line segment: bounce *)
      {a[t], b[t]} -> 
       ReflectionTransform[RotationTransform[\[Pi]/2][#1 - #2]][{a[t],
          b[t]}]]] & @@@ Partition[line, 2, 1];
 sol = NDSolve[{
    (* model of motion *)
    x'[t] == a[t], y'[t] == b[t],
    (* initial parameters *)
    x[0] == 0, y[0] == 1/2,
    a[0] == 1, b[0] == Sqrt[2],
    (* actions at boundary *)
    Sequence @@ eventactions},
   {x, y}, {t, 0, 12}, DiscreteVariables -> {a, b}];
 Animate[Graphics[{Line@line, Point[{x[t], y[t]} /. sol]}],
  {t, 0, 12}, AnimationRate -> 1/2]]

enter image description here

(It seems GIF export has some issues in this case in the end of the animation...)

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.