 All right, so today I'm going to start out by finishing up some examples of doing integrals that are relevant to chemistry. And I'm just going to go ahead and write on the board what we're going to do and then we'll crank them out. Okay, so I've mentioned to you previously that if you have a probability distribution of say a variable, continuous variable say X and you want to calculate the average of some function of X, the way you do that is you integrate the product of the probability distribution times the function over all of the range of X. Okay? And so what we're going to do today is we're going to take the Maxwell-Boltzmann distribution of speeds of molecules or atoms in an ideal gas so that's f of u where u is the speed, it's equal to 4 pi and then we have m, the molar mass over 2 pi rt, squeaky, 3 halves and then e to the minus m u squared over rt. And then what we're going to do with that is we're going to calculate the mean speed so that's going to be the integral of u times f of u, I'm sorry, there should be a u squared in here too, okay, du. Now what's the range of the speed for a molecule in a gas? We have to know that so we can do the integral over the correct range. What's the slowest a molecule can go? Zero and what's the fastest? Infinity in principle so we'll do that and we should get a known example either from GCAM you might have seen this or you will see it in physical chemistry which is that this should come out, it should have a closed form and it will be 8m rt divided by, well sorry, 8 rt divided by pi times m to the 1 half, okay? So this will be the average speed and then in addition I want to calculate the so-called root mean squared speed which you've probably also seen before and the definition of that is that it's the square root of the mean squared speed so calculate the mean squared speed to take the square root and so that's going to be the integral from 0 to infinity of u squared times f of u times du and this one you may also recognize that's going to be 3 rt divided by m to the 1 half, okay? All right so those are the first couple of things that we're going to do and then while I have the lights and I'll tell you what we'll do after that, okay? And so the next thing I want to do is I want to calculate the probability that the speed is between two values so let's say u1 and u2. Anybody know how I do that? Well what I want to do is I want to add up all the infinitesimal probabilities ranging from u1 to u2. Okay so what I do there is I'll call this p that u1 is less than or equal to u which is less than or equal to u2 so to get that probability what I should do is take the integral from u1 to u2 of f of u du, okay? So that's just like I have my Maxwell-Boltzmann distribution say u1 here and u2 here. What we're calculating is just the area under the curve here, all right? So that's another thing we can do. And then what we'll do is we'll consider a different system but a similar sort of problem so what we're going to actually do is for the hydrogen atom we're going to take an orbital in the hydrogen atom and we're going to look at the 1s orbital and we're going to calculate the probability that the electron is closer to the nucleus than the Bohr radius so it's within a zero of the nucleus. And what that's going to be is first of all we need to know as in this example we need to know what's the relevant probability distribution and that turns out to be because we're in spherical coordinates it's going to be r squared and then times the wave function, radial part of the wave function squared which I'll call r10 of r squared, okay? And then we need to integrate that between r equals zero and r equals the Bohr radius, okay? So these are some examples where we'll use Mathematica to calculate probabilities and then average properties from probability distributions, okay? And you will definitely see this in physical chemistry and those of you who are in physical chemistry right now are probably very close to seeing calculations of this sort. Started the hydrogen atom yet? Nope, not yet, okay, maybe next week. Anyway, we'll see how that works here but mostly for us this is just practice using Mathematica to do integrals. Okay, so for the first three things that I listed there we need to have the Maxwell-Boltzmann distribution typed in, all right? So I'll just type it in now, f of u underscore colon equals 4 times pi times m divided by quantity 2 times pi times r times t, parentheses, parentheses, power parentheses 3 halves and then times u squared and then times the exponential factor so that's going to be e carat parentheses minus u squared divided by, sorry it should be mu squared so we need a parentheses m star u squared and then parentheses 2 times r times t, okay? Then close that parentheses and that one. All right, so let's go ahead and we can enter that and now we'll do the mean speed, okay? So we could say u average equals, all right? And what we want to do is integrate u times f of u and we want to integrate from u goes from 0 to infinity. All right, so let's let that rip and we get a nice conditional expression. So what is that telling us? We should put in some assumptions, all right? So what can we assume about this guy? I'm sorry, I can't hear you. Yeah, so let's put in assuming and then put some brackets around here and then we'll put in some curly brackets here for our assumptions and a comma and now we can list, I don't know what this, I put the comma in the wrong place. So comma i, there we go. Okay, so we know that m is greater than 0, r is greater than 0 and t is greater than 0. So we can try that and see if that'll give us a nice, tidy expression and you see that we get a nice, tidy expression that we could use later in subsequent calculations if we want and it doesn't look exactly like what I wrote there but if you bring this 2 inside it becomes a 4 so that gives us a 8, rt over pi m all to the square root. Now that's one you could probably crank out by hand if you wanted to but I suspect most of you would prefer to do it like this. Okay, so let's go ahead now and calculate urms so we'll just mouse that in since we're going to use the same assumptions and now what do we need to do? Well, we need to change two things. First is we want to put u squared in the integral and then the second is we want to take the square root of the whole thing and we'll call it something else, urms. So let's try that and sure enough we get the equation that you find in your textbooks which is the square root of 3rt over m, okay? And now if you wanted you could put some numbers in there so for example we could say do in SI units we could say r equals 8.314 and let's say t equals 300k and then m let's put in 0.028 kilograms per mole which is n2 and we've seen this number before. Now we can ask for urms and evaluate that, okay? So we get about 517 meters per second for the rms speed of a nitrogen molecule at room temperature. Any questions? Okay, now let's go ahead and do the probability that a nitrogen, well let's have a look here just for fun. Let's go ahead and plot this guy here with the values that we have so I think we ought to be able to plot f of u and then we'll go from u goes from 0 to 1,000 meters per second. Okay, so there's our Maxwell-Boltzmann distribution. Now what if we want to calculate the fraction of molecules, n2 molecules that have speeds between say 300 and 500 meters per second? What should we do? Well that's going to be the area under the curve between lines drawn vertically at 300 and 500 and we can calculate it by doing an integral so I'll just go ahead and grab this guy here and put it in and now we don't want u times we just want the probability and now we'll put in specific values for the lower and upper limits. Now what do you think the answer should be? Look at the curve here. Is it 10 percent, 50 percent, 90 percent? All right, what we want is the area going basically from here over to here so this area in here. Probably about a third or so wouldn't you say? It's good to know the answer sometimes in advance and so when we calculate we see that in fact it's about 38 percent. All right, so you can imagine that in this room about 38 percent of the nitrogen molecules are going between 300 and 500 meters per second. All right, any questions on this calculation? Okay, well let's now go to the hydrogen atom and we'll calculate the probability that the electron in a 1s orbital in the hydrogen atom is within the Bohr radius of the nucleus. All right, so the first thing we need to do is type in the wave function for the 1s orbital, we've seen this before and I'm going to call it f of r underscore colon equals and so what this is is 2 times 1 over a 0, the Bohr radius and that's to the power 3 halves and then it's times an exponential decay which is e to the power parentheses minus r over a 0. Okay, so we can go ahead and enter that, all right and let's just, what do we want to do here? Well let's go ahead and calculate the probability and then we'll see whether or not it makes sense. Okay, so then what I want to do is, I'll say prob equals integrate and this one has a volume element that involves r squared. You'll see this when you learn about spherical polar coordinates in physical chemistry class. So what we actually have to do to turn the wave function into a probability is square it and then multiply by r squared. So we'll say r squared times f of r squared and then I said we want the probability that the electron is between 0, the nucleus, and the Bohr radius, a 0, all right? So we can go ahead and try that and what do we see? What do we see is that I should clear r because I assigned r to a value and that screws everything up. So I'm going to go ahead and say clear r here, re-enter and then try again and notice we got an exact answer for this. If we want a numerical value we could say n percent and it says there's about a 1 and 3 chance of finding the electron in the 1s orbital between 0 and the Bohr radius. Does that make sense? Well, let's go ahead and put in a value for the Bohr radius. It happens to be 0.0529 nanometers and then we'll plot r squared times f of r quantity squared and we'll do that from r goes from 0 to 3 times the Bohr radius, all right? So let that rip. So the probability we were asking for was r goes from 0 to about 0.0529 so out here somewhere which is this area over here. Does that look like it's about a third of the area under the curve? Maybe it's easier if you go out a little bit further like to 5. Does this look like about a third of the area? Yeah, okay. So that's sensible. All right, so the electron spending about a third of its time in that region there and notice as we previously had noticed that the peak, the most probable place of finding the electron is actually at the Bohr radius. That's the significance of the Bohr radius, all right? So that does it for integration. Are there any questions on using integration in Mathematica? All right, well you'll get to test and see how to use it by doing the homework which is what I want to talk about right now. So let's go ahead and have a look at our homework for the week. Okay, so there's three problems in the homework this week and the first one you're going to use different plotting techniques to have a look at the 4FZ squared orbital, hydrogen like orbital, okay? Which in Cartesian coordinates has this form where R in the exponent is given in the Cartesian coordinates like that. So this will be very similar to examples we did in class. You define this function as function of x, y, and z and that one and then you're going to use contour plot 3D to plot the orbital and you're going to plot two contours, one corresponding to positive amplitude or amplitude equals 0.2. That'll give you the positive lobe and then another minus 0.2. And you may have to play around with the ranges so that you see the entire surface. And what I'd also like you to do in part A here is you can choose your two favorite colors to plot each of the two contours in different colors, all right? So we can tell which one is which. All right, and then in parts B and C, what I want you to do is look at slices through that orbital, all right? So the particular slices that I want you to look at are the slice through the YZ plane, okay? So that corresponds to x equals 0. And you can go to the notes to see how you do that. I want you to take it from a four-dimensional function to a three-dimensional function by eliminating the appropriate variable. And then in part B, make a contour plot of that projection. I give you the ranges to use. Go ahead and use 20 contours so you can see the orbital in detail and use plot range arrow all to make sure you get the whole thing. And then in part C, what I want you to do is actually plot a projection, the same projection of R squared times the function squared and plot that as a density plot. So this will give you a function that's proportional to the probability of finding the electron in that orbital in the YZ plane, okay? All right, so that should be straightforward if you follow the examples that we did last week in class. Now, the next thing I want you to do is do some differentiation, okay? Now, what you'll learn in Chem 131C, you'll be learning about a branch of physical chemistry called statistical mechanics. And what you will learn there is that there's a very important function which is called the partition function from which, if you know it, you can derive all of the macroscopic properties of a system, okay? And here in this problem, I'm calling that function Q which is a function of temperature, all right? So here's a couple of examples of things that you can calculate if you know the partition function. So one of them is the thermodynamic quantity called the internal energy which I use the symbol U for here. And that's Boltzmann's constant times T squared divided by the partition function and then times the derivative of the partition function with respect to temperature, all right? So you'll derive this formula when you take Chem 131C. And then another thing you'll learn in thermodynamics is once you know how the internal energy depends on the temperature, you can calculate a quantity called the heat capacity which is how much heat something absorbs, a substance absorbs when you increase the temperature. And the relation is that it's just simply the temperature derivative of the internal energy, okay? All right, so forgetting about all the statistical mechanics part, what I want you to do is actually evaluate these two things for a function that I'm going to show you on the next page. So basically it's just a differentiation exercise. And then I'll have you plot the results as a function of temperature, all right? So the particular system that you're going to study here is the so-called two-level system which is a model system that's used a lot when you talk about NMR. So for example, NMR of spin one-half systems, maybe you'll learn this in organic chemistry. There's two spin states and they're separated by an energy which I'm calling epsilon here, all right? And so what I want you to do is define this function and you can go ahead and set epsilon equal one and Boltzmann constant equal to one because the important part here is the temperature dependence. And then use the formulas on the previous page to define the internal energy as a function of temperature and then I want you to plot it over the range shown there and then plot the heat capacity versus temperature for the same range, okay? So this problem is to find a function, take its derivative and multiply by some numbers, then take the derivative again and make separate plots of those two things, okay? And maybe you can ponder the results and see if they make sense. But in any case, it's a derivative and plotting problem. And be aware that you may have to be careful with how you treat the derivative in the plots and there are examples in the notes showing you how to deal with some of the problems that arise when you do that. Okay, last problem is, so we've been talking about kinetic theory and so for example on the board there, we have some results from kinetic theory, namely we have the Maxwell Boltzmann distribution which tells us what's the probability of finding a gas molecule in an ideal gas with a speed u. And then we have the average and RMS speed that we can derive once we know the probability distribution. Now there's another important probability distribution that comes from kinetic theory and that's called the Maxwell distribution which is different from Maxwell Boltzmann. And what the Maxwell distribution is is the probability of finding a velocity component within a certain range and that velocity component might be the velocity in the x direction, the y direction, or the z direction. And velocity components range from minus infinity to infinity. It's not the speed, it's not the square root of the velocity squared. Okay, now it turns out that for an ideal gas that distribution is a Gaussian, it's shown here. This is the Maxwell distribution for the x component of the velocity of a gas molecule. And I think you can see over here it's got e to the minus something times vx squared which is Gaussian. So this is one of the places where our friend the Gaussian distribution shows up in an important context. All right, so what I want you to do here is basically derive the ideal gas law from kinetic theory. Okay, so kinetic theory tells us that the pressure is equal to the number of moles of gas times the molar mass times the mean square of one of the components of the velocity and then divided by the volume. Okay, so this is what you call a microscopic formula. Telling you how you, well, it relates a macroscopic quantity of the pressure to microscopic behavior. In other words, the average of the velocity components. All right, so this is defined in the same way as we defined averages over there on the board. So the average of vx squared, you take the corresponding probability distribution, f of vx, so that's that, and you put in vx squared in here and you integrate over the whole range which is minus infinity to infinity. So what I want you to do for this problem is define this and then plug this into here and evaluate that. And if you did it right, you should get the ideal gas law and hopefully you'll find that somehow satisfying. What it is is it's a proof that the kinetic theory is consistent with the macroscopic ideal gas law. Okay, so that's part A. And then for part B, I just want you to show using an integration that this guy is normalized, meaning if I integrate it over its full range, I should get one. Okay, so this is a problem where you get to practice using integration on some chemistry related examples. Any questions on the homework? And if you're like freaked out by all the physical chemistry stuff in here, just worry about the formulas and put them into Mathematica. And then later on in physical chemistry, you'll be like, oh, I remember that. Okay, all right, so we're onto a new subject now and our next subject is equation solving. Okay, so let me motivate that with a couple of examples. What we're going to see is that the technique of equation solving, so we can solve one equation or multiple equations simultaneously, we're going to see that this is very, very useful for doing calculations for complex equilibria, which is stuff you normally don't touch in general chemistry and you get a little taste of in Chem 151. And then also some gnarly kinetics examples where you have much more complicated things than what you saw in general chemistry where you can treat several rate equations at the same time and get the concentrations as a function of time for many species. Okay, so this is a very powerful thing that Mathematica is very, very useful for. So I'm going to start with a very, very simple example, excuse me, to show you how it works. So suppose I have an equation x plus 1 equals 0. What's the solution to that equation? What value of x makes that true? X equals negative 1, right? So you just do very, very simple algebra that you learn in, I don't know, fifth grade or something and you have the solution for x. Okay, so how can we do that problem using Mathematica? Well, the first thing we do is we turn it into an expression that basically asks the question, is that true? And the way you do that in Mathematica is you make a double equals, okay? And then the next thing you do is you say solve that. So solve, bracket. And then in general, there may be more than one thing that looks like a variable, so you want to actually say which variable do you want to solve for? Okay, so in this case that would be x. And then you enter it and you get the answer in a somewhat strange looking form. Okay? So this looks kind of like a replacement rule sort of object, all right? So what it is is it's a list of lists. In this case, the list inside contains one element, but in general we may have more than one solution in which case they'll all be listed. And we'll see soon enough how we could actually pull out the value if we wanted it, all right? We'll worry about that in a second, all right? But this is the basic form of using the solve command and seeing what the format of the results is, all right? So let's try another familiar example or a familiar example. So what I'm going to do is I'm going to now solve the quadratic equation and get out the quadratic formula. So I can say solve. And I'm going to say I have an expression A times x squared. Plus B times x plus C, all right? So that's a general quadratic equation and solve that or set that equal to zero and then solve for x. Now, what should I get out? I should get out negative B plus or minus square root of B squared minus 4ac over 2a, the thing that you've probably memorized a million times in your life already by now, okay? So that hopefully should look familiar. Now, let's use this as a way to actually get out, to get access to those formulas, okay? Now, let me go ahead and mouse this in because I want to show you how this works in comparison to this format here. So what I'm going to do is I'm going to define an output here, roots equals, all right? Now, if I just enter that, I get the same thing so that doesn't help me. But if I want to actually extract out the formulas from the list, notice we have a list of lists, right? So there's two elements in the list, two things inside. So if I want to get the interior brackets off of there, what I can do is say x slash dot, okay? So what that's going to do is it's going to unpack the guys in the solutions. And now notice I have those two formulas, okay? Now, what if I wanted just one of them? Well, now I can use the usual way of addressing a list. If I want the first one, I would say that and notice I have a formula that I can use now. So if I wanted, I could set it equal to something like root one, okay? And now I could use root one in a calculation and similarly, I could pull out the second root. Call it root two, say, all right? So there's the, yes, notice plus sign, minus sign. Okay, so that's pretty cool. What if I want to put in some actual numbers? Well, I could say now that I've got roots here, I could say give me roots for particular values of A. So let's say A arrow one, B arrow three, and C arrow one, all right? If you enter that, you get some numbers. And in this case, they're exact. So if you wanted numerical values, you could say N percent. And then you get some numerical values. And notice, if I use those replacement rules, I still have my formulas intact. So if I want to reuse them for another set of coefficients, I can do it, all right? Now, so far, if you're not impressed, I don't blame you. But you can quickly get pretty sophisticated. How many people have ever solved a cubic equation or seen the results? How was that? Yeah, it was hard, wasn't it? Well, I'll show you an easier way to do it. So let's solve a general cubic equation, A times X cubed and then plus B times X squared plus C times X plus D equals, equals zero, and solve for X. Enter. Now notice, I can't even fit it on the screen. In fact, I'm going to shrink it down just for a second here. So you can see how impressive that is. Do those formulas look familiar? Now, you probably did a particular case. All right, so the thing I wanted to point out to you, though, on this one is that we have three roots. It's a cubic equation, so we should have three roots. One here, one here, and one here. And notice that the first one looks like it's real, whereas the second two could be complex. They have I's in them. See the I and the I. All right? So when you're solving equations, you oftentimes have to make a choice at the end to choose the root that makes most sense for your particular problem. And we'll see some examples of this later on. Okay, so there you have it. But that's kind of nice, right? You can crank out exact formulas for the cubic equation very simply using the solve command. All right, so I'm going to go back to the big screen here. And I'll just finish up, since we're almost done for today. We'll evaluate for a particular set of numbers. So one way I could do that is just say percent. That means the last result. And then use replacement rules to put in some values. So A arrow 1, B arrow 2, C arrow 3. Whoops, my B doesn't have an arrow here. And D arrow 4. All right? So I get a big mess here. But I could convert if I want to numbers and percent. Okay, so there you have it. Now you could see you have the first root is real and the second two are complex. Okay, so let me just give you a preview of what we're going to do next time. So what we did here was just solve single polynomial equations. So next time we'll see it works perfectly well a lot of the time for non-polynomial equations. We'll see what you can do when the solve command won't work because sometimes it doesn't work. There's no closed form solution. And then we'll see how you can solve multiple equations simultaneously and then we'll start doing examples relevant to chemical equilibria. All right, so some fun to look forward to. See you tomorrow.