Matter & Interactions I Fall 2016

Similar documents
VPython Class 2: Functions, Fields, and the dreaded ˆr

Computer Model of Spring-Mass System. Q1: Can a computer model of a mass-spring system, based on the finite-time form of the momentum principle

Computer Model of Spring-Mass System, Part 3 of Springs Lab

The Monte Carlo Method

1 Newton s 2nd and 3rd Laws

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

Project 3: Pendulum. Physics 2300 Spring 2018 Lab partner

Modeling the Motion of a Projectile in Air

Overview In chapter 16 you learned how to calculate the Electric field from continuous distributions of charge; you follow four basic steps.

Project 2: Using linear systems for numerical solution of boundary value problems

5.6 Logarithmic and Exponential Equations

2013 Purdue University 1

Introduction to SVD and Applications

5-Sep-15 PHYS101-2 GRAPHING

Math 148. Polynomial Graphs

Introduction to Hartree-Fock calculations in Spartan

Q520: Answers to the Homework on Hopfield Networks. 1. For each of the following, answer true or false with an explanation:

Foundations for Functions

Introduction. Pre-Lab Questions: Physics 1CL PERIODIC MOTION - PART II Spring 2009

SECOORA Data Portal Exercises

MATH 408N PRACTICE MIDTERM 1

If a function has an inverse then we can determine the input if we know the output. For example if the function

Lab 6: Linear Algebra

MAT 343 Laboratory 6 The SVD decomposition and Image Compression

LAB 2 - ONE DIMENSIONAL MOTION

CS5314 Randomized Algorithms. Lecture 15: Balls, Bins, Random Graphs (Hashing)

After linear functions, the next simplest functions are polynomials. Examples are

, where c is the speed of light in a vacuum. This new factor, the Lorentz factor, 2 v

MAC Learning Objectives. Logarithmic Functions. Module 8 Logarithmic Functions

Lesson 4 Linear Functions and Applications

Chapter 4. Vector Space Examples. 4.1 Diffusion Welding and Heat States

Example. If 4 tickets are drawn with replacement from ,

Introduction. Pre-Lab Questions: Physics 1CL PERIODIC MOTION - PART II Fall 2009

Logarithms Dr. Laura J. Pyzdrowski

Lecture 3: Special Matrices

Mathematical Background. e x2. log k. a+b a + b. Carlos Moreno uwaterloo.ca EIT e π i 1 = 0.

Probability Distributions

CMSC Discrete Mathematics FINAL EXAM Tuesday, December 5, 2017, 10:30-12:30

Essential Question How can you solve an absolute value inequality? Work with a partner. Consider the absolute value inequality x

Learning Packet. Lesson 5b Solving Quadratic Equations THIS BOX FOR INSTRUCTOR GRADING USE ONLY

Boyle s Law and Charles Law Activity

Calculating and displaying the magnetic field of a single moving charged particle

1.) Suppose the graph of f(x) looks like this (each tick mark denotes 1 unit). x y

MA131 - Analysis 1. Workbook 4 Sequences III

Introduction to Spectroscopy: Analysis of Copper Ore

, gives a coupled set of first order dt m differential equations.

CSCE 155N Fall Homework Assignment 2: Stress-Strain Curve. Assigned: September 11, 2012 Due: October 02, 2012

Mathematica Project 3

empirical expressions. The most commonly used expression is F

Graphical Analysis and Errors MBL

Vectors and Vector Arithmetic

Experiment 0 ~ Introduction to Statistics and Excel Tutorial. Introduction to Statistics, Error and Measurement

Integrals. D. DeTurck. January 1, University of Pennsylvania. D. DeTurck Math A: Integrals 1 / 61

Activity: Derive a matrix from input-output pairs

GUIDED NOTES 6.4 GRAPHS OF LOGARITHMIC FUNCTIONS

Molecular Modeling and Conformational Analysis with PC Spartan

Chem 1 Kinetics. Objectives. Concepts

Unit 6 Quadratic Relations of the Form y = ax 2 + bx + c

Differentiation 1. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Modeling Data with Functions

CS173 Lecture B, November 3, 2015

Department of Chemical Engineering University of California, Santa Barbara Spring Exercise 2. Due: Thursday, 4/19/09

An introduction to plotting data

LTM - LandScape Terrain Modeller

Physics with Matlab and Mathematica Exercise #1 28 Aug 2012

Lab 10: Ballistic Pendulum

Lesson 18: Recognizing Equations of Circles

A factor times a logarithm can be re-written as the argument of the logarithm raised to the power of that factor

Please bring the task to your first physics lesson and hand it to the teacher.

4.4 Graphs of Logarithmic Functions

PHYSICS LAB FREE FALL. Date: GRADE: PHYSICS DEPARTMENT JAMES MADISON UNIVERSITY

Motion II. Goals and Introduction

Introduction to Determining Power Law Relationships

Kinetics of Crystal Violet Bleaching

Chapter 2. Review of Mathematics. 2.1 Exponents

Math/Phys/Engr 428, Math 529/Phys 528 Numerical Methods - Summer Homework 3 Due: Tuesday, July 3, 2018

Guided Inquiry Worksheet 2: Interacting Einstein Solids & Entropy

Quick Overview: Complex Numbers

EEE161 Applied Electromagnetics Laboratory 1

Vector Spaces. 1 Theory. 2 Matlab. Rules and Operations

Study Resources For Algebra I. Unit 2A Graphs of Quadratic Functions

About the different types of variables, How to identify them when doing your practical work.

Investigating Limits in MATLAB

LAB 1: MATLAB - Introduction to Programming. Objective:

EAS 535 Laboratory Exercise Weather Station Setup and Verification

LECTURE NOTES: Discrete time Markov Chains (2/24/03; SG)

Making Piecewise Functions Continuous and Differentiable by Dave Slomer

Lab 2: Static Response, Cantilevered Beam

WISE Regression/Correlation Interactive Lab. Introduction to the WISE Correlation/Regression Applet

PHYS 275 Experiment 2 Of Dice and Distributions

Lesson 8: Why Stay with Whole Numbers?

CS 420/594: Complex Systems & Self-Organization Project 1: Edge of Chaos in 1D Cellular Automata Due: Sept. 20

Laboratory 11 Control Systems Laboratory ECE3557. State Feedback Controller for Position Control of a Flexible Joint

Exam III #1 Solutions

Measurements of a Table

Lesson 3: Advanced Factoring Strategies for Quadratic Expressions

CSC2515 Assignment #2

VECTORS. Given two vectors! and! we can express the law of vector addition geometrically. + = Fig. 1 Geometrical definition of vector addition

Chapter 6. Exploring Data: Relationships

Solving Linear Systems of ODEs with Matlab

Transcription:

33-151 Matter & Interactions I Fall 2016 Name (Printed) Instructor Signature for 9.P70 (a): Instructor Signature for 9.P70 (b): Instructor Signature for 9.P70 (c): Instructor Signature for 9.P71: Due Date: Tuesday of Week 14. Introduction Section Distribution of particles between two boxes In this exercise, we will numerically calculate the probability distributions of N particles distributed between two boxes. As we showed in class, the distribution is given by: ( ) N1 ( ) N2 N! V1 V2 P (N 1, N 2 ) = (1) N 1!N 2! V V with the condition that the total number of particles N 1 +N 2 = N is constant and V 1 +V 2 = V. We will want to be able to vary the two volumes, keeping the total volume fixed. We also showed that give a probability function, P (x), we can easlily compute the average of some quantity, y, as < y > = i P (x i ) y i, where the sum is over all possible values of x (and y). For example, < N 1 > = N N 1 =0 P (N 1 ) N 1. In order to simplify things, we will choose our total volume to be V = 1, and will start with a total of N = 10 particles. However, we may want to increase N to a larger value later, so be sure to allow this flexibility in your program. For the simulated experiment, you will have the computer throw N particles into the two subsystems with the appropriate probability. A random number between 0.0 and 1.0 can be generated by the random function as given above, no argument is needed. Programming Assignment We will be doing problems 9.P59 and 9.P60 from the textbook. 9.P59. In this problem, we will numerically calculate the probability distributions of N particles distributed between two boxes. These probabilities are given by equation 1 where we have the constraints that N = N 1 + N 2 V = V 1 + V 2. 1

As we write our program, we want to be able to easily change V 1 and V 2 subject to these constraints, but to start, choose that V 1 = 0.5 V. (a) Write a program which will draw a plot of the probability distribution as a function of N 1 for N 1 goes from 0 to N. Include a calculation if the average value of N 1 based on your probability distribution. Have your program print out the average value of N 1, the most probable value of N 1 and the probability of the average value. (b) Modify your program to plot the natural logarithm of the probability as a function of N 1. Verify that the maximum of this plot is where the maximum was from part (a). (c) Use your program to carry out your calculations and make plots for N = 50 particles and V 1 = 0.25V, 0.5V and 0.75V. Record the average and most probable values of N 1, for these cases. 9.P60. Write a program that randomly throws one hundred particles, one at a time, into two identical boxes. After the 100 particles have been thrown, record how many times we found N 1 = 0, 1, 2,, 100 in the first box. Make a plot of these agains the number N 1. Does the location and the width of the histogram distribution agree with what you expected from the theoretical probability distributions and the maximum entropy? There is a program shell at the end of this document to get you started, but you will need to still do quite a bit of work to get things going. We have broken this exercise into four related programs. You are welcome to combine them all into one larger program if you want, but there are four signatures associated with this Programing Hints You are likely to need the factorial, binomial coefficient and natural log functions in VPython. Recall that the factorial of zero is defined to be one, 0! = 1. The functions are given as: factorial(n) = N! = N (N 1) (N 2) 2 1 ( ) a a! combin(a, b) = = b b!(a b)! log(x) = ln(x) = log e (x) Note that in Equation 1, the ratio random() = random number from 0 to 1 N! N 1!N 2! = combin(n, N 1 ). We also note that because of internal precision of our computer, there is a maximum value for which we can compute the factorial. However, the upper limits for the binomial coefficients, combin(a, b) are larger as the algorithm does not fully evaluate the a! term in the expression. Thus, if you can write things in terms of combin(a, b), you will be able to got to larger numbers. So rather than writing N2 = N - N1 2

Prob = factorial(n)/(factorial(n1)*factorial(n2)) it is better to write the probability as Prob = combin(n,n1) which will not suffer from numerical problems. In the shell program below, you will see that your program starts with several import statements. We are already familar with the first two while load the visual modules and the graphing modules. from visual import * from visual.graph import * What is new are the following two that allow us to compute random numbers and factorials. from random import * from visual.factorial import * Also recall that to create a display, the general form is as follows. nameofplot=gdisplay(title=????,x=??,y=??,width=??, height=??,xmin=0,xmax=n,ymin=??,ymax=??,xtitle= N1, ytitle=???? ) You do not need to provide values for all of the question marks as VPython will choose reasonable defaults are taken. However, as a reminder 1. x and y give the locations of the upper left-hand corner of the display in pixels 2. width and height give the dimensions of the display in pixels. 3. xmax and xmin, etc. give the maximum and minimum values for the axes in the plots. For our problem, we want that the x-axis will run from 0 to N. You need to choose the other values based on what you are plotting. e.g. for a probability distribution, all the y values must be in the range of zero to one. To create a curve, we use the gcurve command. nameofcurve=gcurve(color=color.cyan We can also draw histogram bars using the gvbars command. nameofcurve=gvbars(color=color.magenta) A point can be added to both of these using the command 3

nameofcurve.plot(pos=(n,value)) which adds a point that has n as the value on the x axis and value as the number of the y axis. If you need to have multiple display windows opened at once, then use a series of gdisplay and gcurve commands. The following example will open three windows lined up on the screen: Create the first display window. mywin1 = gdisplay(title = "Probability", xtitle = "N1", ytitle = "Combinations", x=0,y=0,height=150,width=400) Set up a curve named "prob" in this window. prob=gcurve(display=mywin1) Create the second display window. mywin2 = gdisplay(title = "Probability", xtitle = "N1", ytitle = "log P", x=0,y=250,ymin=-10,height=150,width=400) Set up a curve named "problog" in the second window. problog=gcurve(display=mywin2) Create the third display window. mywin3 = gdisplay(title = "Experiment", xtitle = "N1", ytitle = "Number", x=0,y=500,height=150,width=400) Create acurve named "experiment" in the third window. experiment=gcurve(display=mywin3)} In order to make a histogram of the probabilities, it is easiest to first create a list of objects. Consider the list probdata[0:n] that will contain the probabilities for each value of N. i = 0 while (i<n) : 4

Evaluate the probability for the value N1=i p =??? Add this to the list of probabilities. probdata.append(p) We now use the histogram commands in VPython. The following will create a histogram on the last opened display. It will then take our probdata list which contains the results from our experiments and histogram them. "experiment" - using histograms Create a histogram with N+1 bins. my_hist = ghistogram(bins=range(n+1), color = color.red) Copy the contents of your list into the histogram. my_hist.plot(data=probdata) In the random-selection program, 9.P71, you will create a histogram which is used to record the number of times each outcome occurs. There are some commented-out notes at the end of your shell on this. The trick is to build a list for each possible value of N 1 as seen in volume V 1, and repeat the experiment many times. Each time you test how many are in V 1, and then increment the appropriate element in the list. After you have done many numerical experiments, plot the number of times each value of N 1 occurred. The following hints might be helpful when you do the randomized throwing of the particles. You need to understand what this is doing before trying to code it up... Set up an empty list to contain the results: N1=0 while (N1 <= N): probdata.append(0) Carry out the Nexpt numerical experiments, the index i represents a particular experiment. 5

i=0 while (i<nexpt): Throw N total particles: j = 0 N1 = 0 while(j<n): decide if the particle went into V1... if random()<(v1/v): N1+=1 get the next particle in this experiment j+=1 N1 is the number of times the particle went into the first volume in this experment. Add one to the appropriate element of our list. probdata[n1]+=1.0 Go to the next experiment. i+=1 Program Shell ******************************************************************************* Probability Computations Program Shell from visual import * from visual.graph import * from random import * from visual.factorial import * Set up the total number of samples and experiments N = 10 Number of particles to distribute Nexpt= 100 Number of experiments for last part. 6

The following is a list that allows us to store the probability for each of the N1=0 to N1=N possibilities. The list has N+1 entries, so if you increase N from 10, be sure to change the number of entries here. probdata=[] Set up the two volumes: V = 1.0 Let the total volume be one unit ratio = 0.50 Set up the ratio V1/V V1 = V*ratio V2 = V-V1 Setup the graphical displays. You are likely to need to modify some of this as you go through the various programs. scene1 = gdisplay(title="probability",width=400,height=200,xmin=0, xmax=n,ymin=0,xtitle="n",ytitle="probability") probplot=gvbars(color=color.blue) -------------------------------------------------- Initialization Complete, Start Actual Calculations -------------------------------------------------- Max = 0 Most probable value of N1 MaxValue = 0 Probability of most probable value of N1 Average = 0 Average value of N1 Use the Analytic formula to compute the probability for each value of N1, and then find the most probable and the average. N1=0 while (N1<=N): Compute your probability for our choice of N1 p=??? Add this probability to the list of probabilities 7

probdata.append(p) Do a check to see if the current value of p is the maximum value. (Max and MaxValue)... Update your running sum for the average value of N1 (Average)... Go to the next value of N1 N1+=1 We have finished the loop, print out the numerical results. print " Analytic Results:" print " Average Value of N =",Average print " Most Probable N =",Max,"; Probability=",MaxValue print " --------------------" Plot the probability distributions in a window, assuming that we have the filled probdata array from above. i=0 while (i<=n): probplot.plot(pos=(i,probdata[i])) i+=1 8