Skip to content

Balanced Forces VPython assignment draft

September 3, 2011

I’ve finished the first draft of the second computational modeling assignment, which this time explores balanced forces, by creating an objects that moves across the screen, and then allows students to change the forces acting on the object and observe how they affect the motion of the object.

Here is the assignment:

View this document on Scribd

Here is the code to download and try out using VPython: Unit 2 Program.

I welcome any feedback you may have about this assignment.

8 Comments leave one →
  1. September 4, 2011 10:21 pm

    This is a ‘blog series’ I am going to follow closely. I like VPython, and have had my Jr/Sr students do the vpython tutorial for the past two fall semesters as a “trial run” to see how the physics student population at my school handles the programming concepts. What I’ve found is that even just the tutorial helps them to become more mindful of their deliberate actions (e.g., putting a period or space where you needed to put a comma actually matters, so pay attention).

    I have also noted that all student have been able to successfully complete the tutorial without an excessive amount of guidance from me. I mostly watch and provide a sounding board, rather than getting too involved in their work.

    My student population tends to be a mix of students currently enrolled in trig, or currently enrolled in calculus; roughly 50/50 gender ratio, and probably 25% “hard core” science students and the remainder “interested”, “pre-professional”, or “otherwise motivated” (e.g., seeking graduation honors).

    I hope to eventually develop a computational ‘module’ for each unit in my course, which on the mechanics end is modeling physics (and I’m working on making the thermo/E&M/waves/optics/modern part more ‘modeling’ based). Or…I’ll be glad to ‘steal’ from you if you end up doing all the work first!

    • September 5, 2011 10:04 am

      I’ve worked with John on this project a bit. And I think that you might be interested in checking out PhysUtil for VPython. John, myself and others have worked on this module to relieve some of the overheard in creating highly visual simulations. Check out and enjoy!

      • September 25, 2011 5:16 am

        I downloaded physutil v1.12 today, and it doesn’t pass its own unit tests. The problem is that Hours:minutes:seconds labels have the fractions of seconds incorrectly separated with a colon, rather than a decimal point. There are three places to fix (“00:00:00:00” => “00:00:00.00” twice and “01:05:23:65″ =>”01:05:23.65”). It looks like Daniel Borrero made changes in 1.12 without running the unit tests, since the tests fail precisely because of the change he introduced.

        • September 26, 2011 7:09 am

          Hmm. I’ve passed this along to Danny to see if he can help out.

        • September 26, 2011 8:45 pm

          Thanks for pointing this out. I mentioned it to Danny, and he got it fixed and issued a new release. You can find it here: Phyutil 1.13

    • September 6, 2011 12:08 am

      Thanks—I’m going to try to put up everything I put together here on the blog, and also in the google ECT forum that Phil moderates. We’re building a very strong community of folks interested in computational modeling, particularly with python.

  2. September 5, 2011 1:29 am

    Cool stuff, IMHO it seems like a lot of code just to answer that question. But if you are reusing the code then its no big deal. I like that you are using this to create systems for interaction. I like this stuff for science for the same reason I like Geogebra for math. It makes it interactive and come alive. The modeling curriculum is all the better off with the addition of computer science.

    I don’t see a link to the video so I can’t confirm that this isn’t mentioned in there but I wouldn’t know that a mouse click is needed to start the simulation until I read the code. Could you put that into the instructions or put in a label saying “Click to start”. Unless the students are expected to read the code.

    Are the students building this code and then you are asking questions based on tweaks modifications? I imagine that would be difficult with time constraints. Perhaps there might be a couple of students like you mentioned before who would be interested in helping you build simulations. I might suggest packing a lot of this into a class and functions. Physutil/Vpython are classes and methods/functions built upon regular python and it saves a ton of code for the creator (e.g. I only have to type sphere() to make a sphere instead of having the code in the script.

    Since you already include the in the zip file you might also have another module where you keep a lot of the initialization and distracting stuff and then just import it like you do for physutil and vpython. This will make the code simpler for the student as well as saving you the need to retype.

    Reusing and pasting or importing code is an essential practice for programmers and has saved me a lot of time. I often turn these into mini assignments in themselves , for example “a certain function takes 2 numbers and returns whether or not it is prime” take out your whiteboards or pull up Python and write your own version. By thinking modularly, students can start to think of functions as tools in their toolbox. Already your assignments are helping them to see patterns, functions will help them to think algorithmically.

    If you haven’t tried functions/classes before its a little tricky at first but it pays off in dividends with saved time and clearer code. Let me know if you want any help, I just blogged about the update to my favorite Python Tutorial: How to Think Like a Computer Scientist ( which does an great job of explaining it. I use it for my students to reference all the time.

    Thanks for sharing yet again!

    • September 6, 2011 12:10 am

      Thanks for the awesome feedback, as always. I think you’re right that this is a pretty dull program with too much code, but since we’re just getting started, I also don’t want to hide everything away with functions and import statements. I want them to see that they can take on a long piece of code and make small edits that have dramatic effects on the output of the program. But I do really like your ideas, so I made the idea of cleaning up the code with import statements and functions an extension for this assignment, since I couldn’t think of any really good physics extensions.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: