 All right, good afternoon, everybody. So today we will continue where we left off yesterday. We were working on fitting, learning how to do linear least squares fitting. And just to remind you what that is since it's new to everyone it seems. The idea is that we often try to model a data set using a particular model that may conform to some theory that we derive in order to understand our data. And one of the examples that we looked at and we'll consider again today is we take concentration data as a function of time and extract from that information about the order of a chemical reaction and determine its rate constant. So that's a simple example from chemical kinetics. There are many, many other. Fitting is something that's done all the time in various sciences. So the idea is we try to determine the parameters of a function that we think the data should conform to by doing this process called linear least squares fitting. And that process optimizes the coefficient such that the fit is as good as possible for a particular data set and a given function, fitting function, okay? And we've seen a little bit how that works. So today I want to do just a couple of more examples so you can get a better handle for the fit command in Mathematica. And then we'll talk about your homework. And then after that we'll start a discussion of statistics, okay? So the first thing that I want to do today is I'm going to generate an artificial data set. And it's basically a polynomial. I'm going to evaluate a polynomial function and add some noise to it. And then we'll fit it with a polynomial function, okay? So this will give you an example of doing something a little more complicated than just a straight line, all right? So the first thing I'll do is define the function. So I'm going to call it y of x underscore colon equals. And then I'm going to have a term 1 and then another minus 0.3 times x and then plus 0.04 times x squared. And then minus 4.5 times x cubed and then plus 0.4 times x to the fourth, okay? So this is a quartic polynomial. And now in order to make it a little noisy I'm going to add some random numbers. So I'm going to say plus 20 times random real, bracket, curly, minus 1 to 1, curly, bracket, okay? All right, so we take our quartic and then we mess it up a little bit by adding some random numbers, all right? So I'm going to go ahead and enter that. And now I'm going to tabulate. I'm going to make a list of points of this function and then we'll perform a fit. Okay, so I'm going to define my matrix, my data, and use the table command to fill this matrix, all right? So first thing I want to put in the table is x and then I'm going to put y of x. And now I'm going to evaluate this for x goes from 0 to 10, all right? And now I'm going to generate the least squares fit. Okay, so let's write down what is our fitting function. Well, I'm going to try to fit it to a quartic polynomial. So basically I'm going to fit it to a function that looks like y of x equals a0 plus a1 times x plus a2 times x squared plus a3 times x cubed plus a4 times x to the fourth, okay? So in the fit command I have to specify the terms in x that are defining my fitting function. So what should I put for this polynomial? Remember within curly brackets I need to write down the orders of the terms. Well the constant term I indicate by just putting in a 1 and then I have a term that's in x, so I put in x. And then I have a term that's in x squared, so I put in x squared and then x cubed x fourth. That's how I specify this fitting function in the fit command. Any questions on that? All right, so let's go ahead and do the fit. I'm going to assign the fit to a variable fit data so that I can refer to it later in a plot command. So let's say fit data equals the data is in the table my data, okay, and now I specify my fitting function. So I have 1 comma x comma x squared comma x cubed comma x to the fourth and then I specify my variable, all right? Now let's enter that. We enter that and we get the best set of parameters by doing the least squares fit. Okay? Now you can look at that closely and you can see that some of those parameters are not that close to the function around which I generated some noisy data, right? Some of them are quite different. So for example the first one was 1 plus or minus some noise and the best fit came out to be around 19, okay? So you might think, well that's not a very good fit. Well, you have to be careful when you say very good fit and like I said later in the course we'll look at some quantitative diagnostics to tell us about that. But for now we can plot the function next to the data and sort of eyeball it to see if it looks like a decent fit, okay? So to do that what we'll do is generate a plot of the actual data, so I'm going to call that data plot equals and the data is a bunch of points, it's a list of points so I use the list plot command and give the name of the matrix containing the data. All right, so if I enter that you see I get this curve. All right, now we're going to plot the actual fitted function and I'll call that fit plot equals. Now we use the plot command because the thing we're going to plot which is this function here is defined in terms of the continuous variable X, okay? So then I say plot fit data, that's that function and I'm going to use the same range as in the list plot so that's going to be X goes from 0 to 10, okay? And if I plot that you see I get a curve that looks something like our data but to see just how close it is we can plot both of those on the same plot using the show command. So show data plot and fit plot and now you see that in fact it looks like the fit is actually quite good. Any questions on that example? Yes, the reason that's a very good question so the reason for that is it's the random number generator, okay? So this is a good time to point out something here. So we, the data that we generated we used this function called random real. That function generates random numbers. The interval is here, okay? So it chooses random numbers between minus 1 and 1. It's a different number every time random real is called and in this case I multiplied it by 20 to give a little bit of noise to this curve, okay? Now, whenever you have a random number generator there's a, there's a quantity called a seed which starts the process of generating a chain of unique random numbers. That seed is based off the computer clock and so if you do your command at a slightly different time, even infinitesimally small time that's away from the time that I did mine you're going to get different numbers. And you can see that by, notice if I re-enter this command here and then re-enter this command here, I'm going to get different numbers because my data points are going to be different, okay? So I get a slightly different plot or a different fit there. Okay, so whenever we use this random number generation, all of us are going to get different numbers, okay? Any more questions? Okay, so then I'm going to do one more example. You get to do a couple of these in your homework so I want to do one more example just to make sure it's really clear. And like I say I won't ask you to do anything I didn't show you how to do, okay? And so for this example, we are going to revisit the kinetics data that we looked at last time, all right? And just to remind you, last time we had some data that consisted of time in seconds and concentration of some reactant in molar. We had some values. We read those values into Mathematica. We looked at plots of the log of the concentration versus time and the reciprocal of the concentration versus time. We found that the second one looked like a straight line. In other words, it conformed to the second order integrated rate law and we can write that as a line. So this analogy here says that if we plot one over the concentration of time t versus time, we get a straight line with slope equal to the rate constant and y intercept equal to 1 over the initial concentration. Okay, so what we're going to do now that we didn't do last time, we'll get those data back in and then we will fit them to a straight line and determine the rate constant, okay? Now, remember, you may recall last time it was kind of a pain to type all those numbers in. So this time we're not going to do that. This time we're going to read them in from a file, which is a lot easier than typing them in and a lot less prone to mistakes, okay? So I want to show you a couple of ways to do that. Well, first of all, let me show you where the data are. The data on the course website, on the links page and there's this file called data for lesson three, okay? So if we go there and click on this, we see the numbers which you may or may not recognize from last time. Those are the numbers that we typed in, time in seconds in the first column and then the concentration in the second column, okay? So there's two ways that we can read these data directly into Mathematica, okay? So one of them is we can actually save the file on our disk and then I'll show you how to read that file in once it's on your disk, okay? So we say file, save page as and then go into the save here directory and then go ahead and save it as lesson three dot dat, okay? So now that's sitting in the save here directory on my computer and now to bring that file into Mathematica what I do is I just use a command called, so I'm going to go ahead and define a variable that's going to have that, those data in it. So I'm going to say my data equals and the command to read the file is called import and then I put double quotes and the one thing you have to keep in mind about import is that you have to say exactly where is the file, okay? So on Windows we specify the name of the drive which is the C drive in this case and then the name of the directory save here and then the name of the file lesson three dot dat quotes bracket and now if we enter that you see that we got a matrix in Mathematica notation and it's exactly the same one that we typed in by hand yesterday except it was a lot easier to do it this way. All right, now the second way to import data which is particularly convenient if it's on the web like this one is, is you go get the URL, all right? So what I can do is select this, control C, I'll call this web data. Use the import command again except now instead of putting in the name of the file I put in the URL so control V quotes bracket and voila, okay? So those are two ways to get data from files, text files, data files, all right? And in general that's a lot less painful than typing in long lists of numbers. All right, now let's recapitulate what we did last time. So next thing I'm going to do is copy my data into something I'm going to call new data, all right? And then I'm going to take the reciprocal of the second column. Does anybody remember how to do that? New data to refer to the second column I say give me all rows in the second column equals one over my data, all rows in the second column. And now to see what it looks like I can say list plot new data and as we saw yesterday plotting one over concentration versus time gave us a line that looks pretty straight. Okay, so now we'll do the, take it to the next level by performing a least squares fit to determine the rate constant. Okay, so I'm going to define fit data equals fit new data. I have to put in the form of the function. So which terms do I need for a simple straight line? I need the intercept which is proportional to X to the zero power or one. And I need the linear part, X and then X. All right, enter and now somebody can tell me what's the rate constant. Anybody want to tell us what the rate constant is? It's this number here. All right, so is that it? That's it as far as mathematics is concerned but as chemists we're concerned about the units, aren't we? So what are the units? If you want you can try to figure them out with Mathematica but here's a case where you can use your knowledge of what these quantities actually are in order to do it very easily by hand. Okay, so this equation tells us, okay, so the units of the two sides of the equation have to be the same, correct? So this equation tells us that one over concentration is equal to rate constant times time. So rate constant has units of one over concentration times time or molar to the minus 1, seconds to the minus 1, right? Okay, so now we've determined the rate constant. All right, so just to finish this up let's see how good is the fit. I think we can already tell by eyeballing the data that it's going to be a good fit but let's see just how good it is. And so what we want to do is generate a plot of this function so fit plot equals plot fit data for X goes from zero to 6,200, okay? And there it is. And now if we go up here and just call this data plot and reenter it then we can come down here and you show data plot and fit plot. And now we'll have them both on the same graph and you see that indeed the second order integrated rate law fits these data extremely well according to eyeballing the fit. Okay, so as far as I'm concerned that completes our lesson on least squares fitting. Like I say we'll come back to it later in the quarter and we'll look at two additional aspects of fitting. One is quantitatively assessing the quality of the fit and the second is we'll consider nonlinear functions of the parameters, okay? Now this is a good time to pause and for me to tell you how to do your homework. So let me go to the website, homework, okay. So as with the last homework assignment this looks really long but it's mostly because I like to do a lot of explanations about what it is that you're actually doing even though the most important thing in this course is that you just do the mathematical part. All right, so the first problem I want you to calculate this quantity, all right? So what's this quantity? It's called the Rydberg constant. It's a fundamental physical constant. Does anybody remember who Rydberg was? No? Well, he was the guy who wrote down the formula that described the positions of the lines in the hydrogen atom line spectrum and you're so unimpressed. Well, I remind you, I remind you that there were integers in that formula and the fact that there were only discrete lines as opposed to rainbows for the light coming out of excited hydrogen atoms was an indication that there was some sort of quantum mechanical effect there. And then Niels Bohr came along with his simple model of the hydrogen atom and showed that it would predict the positions of those lines as dictated by Rydberg's formula quantitatively and I was considered a smashing success for the quantum theory and Bohr got the Nobel Prize for his work. Okay, well anyway, a fundamental physical constant that appeared in Rydberg's formula is this thing called R sub H. Okay, Bohr's theory actually predicted that that value could be computed from values of other fundamental constants and this is Bohr's expression. Okay, so that's the background. Now, what do I want you to do? I want you to calculate a numerical value for that with units two different ways. Okay, and I give you all the values of the constants that go in here and remember this E here, this is not the base of natural log, this is the charge of the electron in coulombs. Okay, so the first, in part A, I want you to calculate that using symbolic units. Okay, so for example, capital C for coulomb, capital J for joules. Okay, and then you'll have some symbolic units in your answer. Then for part B, what I want you to do is recompute the same quantity except this time load in the physical constants package, list out all the names of the physical constants that are in there and find all of these things and use them to recalculate the Rydberg constant. Okay, so for example, this thing E0, it's what's called vacuum permittivity in Mathematica and then you know M sub E is the electron mass, there's the electron charge, there's speed of light and there's Planck constant. Okay, so you find those things and just plug them into that formula. Now you should get the same number in parts A and B but what you will also notice is that you'll notice that the units will appear at first glance not to be consistent. We talked about this a little bit already and so even though I don't ask you to do it here I'd like you to convince yourself that those units are in fact the same and this is just a reminder to you that when you're working with units sometimes you have to put a little thought into what you get out to make sure it's what you think it is. Okay, does anybody know what the units of the Rydberg constant are? It should come out to be inverse meters. It won't look like it in your calculations but that's what it should be. Okay, so that's number one. You can probably do that problem in less time than it took me to explain it to you. Okay, so the next problem is just to do some units conversions. Okay, so load in the units package and convert one acre which is you know area of land usually is what it's used for to square meters and then this funny quantity furlong is a length and fortnight is a time so that's like a speed. You can convert that to miles per hour to see what a furlong per fortnight is. Convert a gallon to milliliters and minus 20 degrees Celsius to Fahrenheit. Okay, excuse me. Okay, next I want you to enter this table of numbers into a matrix in Mathematica so it's going to have four columns, three rows and then write it out in table form and matrix form and then do a couple of manipulations. So I want you to take the third column, multiply it by two in part C and then take the second or the reciprocal of the second row in part D. So you can practice manipulating matrixes and then the last two problems are fitting problems. So there's a file homework 2.dat which is right below the PDF file for the homework on the homework page. Okay, so I want you to import those data so it can be either you can use the URL or you can download the file and read it in and then I want you to fit it to this form. Okay, so that function has no constant term but it has two terms in X, one is X to the minus one and the other is X to the minus two. Okay, and then I want you to plot the original data which is in homework 2.dat along with the fitting function that you get out from fit on the same plot like we did several times in the examples. Okay, the last problem is a chemistry problem. Does anybody remember from general chemistry, kinetics? You talked about the Arrhenius law. What's the Arrhenius law all about? Yeah, well that's one thing you can do. In fact, that's what this problem's all about. Okay, so let me just remind you. So Arrhenius supposed that a nice way to think about the kinetics, the rate constant in particular for chemical reactions is in terms of an energy profile. Okay, so a simplified energy profile might look like this. This is a measure of the progress of the reaction and this is a measure of energy and over here we have reactants and over here we have products and he's supposed to think about the reaction as needing to go over a barrier in order to get to the products, a barrier in energy and the height of that barrier is called the activation energy. So the idea being that reactions occur when molecules collide but a reaction can only occur if when the molecules collide there's enough energy to overcome this energy barrier. Okay, and then Arrhenius's formula, well it's right here, he said that the rate constant is equal to a pre-factor which has something to do with the collision rate times e to the minus activation energy over RT. Okay, so as that activation energy over that barrier increases the rate constant becomes exponentially smaller, okay? So it's quite sensitive to that number and also this explains the temperature dependence of the rate constant fairly accurately for many reactions, okay? Now, what I want you to do in this problem is you have a bunch of data down here, it goes on to the second page so don't forget the next third page so don't forget that. So I want you to, I'm sorry, type the data in to a matrix, all right? So you're going to have rate constant versus temperature and then I want you to use a fit to determine the pre-factor A and the activation energy. Now, this form here is not directly amenable to a linearly squares fit. However, if you take the log of both sides then you see that log K is equal to log A minus EA over R times 1 over T. So it actually looks like this. I'll write it slightly differently here, okay? So if I call 1 over TX minus EA over RM log of AB and log of K, Y, you see I have the equation for a straight line which then I can fit to using the fit command in Mathematica. Okay, so how do you actually do that? Well, once you've got your table typed in, what I want you to do is you take the log of the second column, okay? So then you'll have log K as Y and then I want you to take the reciprocal of the first column because X is 1 over T and then when you plot log K versus 1 over T you should see that it looks like a pretty decent straight line. You can verify that before doing the fit, all right? And then when you fit it, your slope will be minus EA over R and your intercept will be log of A, all right? So then I want you to specify the values of those quantities. You can put them in a text box or a comment, okay? So that's it. Not too bad, huh? Any questions on the homework? Looks like fun, huh? All right, now the next subject is we're going to learn how to do some statistics. Has anybody in here had a statistics class ever? Oh, okay. Well, then you'll be familiar with this stuff. I'm not assuming that you had a statistics class, so. All right, so then somebody who's had statistics, can you give us any examples of what statistics is actually useful for? Why bother? It's used for hypothesis testing. Yes, exactly. And a lot of times that's done by fitting a model to data, like what we've learned how to do here, right? And, you know, if you think about it, the statistics are everywhere, all right? They say that tonight we have a 30% chance of rain. That's a statistical quantity, right? A probability of having rain. There's statistics involved in computing your grades, all right? How did you do relative to the mean? And maybe more importantly, well, nothing's more important than your grades, sorry, whenever we make measurements, if we want to be responsible scientists, we should provide some indication of the amount of uncertainty and the value that it is that we're reporting. So oftentimes when we report data, those data are the mean of several different independent measurements. And if we want to report an uncertainty, we might report something like the standard deviation or the standard error of the mean. So there are many statistical quantities that are very useful in helping us to understand what's the quality of data and the conclusions that rest upon them. Okay, so I'm going to show you a few things in Mathematica that help you to do some statistics. And then I'm also going to introduce you to what are called distributions. And I'll explain more about that as we get to it, okay? All right, so let's go ahead and brew ourselves up some data. So I'm going to make a list of numbers that I'm going to call data. Okay, so I have 1.05, 1.01, 0.97, 1.14, 0.92, 0.99, and 1.07. And I need another curly brace here. Okay, so this you might imagine to be the values I get by making repeated measurements or independent measurements of some quantity in an experiment, okay? And you can already tell by looking at the data that they seem to be, the values seem to be grouped around 1 and that there's a little bit of a spread in the data, maybe a couple to few percent. Okay, so let's be more precise. So suppose I wanted to report the average value in some measure of the uncertainty. Well, we'll see how to do that in just a second, okay? All right, so first of all, I might be interested in knowing what's the lowest value of all of those? Well, there's a simple command called min. If I put the name of my list in there, it will give me the smallest number in the list. Oops, did I not enter that? I didn't enter that, okay. All right, so min gives me the smallest number, 0.92. How about maximum, 1.14? Suppose I wanted the sum of all those numbers. I could say total. How about the average or the mean, okay? So with one simple little command, I get what I would normally have to do if I wanted to take the mean of that would be to add all those numbers up and divide by the number of entries. So here I get it with one simple command. What about the median, 1.01? What's the difference between mean and median? Anybody know? Yes, correct. The median is the middle value in the list. And the mean is the actual average computed as the sum of values divided by the number of entries. Okay, now I want to write down a formula to define a quantity that we'll calculate next. Okay, so what we calculated the mean, so what we suppose is that our data is just a bunch of values, a set of values which I'll call xi, x12345 up to the number of entries. Okay, so the mean which we denote here as x with some angular brackets, that's just the sum of all the values divided by the total number of data points so that we have n values, okay? Now the next thing we want to know is what's the spread in the values around the mean value, okay? So one way to quantify that is through the variance, okay? So the variance which we call sigma squared is equal to the sum over i of the difference between each point and the mean. Okay, and then we actually divide that by the number of points minus 1, okay? And then probably most of you have heard of the standard deviation. Standard deviation is defined as sigma which is the square root of sigma squared, okay? So you can see that this is a measure of how much on average the individual points are spread around the mean. It gives us a single number to give us if you like some measure of the uncertainty. And standard deviation is often used as a single number to tell you that. Okay, so if I want the variance of my data, I just say variance of data, okay? So here we see it's about 0.005. And the standard deviation, you can get with a single command like that. And we see that it's 0.07, okay? So that's a number we might report as the error bar in our measurement, if you like, or the uncertainty in our measurement. Okay, now I want to look at a larger data set. Okay? And so what I'm going to do is I'm going to grab a file from our website and it's called data for lesson 4. And as you can see from the bar on the right here, this is a long file. It's got a lot of points in it. So I'm not going to type them in. I'm going to read them. Okay, so let's see. I'm going to call this input data. Equals import quotes URL quotes. And I'm going to put a semicolon here so I don't have to see a very long list of numbers. Enter. All right. Now let's do a list plot of that just so you can see what it looks like. All right, so you see lots of points. I think there, yeah, there's a thousand of them. And I've just plotted the values as a function of the number of the point. Okay? All right. Now what I'm going to do is I'm going to make a list that contains only the values, okay, not the index, so that I can pipe that into things like mean and standard deviation and variance. All right, so I'm going to say data equals. How do I get the second column? Input data, bracket, bracket, all, comma two, semicolon. All right, enter. All right, now I'm going to calculate the mean of that. And I get a value 4.98. Does that seem reasonable given what we see on the plot there? We can kind of see that those data are sort of evenly spread around somewhere around five. Okay, so that makes sense. All right, and what about the standard deviation? If I had to ask you to guess it without doing the calculation, what would you say? So the mean is around here, and the standard deviation is sort of a measurement of the fuzz around the mean. You think that big? Well, let's find out. It's about one. Although, well, it depends a lot, you know, what the underlying distribution of the data is, but in general you can think that, you know, the outermost points, if this conforms to, say, a normal distribution are going to be, you know, a few standard deviations, like two or three standard deviations away from the mean. Okay? All right, now, so we see that these data seem to have sort of a regular pattern of spread around the mean, don't they? So the next thing that I want to introduce you to is a way to plot the data in such a way that we can see how they are distributed. Okay? And so we're going to construct something called a histogram. Now, what a histogram is, is that I take my range of values and I divide them into little strips, you know, like that, and like that, and like that, and I just go across and count the number of points that are in each strip and write it down, or in the Mathematica's case, it keeps it in memory, and then I can plot it and see what's the shape of the data. So for example, this may be some scores on a quiz in a Chem 1 class, and I want to see what's the shape of those scores, so I can draw lines where the grades are going to be. Okay? All right, so let's see how to do the histogram then. Can you already tell by looking at the data what the histogram's going to look like? It looks to me like the points are denser near the mean and that they become less dense as we go out, and it looks more or less the same on both sides. So by eyeballing it, I can already see that it's going to probably look something like a bell curve, and I'll tell you a secret. It actually is because I generated it to be a bell curve more or less, so okay. So how do we make the histogram? Well, it's got this command histogram, all right, and if I do that, I get a plot, okay? So what's this plot? Well, if you just say histogram, Mathematica is going to decide for you how big each strip is going to be, okay, so it's decided to put one strip between 2 and 2.5, and then it counted up the number of values and it looks like there must have been, I don't know, a few, okay? And then you notice as we get closer and closer to the mean, the number of values on each side or on this side is growing, and then as we start to go past the mean, it goes on the other side, and so we have something that looks like a bell curve, okay? A little later, we'll learn something about the different types of distributions that one sees often in science, okay? Now, if you don't like the choices that Mathematica makes for you, you can change the way the histogram is displayed, okay? So one thing we can do is we can tell Mathematica how many strips to use, maybe we want to see if there's any little lumps in the data in the distribution, all right? So if I want to specify the number of strips or bins they're called, all I have to do is put in a number saying how many bins, all right? So this command will generate this histogram from the same data but using 40 bins, okay? So now we can see there's actually a little bit of fine structure in the data, right? When you look at it more closely like this, you can see that it looks a little bit less like a beautiful bell curve, and also there are some places where it's got some little bytes taken out of it, all right? Now, in this one I specified the number of bins. What if I would prefer to specify not the number of bins but the width of the bin, okay? So suppose I said, well, I want to generate a histogram that has bins of width 0.2, okay? So I can say histogram, data, and if I put my, oops, comma, if I put a number in curly brackets that will set the bin width. It turns out it's the same as this plot. You can make it finer, all right? Now, what if you only want to look at a particular part of a region of the values, okay? So suppose I want to zoom in and just look at values between say 4 and 6. So I want to look in the vicinity of the peak of this distribution. Well, in that case, what I do is instead of putting a single number in the curly brackets, I put the minimum, the maximum, and then I can put in the bin width. So for example, 0.1. And now I'm looking in detail at the vicinity of the peak at a pretty high resolution, 0.1. Now, this histogram here, just to remind you what it is, this is what I would call a raw histogram, okay? Which is simply going through the data, counting how many points are in each strip, and then just putting that count on the y-axis, okay? Now, there are other ways to construct histograms that are often more useful. So I want to introduce you to probability distributions and probability densities. So I'm going to suppose that my values are x's, okay? And then I'm going to define a quantity which I'll call p of x, and this function is, I'm defying it as a probability density function. Now, if I multiply a density times a volume, I get a number. All right? So if I take my increment, my bin width, and call it dx, then the interpretation of p of x times dx, which I'll call this a volume element, right now we're in one dimension, so it's just, you know, one variable, the interpretation of this is the probability that a value lies between x and x plus dx, okay? So within a bin, say, all right? And this is often the thing that you're most interested in, okay? So we can use a histogram command to generate either of the probability distribution or the probability density function. Both of them have their places, okay? So let's do that. So how would I create a probability from, say, a raw histogram if I was doing it by hand? Well, what I'd want to do is replace these raw counts by probabilities. So what I would do is I would take all of these values that are being plotted here and divide by the total number of points I have, and that would tell me what's the probability that a value landed in a particular bin, okay? And then if I divided that by the bin width, I would get the probability density. So that's the relationship between the raw histogram, the probability distribution, and the probability density function. All right. So if I want the probability, all I have to do is put an option into the histogram command that specifies that. So I say histogram, data, and I can put in a bin width, so I'm going to put in 0.2 so we can compare it to the plot above. And then quotes, probability, bracket. And I'm going to nuke this so we can compare the two. All right, so let's go ahead and enter this. Okay. Now notice what I told you is correct, okay? So the peak in the raw histogram, let's say it's about 50, all right? And I have 1,000 points. Oh wait, these are not at the same, sorry about that. I want to make my point here by comparing apples and apples. So put a 0.2 in there, okay. That's more like it. Okay, so you can see that the highest value here is about, I don't know, what, 85? I have 1,000 points. If I divide 85 by 1,000, that should give me the probability and you can see it is about 0.085, which is 85 divided by 1,000. Okay, so that proves the relationship. All right, suppose I want the probability density. So to get that from the probability function, it's basically all these values divided by the bin width, which is 0.2, so it's going to be about five times each of those. I get that by replacing probability with probability density, okay? So now you see, in fact, that this highest value, little more than 0.08, has become a little more than 0.4, so that's five times that value. All right, so now you know the relationship between a histogram, probability distribution, and probability density, and you know how to get those using Mathematica from a set of data. Now, this makes for a nice segue into the next subject, which is that I would like to introduce you to some famous probability distributions that pop up a lot in the sciences. Okay? And in particular, we're going to talk about the binomial distribution and the Gaussian or normal distribution, and those of you who've taken statistics, those names should ring a bell, or at least ring a bell curve. All right, now to do this, we have to start out, we're going to build up to the binomial distribution and learn a few more tricks along the way. Okay, so the first thing I want to introduce you to, on this path to the binomial distribution is permutations. All right? So I'm going to make a little list here, which I'm going to call list, equals, and then I'm going to say A, B, C. Okay? And now, I'm going to look at the permutations. So let's do it, and then we'll see what we get. Permutations of list. Now you can see what a permutation is. All right? What it is, is all the lists that I get by reorganizing the elements of the list. Okay? And if you want, you can go through and verify that in fact, those are all the unique ways that you can do that. Okay? How many did we get? We got six. Does that number, can we understand that number six? Okay, let's suppose that I have an empty list. So it's like little boxes where I put letters, and I have three boxes. So I take my A. How many choices do I have for where I put A? Three. Once I've placed A, how many choices do I have to put B? Two. And then once I've placed A and B, how many do I have to place C? One. The total number of permutations is the number of ways to place A times the number of ways to place B times the number of ways to place C. So it's three times two times one equals six. This thing, three times two times one, that has a name. It's called a factorial. Okay? And for a number N, we indicate the factorial with an exclamation point. And what that is, is that I take N, and then I multiply it by N minus one, N minus two, dot, dot, dot, and then times two and then times one. Okay? So three factorial is three times two times one, which is equal to six. And it turns out that the number of permutations that you can have with a list of N elements is N factorial. Okay? Now, how do we get factorial in Mathematica? Factorial. We put in three, we get six. There's one strange one, and that's the definition of zero factorial. Whoops. One is defined as one. Okay? All right. Now, let's make our list a little longer. So now I'm going to say list equals A times B times C, I mean, no, A, B, C, D, E. And let's get the permutations. Notice there's a lot. We only added two elements to the list, but we got a lot more permutations. That's because this factorial thing grows very, very quickly with N. So we had six permutations, for a list containing three elements, if we have five, then we have six times four times five, 20 times six, in other words, 120, went up quickly. We can verify that by doing two ways. We can say, give me the length of permutations of list, that's 120, or we could say we have five elements, so we should have five factorial permutations. So same number. All right. We're going to do one more thing today. Let's see if I can explain this one to you. Maybe I'll go over to the other board. All right. So what I want to do is I want to take, I'm going to start with a list of N elements. And what I want to calculate now is the number of ways that I can break this into two lists, one containing M elements and the other containing N minus M elements. Okay? And the number I want to calculate is the number of ways I can do this without caring about the order of the elements in each of these little lists. So without regard for order. I only want to know how many ways I can break up the list into these set fixed numbers. Okay? All right. So how many permutations are there of this piece? We start out with, so permutations of the M minus M and minus 1 times N minus 2 dot, dot, dot, N minus M plus 1 and then finally N minus M. And what I think you can see is that this is like the first part of N factorial but not quite because I'm missing everything after N minus M. So in fact, this happens to be N factorial divided by N minus M factorial. Sorry, this is not the permutations. I made a mistake. I should be careful. This is the number of ways to make the first group. Okay? All right. Now the number of ways to make the second group is that turns out to be N minus M factorial. Okay? All right. Now we're still not to this number, okay? Because if we were to actually take the product of these, we would be part way to the answer but we have to deal with this part. Okay? So the next thing we need to know is the number of permutations of each of these guys because what we want to do is take the products of these two and then divide by the number of permutations of each of these. Okay? So this number then is going to be the product of these two and then to get rid of the caring about the order, we take the number of permutations of the M group, so that's M factorial times the number of permutations of the N minus M group which is N minus M factorial. Okay? So the final answer is these guys just cancel N factorial over M factorial times N minus M factorial. Okay? And this has the shorthand notation N over M in parentheses and this is what's called a binomial coefficient and what's the significance of this quantity? Well, we'll see one example of the significance next time. I just want to show you how to calculate it first quickly before we go. It appears in many, many places in mathematics and in statistics so those of you who had statistics probably saw the binomial coefficient, right? All right, so let's just finish up today by actually calculating it, okay? So the command is as follows, it's called binomial and then you put the two numbers in. So this will be say N and M. All right? So let's suppose I had a group of four letters and I wanted to know how many ways can I break that group up into two groups, one containing three letters and one containing one letter. That's the binomial coefficient, gives me that number. All right, so if I do N equals 4 and M equals 3, I get that number and it's 4 and we can verify that. I'll just verify it for you in the last minute here. So I start with A, B, C and D. So one of the ways I can break those two up is, I guess I have it, oh, I have it here. So I can say A, B, C in one list and D in the other and then I could say A, B, D and put C in the other one and then I could do A, C, D and put B in the other one and then finally I can do B, C, D and A in the other and the key point here is that the order in these lists doesn't matter, I don't care, all right? Now, right now you're probably wondering what the heck does this have to do with statistics and why are you teaching us this stupid stuff and you would be right in thinking that. I'll just let you know that next time I'll show you that this binomial coefficient is a very, it's a piece of what's called the binomial distribution and the binomial distribution is a very interesting distribution so that's something that you can look forward to for next time. All right, so see you next time.