Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am trying to represent the position of an object under freefall, but am completely lost. Here is my attempt so far:

time = 0;
increment = 10;
distance := 0 - time*(time*increment); 

{Dynamic[Refresh[{time++ 1, ClockGauge[DateList[]]}, UpdateInterval -> 1]],
 Dynamic @ distance, 
 Dynamic @ Framed[Graphics[Disk[{0, distance}, 10], 
                           PlotRange -> {{-2, 2}, {1, -1000}}]]}

Which results in:

enter image description here

The bar on the left should represent the position of the object under freefall, and the number to the right of the bar should represent its y coordinate. However this clearly accelerates way too fast way too soon.

Basically the main problem here is that I don't know how to translate the '10m per second per second' into a language that Mathematica can understand. Could someone help me with what formula to use?

share|improve this question

marked as duplicate by Kuba, Simon Woods, ciao, Sjoerd C. de Vries, ubpdqn May 2 '14 at 0:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I would build your simulation with a DynamicModule showing a table made with a Grid and controlled by a Trigger. First I would define a function that calculates distance when given time and acceleration.

dist[a_, t_] := a t^2/2

Next I would get the basic functionality right. A grid showing time and distance with a trigger to control it.

With[{a = -9.8, dmax = -1000.},
  With[{tmax = Sqrt[2. dmax/a]},
    DynamicModule[{t = 0., d = 0.},
        {Dynamic @ t, Dynamic[d = dist[a, t]]},
        {Trigger[Dynamic @ t, {0., tmax, 1}, 1], SpanFromLeft}


Only after the basic stuff was debugged, would I add the fancy stuff -- headers and gauges.

With[{a = -9.8, dmax = -1000.},
  With[{tmax = Sqrt[2. dmax/a]},
    DynamicModule[{t = 0., d = 0.},
        {Style["Time", "SB"], Style["Distance", "SB"]},
        {Dynamic@t, Dynamic[d = dist[a, t]]},
        {AngularGauge[Dynamic @ t, {0, Ceiling @ tmax}, ScaleDivisions -> {3, 5}], 
         VerticalGauge[Dynamic @ d, {0, dmax}]},
        {Trigger[Dynamic @ t, {0., tmax, .1}, 1.], SpanFromLeft}
      }, Frame -> All]


The above implements no more than the basics of what you asked for. There is no end or refinement that could be done to make it prettier. Nevertheless, I think it provides a good example of how Mathematica provides us all the tools needed to write simple physics simulations in very few lines of code.

share|improve this answer

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