Sharing ideas and inspiration for engagement, inclusion, and excellence in STEM
With coding becoming increasingly important in both engineering and physics research, the free and adaptable Python programming language can be a powerful tool in teaching coding activities in your physics and engineering courses.
Save Time
Between the two of us, we have more than 30 years experience using coding languages in the engineering industry and in computational physics instruction. When we first used Python, the download file took hours to compile. Today, the free Anaconda® distribution, the latest version of Python, installs in minutes.
Manually processing and testing data in a college engineering course consumes valuable time. But with Python, students can rapidly process data to validate designs using complex equations for engineering projects.
Computational Physics and Python
Solving problems that require iterative calculations are only possible using computational methods, so they are often left out of college physics courses. Python is a common solution for adding computation to undergraduate physics instruction.
Take Measurements in Experimental Setups
In the engineering classroom, Vernier has long supported the use of LabVIEW™ for data acquisition and sensor-control projects. With the application of Python, students have another option to learn a popular and useful coding language. Using the Vernier module for Python, named godirect, students can connect to and read measurements from many Go Direct® sensors within a Python program.
Students can take measurements in experimental setups from a Go Direct Acceleration Sensor with this simple codebase and use the readings from the gyro and accelerometers to determine pitch and roll. They can monitor position using a Go Direct Motion Detector or use a Go Direct Light and Color Sensor to control an Arduino™ microcontroller.
Add the Visual Elements Necessary for Student Understanding
While it is fairly easy for students to do iterative calculations on a spreadsheet, VPython adds a visual element. Even with limited programming experience, students can create navigable 3D models and animations. Here are some examples of how you can use VPython in your classroom.
Example 1: Write a short program that models the behavior of a mass on a spring. If students model their computational system on a real system used in class, with the same mass and spring constant, they will instantly see that the choice of too large a Δt makes the computed oscillation look very strange.
Example 2: Create a “live” freebody diagram, which is a diagram of a ring with three forces acting on it—a hanging mass and two supporting strings. One string is fixed to a ring stand and the other is attached to the Go Direct® Acceleration Sensor. When the program runs, it collects force and acceleration data from the force sensor and uses that “live” information to draw a force vector that points in the same direction as the sensor and is proportional in length to the force on the ring from the sensor.
Create Navigable 3D Models and Animations with Limited Programming Experience
An excellent example that helps explain the potential of VPython is the binary star simulation. In this binary star simulation, notice the presence of the Universal Gravitation equation and the momentum updating equations, in which the momentum of each star is based on the previous momentum plus an impulse term. Then the position of each star updates by adding vΔt to the previous position, where Δt is defined just prior to the loop. When students create their own simulation like this, they can alter the Δt, the masses of the stars, or the stars’ initial momenta, and compare the behavior of the system in each case.
Enhance Your Python Projects
Your students can complete unlimited projects in their physics or engineering courses when integrating Python. The open-source platform is adaptable and with the use of modules offers the ability for visual elements or sensor integration, among many other applications.
Here are some helpful links to learn more:
Share this Article
Sign up for our newsletter
Stay in the loop! Beyond Measure delivers monthly updates on the latest news, ideas, and STEM resources from Vernier.