Presentation is loading. Please wait.

Presentation is loading. Please wait.

1) Google “Vpython” 2) Go to first hit

Similar presentations


Presentation on theme: "1) Google “Vpython” 2) Go to first hit"— Presentation transcript:

1 1) Google “Vpython” 2) Go to first hit
Go do “Download for Windows”

2 3) Download 32 bit version. Notice there are two steps
First python 2.7.5 Then Vpython 2.7

3 Python and vPython software
Python is a “high level” software language. Like C++, Java, etc “interpreted” (like Perl) as opposed to “compiled” (like C) Used in lots of software games, movies, scientific situations vPython connects Python is pre-made visualization software. Lots of physics routines done in vPython.

4 # Dr. Fazzini’s first Python program # 27-Feb-2017 print 'hello world'
Open “VIDLE for python” Type in: # Dr. Fazzini’s first Python program # 27-Feb print 'hello world' Hit <F5> (Remember that tabs are important in python)

5 Let’s add a mistake and see what happens:
# Dr. Fazzini’s first Python program # 27-Feb print 'hello world' print 'hello world' Put a <TAB> here. Hit <F5> (Remember that tabs are important in python)

6 Add a Loop # Dr. Fazzini’s second Python program # 27-Feb index = 0 while index <= 100: print 'index is ',index index += 1 print ('I am done! ') Tabs go here. Hit <F5>

7 Add a Random Number from visual import * # Dr. Fazzini’s second Python program # 27-Feb index = 0 while index <= 100: print 'index is ',index, random.random() index += 1 print 'I am done' Hit <F5>

8 Slow things down so you can see
from visual import * # Dr. Fazzini’s second Python program # 27-Feb index = 0 while index <= 100: print 'index is ',index, random.random() index += sleep(0.01) print ('I am done!') Hit <F5>

9 Physics Model: Model the following: Box starts with a 1000 particles
Every step, there is a 0.5% chance each particle will escape Print the number of particles inside and outside the box.

10 STEP 1 from visual import * # for random and sleep # There are 1000 particles, all but one of them are in # the box. Ntotal = 1000 Nright = 1 Nleft = Ntotal - Nright # index = 0 # # Setup the big loop while index < 2000 : sleep(0.01) index += 1

11 # See if anyone moves from the left box to the outside # There is a 0
# See if anyone moves from the left box to the outside # There is a 0.5% chance for every particle index2 = while index2 <= Nleft: if random.random() < : Nleft -= Nright += index2 += 1 # # give status print (Nleft,' ', Nright) # # emergency stop if Nleft < 0: break print ('done')

12 Add some stuff in to get ready for the three assignments.
Add two lines to the very top from visual import * # for sleep and random from visual.graph import * # for the graphing features from math import * # for the log function

13 Assignment #1 Instead of just empty space, make a second box to the right side. There is now a 0.5% chance that each particle in the right side will make back to the left side. Print out Nright, Nleft and Entropy each step.

14 Hints Remember S = k ln(W) In this case W = Ntotal!/(Nright!)(Nleft!)
In Python N! = math.factorial(N) In Python ln(X) = log(X) When printing the entropy, you’ll want to plot S/Smax so it scales from 0 to 1

15 Assignment #2 Graph it. Go to: /cartert/PHY2115/ Click on the code-snipets link

16 Extra Credit Make a plot to see if the entropy ever goes down by just a little HINT: Keep track of the previous maximum value of the entropy at each step. Plot the current value of entropy subtracted from the previous maximum. According to the 2nd law, that number should never be negative.


Download ppt "1) Google “Vpython” 2) Go to first hit"

Similar presentations


Ads by Google