Message Boards Message Boards

Interactive Physics simulation software with Wolfram Language?


Good morning,

I'm a French physics and chemistry teacher looking for a replacement to the aging Interactive Physics simulation software. I'd like to know if Mathematica is the way to go.

Typically, I'd use it to model systems subjected to dynamic forces such as projectiles, orbiting masses, mechanic oscillators... Along with the simulation showing the movements, data would be collected and/or graphs displayed.

For example :

enter image description here

Is it easy to model the gravity field surrounding a planet ? Will I have to solve the satellite's movement equations and program the animation or will Mathematica do that for me ?

If in your opinion Mathematica isn't what I'm looking for, please let me know if you heard about something that would better suit my needs.

Thank you,


2 years ago

You will have to set up some equations, and then Mathematica can (numerically/analytically) solve them for you, and with the built in (List)ParametricPlot you will be able to plot those.

It just depends how much effort you want to put in to it. Within half an hour you should be able to make something that shows the trajectories of a system of masses.

Of course there is no built-in function that does exactly what you want, but with the wide variety of high-level functions it should be <20 lines of code I would estimate (depending on the complexity of course you look for of course).

To be honest, I would not know another piece of software that is as customisable as Mathematica and that is as easy as Mathematica. So Yes, go for Mathematica.

POSTED BY: Sander Huisman
2 years ago

Dear Ch'Prof,

There is an example animation at the end of this. Just evaluate the code.

I've been working on developing Mathematica content for teaching STEM subjects at MIT. I often get asked to develop content from an astrodynamics class.

I am going to cut and paste some code that I debugged for a colleague showing a Mars-Earth transfer orbit. Unfortunately, this is only debugged and not commented. I think you may see some of the benefits of teaching via coding like this. Imagine teaching your students to code this up, and not just watch it.

Again, this is not a good and compact example of WL programming style, but it works.

r11 = 1; r21 = 1.5237`; \[Mu]sAU = 0.000295912`; v1 = \
v2 = Sqrt[\[Mu]sAU/r21]
valpha = Sqrt[\[Mu]sAU (2/r21 - 2/(r11 + r21))]
deltav = valpha - v2
solmefunc[theta0_, alpha_] := 
 NDSolve[{(r1^\[Prime]\[Prime])[t] - r1[t]*th1'[t]^2 == -\[Mu]sAU/ 
   r1[t]*(th1^\[Prime]\[Prime])[t] + 2*r1'[t]*th1'[t] == 
    0, (r2^\[Prime]\[Prime])[t] - r2[t]*th2'[t]^2 == -\[Mu]sAU /
   r2[t]*(th2^\[Prime]\[Prime])[t] + 2*r2'[t]*th2'[t] == 
    0, (r3^\[Prime]\[Prime])[t] - r3[t]*th3'[t]^2 == -\[Mu]sAU /
     r3[t]^2, r3[t]*(th3^\[Prime]\[Prime])[t] + 2*r3'[t]*th3'[t] == 0,
    r1[0] == r11, th1[0] == 0, Derivative[1][r1][0] == 0, 
   Derivative[1][th1][0] == Sqrt[\[Mu]sAU/r11], r2[0] == r21, 
   th2[0] == 0, Derivative[1][r2][0] == 0, Derivative[1][th2][0] ==
    Sqrt[(\[Mu]sAU/r21)]/r21, r3[0] == r21, th3[0] == 0, 
   Derivative[1][r3][0] == alpha*deltav Sin[theta0], 
   Derivative[1][th3][0] == (v2 + alpha*deltav Cos[theta0])/r21}, {r1,
    th1, r2, th2, r3, th3}, {t, -100, 1000}]

 ParametricPlot[{rsol1[t - 99]*Cos[thsol1[t - 99]], 
   rsol1[t - 99]*Sin[thsol1[t - 99]]}, {t, 0, 500}, 
  PlotStyle -> {Blue, Thick}, AspectRatio -> 1, 
  PlotRange -> {{-1.6, 1.6}, {-1.6, 1.6}}],
   rsol2[t]*Sin[thsol2[t]]}, {t, 0, 500}, PlotStyle -> {Red, Thick}, 
  PlotRange -> {{-1.6, 1.6}, {-1.6, 1.6}}], 
   rsol3[t]*Sin[thsol3[t]]}, {t, 0, 500}, PlotStyle -> {Green, Thick},
   PlotRange -> {{-1.6, 1.6}, {-1.6, 1.6}}]]

Manipulate[{{rsol1, thsol1, rsol2, thsol2, rsol3, thsol3}} = {r1, th1,
     r2, th2, r3, th3} /. solmefunc[theta0, alpha]; Show[
    rsol1[t]*Sin[thsol1[t]]}, {t, 0, 800}, PlotStyle -> {Blue, Thick},
    AspectRatio -> 1, PlotRange -> {{-2.2, 1.8}, {-2.0, 2.0}}],
    rsol2[t]*Sin[thsol2[t]]}, {t, 0, 800}, PlotStyle -> {Red, Thick}, 
   PlotRange -> {{-2.2, 1.8}, {-2.0, 2.0}}], 
    rsol3[t]*Sin[thsol3[t]]}, {t, 0, 800}, 
   PlotStyle -> {Green, Thick}, 
   PlotRange -> {{-2.2, 1.8}, {-2.0, 2.0}}]], {{theta0, -Pi/3}, -Pi/3,
   Pi/3}, {{alpha, 1}, 1, 6}]

TimeGap = 83;
anim = Animate[
  ParametricPlot[{{rsol1[t - TimeGap]*Cos[thsol1[t - TimeGap]], 
     rsol1[t - TimeGap]*Sin[thsol1[t - TimeGap]]}, {rsol2[t]*
     rsol2[t]*Sin[thsol2[t]]}, {rsol3[t]*Cos[thsol3[t]], 
     rsol3[t]*Sin[thsol3[t]]}}, {t, 0, T}, 
   PlotStyle -> { {Blue, Thick}, {Red, Thick}, {Green, Thick}}, 
   AspectRatio -> 1, PlotRange -> {{-1.8, 1.6}, {-1.6, 1.6}}], {T, 0, 
   259 }]
POSTED BY: W. Craig Carter
2 years ago

Thank you for your answers guys,

So it seems like I should get into Mathematica. I can do that : I have 2 months to learn how to convert and adapt my simulations to this standard. I must admit I didn't understood much of what Craig posted but I got the idea and I think that was his point : what I want to do is feasible.

Today I've been watching 4 Modeling System videos without learning anything worth the time I spent. Available books online have pretty poor reviews.

Is there a good crash course for physicists or a Modeling System for dummies somewhere ?

Which licenses should I buy ? Please understand that as a French teacher, I will never get a refund for those, for no one will ever understand why I'm doing this.


2 years ago

As an educator you should be aware of a huge library (more than 10,000 submissions) of such applications available at the Wolfram Demonstration Project. For example, specifically for orbital motion you can search for three-body or look, say, for Astronomy category. Wolfram Language code and Mathematica notebooks are free to download and be adopted to your own purposes.

enter image description here

POSTED BY: Sam Carrettie
2 years ago

Thank you, I'm studying SystemModeler for 2 days now, and the learning curve is damn steep.

Thanks to the examples provided, I'm now able to have a brick submitted to gravity. I still need to figure out why it goes straight through the ground, though.

Thank you

edited to post questions elsewhere

2 years ago

Are you sure you need SystemModeler for this? I've never used SystemModeler personally, but I'd expect Mathematica to be the easier route for this type of a problem... (Mostly judging by the sheer number of really cool Demonstrations Project submissions.)

As for your specific questions, you may want to create a new thread for them and tag it as a question related to SystemModeler so that the right people will see it and answer.

POSTED BY: Bianca Eifert
2 years ago

I was inclined to think that SystemModeler would be better for me, as I wouldn't have to write as much code as with Mathematica, and I would automatically get a visual rendition of my models.

Am I wrong ?

2 years ago

Hm, I don't know. If you really want to minimize the coding, you might be right... So far I've only seen people use SystemModeler in conjunction with Mathematica, it seems to me that you'll probably have to learn both. That led me to wonder if it might not be easier to do the simpler cases in Mathematica exclusively. But I might be very wrong. After all, there is the catapult and of course the xkcd squirrel. Both of these are mechanical problems that should be fairly close to your use cases, so SystemModeler could be a great choice.

I'm sorry I can't be more helpful... By the way, I think it's awesome that you're willing to go the extra mile for your students!

POSTED BY: Bianca Eifert
2 years ago


I saw you posed your last question in the SystemModeler forum, so I went ahead and answered you over there. You are indeed correct that SystemModeler will allow you to do less programming. By using the the built in blocks, you do not have to worry about the specifics of the implementation, and rather focus on building your system.

Of course, not everything can be included in the built in libraries. One such thing that is not included in the package is components that describes collision with ground. In the other thread, I included a small tutorial on how to create such a component. What you can do, is reuse that component in the future for other types of objects so that you only have to do it once. A video tutorial on how to make your own Modelica components can be found here.

The Modelica Standard Library, that is included with SystemModeler is an open source driven effort to collect reusable models from a wide array of different domains. If there is anything that you, as a new user, feel is missing that should be available out of the box, it is always interesting to hear. It might be something that can be included in the future!

I saw that you where also interested in orbiting masses. You might be interested in the PointGravity examples included in the MultiBody library, for example Modelica.Mechanics.MultiBody.Examples.Elementary.PointGravity.

point gravity animation

This shows two bodies orbiting around the origin and is accomplished by setting the "gravityType" parameter to PointGravity, causing all MultiBody objects to be pulled towards the origin. If they have an initial velocity (which is denoted v_0[3] and set in the "Initialization" tab of the MultiBody object) they will make an orbit.

body initialization

One very interesting model that uses point gravity can be found here: Controlling a Satellite Path. It is a model of a satellite orbiting the earth and has controls that provide thrust that keep it in orbit. It also shows how SystemModeler and Mathematica can be interfaced together. The last part might be a bit in-depth but if you find anything that interests you, do not hesitate to ask in the SystemModeler community. There are lots of people there that would gladly help out!

Regards, Patrik

POSTED BY: Patrik Ekenberg
2 years ago

Hello again, I highly recommend giving the students tools and the freedom to code and visualize simple to intermediate problems whether in Mathematica or System Modeler. My opinion is that Mathematica is preferable because the skills are transferable to other career and recreational skills. Plus, it will give the students access to other things such as big data, etc.

I agree with Patrik, there are many people to help you get started. I am giving a week master course in problem solving at EPFL in late July. I'll teach some mathematica skills, show how to solve and visualize a few problems, and then challenge students to solve their own. The class is for Materials Science PhD students. You would be welcome to join. If you wish to join, please contact me offline.

W. Craig Carter

POSTED BY: W. Craig Carter
2 years ago

Group Abstract Group Abstract