Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shawn Weatherford Saint Leo University

Similar presentations


Presentation on theme: "Shawn Weatherford Saint Leo University"— Presentation transcript:

1 Computational Physics in the Introductory Course with Glowscript: A Glow Party, Part 1
Shawn Weatherford Saint Leo University FL-AAPT Fall Conference Workshop 2016 With significant contributions from Rhett Allain, Southeastern Louisiana Univ.

2 Overview and Goals Numerical Calculations in Algebra-based Physics
Explore and modify a working example program in 1D (constant v) Create a working program in 1D for accelerated motions Develop 3D animation modeling fan cart Extend the fan cart program to simulate projectile motion. Using arrows to represent vector quantities

3 Why do this? Iterative thinking: Real-world physics
Forces act over time, continually updating the dynamics of objects in the natural world Computational code resembles physics equations (with small differences) Real-world physics 3D simulation assists with evaluating the program and any physics errors in the program. Great for lab! After students perform an experiment to measure the average force acting on a fancart, students can write a program modeling the experiment. Other Examples: Calculate the E field at several locations around a charged object, dipoles, improve student understanding of relative position vectors, investigate inverse- square law in gravitation and electric forces, Find spring constant of a mystery spring, then oscillate it in 3D. Phys21: Preparing Physics Students for 21st Century Careers (AAPT, APS)

4 Glowscript and Trinket
Python Write programming code which resembles physics equations VPython – adds a visual module producing real-time navigable 3D environment. Glowscript – VPython in the web browser (requires login) Trinket – share example programs, editable, preserves master (no login) Recently added Glowscript to its programming environment.

5 Example from 1D motion A cart, at rest on one end of a horizontal track, is given an initial velocity of 1.2m/s. How far has it traveled after 5 seconds? Given t0 = 0s, at t=5s, the cart is now 6m from the left side of the track.

6 Numerical Model Rather than completing one calculation over the 5 seconds, complete 5 calculations with 1 second increments, updating the position of the cart after each interval Why would we want to do this? No one would! Let’s write a program to create a while loop to perform these calculations

7 Program Structure https://trinket.io/glowscript/b7f2f43aed
x = vec(0,0,0) #x is now a vector quantity t = 0 #t is scalar v = vec(1.2,0,0) dt = 1 #Interval length while t < 5s: #Note the colon x = x + v*dt #Items in loop are tabbed t = t + dt #updates variable tracking iterations print(x) #a print statement appearing in the output window of the variable x. Since this is outside of the loop, it will only print the final value of x. Initial Values Loop

8 Modify the initial values and duration of loop
Complete 25 loop iterations instead of 5. Where is the cart after 6.3 seconds? Display a print statement after the loop is complete. What if the initial velocity is (0.2,0,0) m/s? What if the initial velocity is (0.2,-3,0) m/s?

9 Constant non-zero Acceleration
The cart’s fan attachment provides a constant acceleration of 0.1 m/s2. How far does the cart travel, starting from rest, after 5 seconds? x = 1.25 meters. Now write the lines of code in the loop of the new program representing these calculations.

10 Euler-Cromer Error scales with dt. Picking a smaller ∆t improves accuracy of the numerical calculation at a cost. Why not just use average velocity?

11 Your turn – modify the program to do the following:
How long will it take the cart to travel down the length of the track (2 meters)? Reverse the fan so that it provides a negative acceleration. How long will it take to reverse directions. What initial speed of the cart will allow it to travel down the length of the track?

12 box(pos=vec(x,y,z), size=vec(length,height,depth), axis=vec(0,0,0))
Adding 3D objects Now let’s create a 3D scene with a box object representing the cart and another one representing the track. In general: box(pos=vec(x,y,z), size=vec(length,height,depth), axis=vec(0,0,0)) The pos attribute used to move the center of the box to a specific coordinate location. The axis attribute is used to rotate the box. Add code below, then run to check for syntax errors.

13 Why didn’t the cart move?
Need to change the calculation of x in the loop to instead update the position attribute of the cart. x = x + v*dt becomes cart.pos = cart.pos +v*dt Don’t forget to change any print statements referencing x.

14 Next steps: What initial speed of the cart will allow it to just reach the end of the track before reversing directions. Add gravity. Turn this into a projectile motion program. Use a if statement to break the loop if the y coordinate for the position of the cart becomes negative. Go to the help and read about arrows. Try to create an arrow attached to the cart during the simulation and represents the acceleration of the cart. Hint: pos attribute represents the tail of the arrow. axis attribute represents the length and direction of the arrow.

15 Extra Create a second cart on the opposite end of the track, with an acceleration towards the left end of the track of ax =-0.15 m/s2. Where and when do the two carts meet on the track? Both carts intial travel towards each other from rest. Create a graph using cartpos1 = series(color=color.green) and cartpos2=series(color=color.yellow)somewhere before the loop. In the loop, plot a curve representing each cart’s position vs time. Call each cartpos1 and cartpos2: cartpos1.plot(t,cart1.pos.x) cartpos2.plot(t,cart2.pos.x)

16 Physics Curriculums and Support for using Glowscript
Matter & Interactions for Calculus-based Physics Many activities are easily adapted for algebra-based students Rhet Allain’s Glowscript VPython Tutorials


Download ppt "Shawn Weatherford Saint Leo University"

Similar presentations


Ads by Google