 Okay, may I have your attention, please? Time to get started. So one thing that you might be aware of is that on Thursday, we'll have an exam here in class. And so let me tell you a little bit about it. That, you can expect that it will be a bit shorter than a typical homework assignment, but more or less the same kind of thing. You'll have some problems. You'll solve them in Mathematica. You'll upload your notebook to a Dropbox. And you'll have all the time in the class period to work on it. And then it will be finished. Now, I want to just plant a couple of things in your mind right now so that you'll be ready. So you can use anything you want except someone else's work. Okay? So when you come in here, you can load up the class notes, have all your previous notebooks ready if you think they might be useful. Anything you want that's yours you can use or anything that's out there on the World Wide Web is available to you. All right? So that's one thing. Another thing is that be especially careful about saving your work frequently to more than one place because once in a while these computers crash in the middle of exams and people lose their work. And it's really a shame because by now you should be used to making multiple copies of your work and saving it frequently. And another thing is there will be a deadline to the Dropbox after which you will not be able to upload your file. And from time to time there's a one minute or so discrepancy between the clock you see on your screen and the one that's actually at EEE that the deadline is based on. So you should definitely upload a provisional version of your notebook at some point well before the deadline. And then of course as you know you can keep uploading new versions if you need to as the deadline gets closer. But it's absolutely important that you take 30 seconds out of working on your exam to put up at least you know an initial version, a tentative version of your notebook. Because if you don't get it in before the deadline then you get a zero of course, all right? The other thing is what should you study if anything? Well in principle you don't need to study because I think as you've noticed the best way to actually solve problems using a tool like Mathematica is to start with an example if you have one. And I've told you many times and I'll repeat it now. I'm not going to ask you to do something that you haven't already seen how to do. Now obviously the problems won't be identical to ones you've seen before but in terms of what you will be asked to do you should already know how to do it and there's no need to memorize any commands or syntax. The one thing that you might do to prepare for the exam is just to look over the notes, remind yourself of what we've done and be familiar with where to go to find something if you need an example. Another thing that you might do is look over your previous homeworks and if you didn't get perfect scores make sure you understand what you did wrong so that if you have to do something similar on the exam you'll be able to do it. All right so those are my comments on the exam nothing to worry about and so do you have any questions about it? Any questions or concerns? Yeah, it will go essentially through yeah today, okay? So through differential equations, possibly. I can't put everything on there, right? It's got to be something you can do in an hour and 15 minutes. Okay, any other questions? Okay, well let me go ahead and start off today by telling you about this week's homework assignment. All right, so it has two problems and in the first problem I want you to calculate the pH of a dilute solution of the sugar glucose, all right? Glucose has hydroxyl groups in it that are very weakly acidic, all right? And the effective K a of glucose is 10 to the minus 12. So you can see it's pretty small and that makes glucose a very weak acid and you have a somewhat dilute solution of a very weak acid and so in order to treat this problem properly you should include the water dissociation equilibrium. So you have a coupled equilibrium between the ionization of glucose and water. You've seen an example of that problem and I want you to more or less repeat that but for this particular problem. Okay, so it should be pretty straightforward. The second problem is one where I want you to use ND solve to solve a system of differential equations and the particular case that you're going to consider is a very famous problem of nonlinear differential equations and dynamical systems. It's called the Hannon-Heil's problem and the problem dates from the 60s when Hannon and Heil's were working together at Princeton and they wanted to come up with a simplified model for describing the motion of a star in a galaxy. So it's an interesting problem and they just to keep it simple and tractable they confine the star to rotate in a plane around the center, okay? And the simplified equations that they came up with, well, these are just the classical equations of motion. So this is the time derivative of the x coordinate is equal to the x component of the velocity so that's basically Newton's second law. Same thing for the y and then the equations that tell you about the time evolution of the velocity components are given in terms of partial derivatives of the potential energy with respect to x in this case and y in this case. And the potential energy for this problem which is a function of x and y, the coordinates in the plane are given, is given here, all right? So what do I want you to do? Well, first of all, you can type this guy in and in part A you can plot it using a contour plot so you can kind of see what the potential energy landscape of the system looks like and I give you the ranges and tell you to use 20 contours and label your axes, all right? Then in part B, actually parts B and C I want you to consider two cases. Now why is this problem fascinating? This problem is fascinating because for certain values of the parameters of the system, so for example, the initial conditions, let's say, just to keep it simple, the star goes around in sort of regular periodic orbits and you're going to see that in part B. And then for other parameters, actually for most parameters, the star goes around the center of the galaxy in a very what we call chaotic way, okay? So this is an example of a nonlinear system that exhibits this both regular periodic motion and chaotic motion. And the interesting thing about the latter is that if you change the initial conditions just a little bit, you get a completely different trajectory. So this is very fascinating to people who are interested in these nonlinear dynamics problems. Okay, but for you, you can either, you can choose not to be fascinated and instead just, you know, do the problem. And so what you're going to do is you're going to use ND solve for those equations up there, all right? And you'll supplement those with the initial conditions given here. And then you're going to solve that over the range of time going from zero to a thousand. And then once you get your interpolating functions, I want you to plot the pair X and Y as a function of time using parametric plot, which we saw how to do last time, all right? And if you did that right, you should get something that looks kind of like a spirograph that's sort of a regular motion of this guy in the XY plane. And then in the second or part C, I want you to do exactly the same thing, but just change the initial conditions slightly. So what you see here is that the only difference between them is that there's a slight change in the initial velocity in the X direction. And you should notice a quite different behavior when you make the parametric plot, okay? Now, this problem is pretty straightforward, but you have to be careful how you type in your differential equations, okay? So I tried to make it very explicit. So if you type something in that looks like that, but you know, using Mathematica syntax rules, then you should be okay, okay? And this guy you can type in more or less as it's written too, all right? So the main place where you might get problems is in the way you type these in. All right, so that's the homework. If you don't get tied up on the second part here, then it should be a very short assignment. Any questions about that? All right, so everything you need to know to do this assignment, you already know, but I would still like to do some more examples from differential equations. And so what we're going to do today and we'll probably finish tomorrow is we'll solve some problems in chemical kinetics, all right? So the first one we're going to solve is one we already know how to solve from general chemistry. So we'll use that as a way to get warmed up and get to thinking about chemical kinetics. And then we'll start solving more and more difficult problems that are hard to do by hand without certain assumptions. Okay, so what we're going to do is we're going to consider first a simple reaction, A goes to B, all right? And I want to now write down the differential equations that express how the rate of the reaction depends on the concentrations of the reactant and product, okay? And I'm going to suppose that this is a first order reaction, all right? So if I wanted to write down the rate in terms of the concentration of species A, what should I write? The rate of change of A with respect to T. We could use concentrations or pressures. It's first order, so it's proportional to the concentration of A. And then what else should I put in there? A rate constant, first order rate constant. And what about the sign? Should be minus because A is a reactant whose concentration should be decreasing if the reaction is going to the right. Now suppose I want to write the rate in terms of the change in B. Well, what's the rules for writing down the rate expressions for products in terms of rate expressions for reactants? Remember from general chemistry if I say minus DADT is the rate with respect to A, then that means plus DBDT is the same rate. B is being produced at the same rate as A is being consumed when you have this stoichiometry. Okay, so I can say that's equal to plus K times A. Okay, so those are two simple first order differential equations which are, you know, trivial to solve by hand. But we'll go ahead and do it in Mathematica just to see how to set it up and like I say, to get warmed up for more challenging problems later. Now we're going to include some initial conditions and we'll say that concentration of A at time zero is equal to some number which we'll call CA0 and same thing for B. All right, so let's go ahead and do that and then we'll play around with it a little bit and then we'll probably have time to do one more, slightly more complicated example and then we'll save the good ones for tomorrow. All right, we'll get rid of that. Okay, so first thing I'll do is define our equations as a list. All right, so the first equation we can say, I'll go ahead and say that the concentration of A is going to be C, little C capital A and I'll use the prime for the derivative of T equals equals minus K times CA bracket T, all right, and then CB prime of T equals equals plus K times CA time of T. All right, and then we'll go ahead and put in the arbitrary initial conditions that will or boundary conditions if you like that will fill in later with replacement rules for a particular problem. So we'll say CA at time zero equals equals a number to be prescribed later and then finally CB time zero equals CB zero, no comma, all right. Okay, now let's go ahead and solve this system of equations and store the solutions in this list. Solutions equals D solve equations and then we put in what we're solving for so that's going to be CA of T and CB of T and then T is our independent variable, all right, so we can go ahead and enter that and we get our solutions. Okay, so a couple of things to point out here. So first of all, this should look familiar. This is the integrated rate law that you learned in general chemistry and normally in the general chemistry class you stop there and you don't worry about the product. So in this case we've got as a bonus the product so we can actually look at them both simultaneously, all right. So here you can see that the concentration of A decays exponentially, all right. So let's go ahead and make a nice plot of these solutions and we'll compare a different situation to this plot a little later so I want to have it available and I'm going to include a plot legend so I'm going to start by loading the plot legend's package, all right. Forget the backward single quote and now I'm going to plot, well let's see, let's make a list to make things, well let's just go ahead and type it all in. So we're going to plot CA of T and now I'm going to put in my parameters so slash dot we'll put in the initial concentration of A is going to be 1, let's say 1 atmosphere and then the initial concentration of B or pressure of B we'll say is 0 so we don't start out with any product. And then I'm going to put in the rate constant for the first order decomposition of SO2Cl2 and so that's going to be K arrow 2.2 times 10 to the minus 5, all right, comma and then we can just mouse this in, put it back and change the CA of T to CB of T, all right and then we need another curly. Okay, now the rate constant's around 10 to the minus 5 so I should go to around time equals 10 to the 5 or so in order to see the decay nicely so I'm going to say T goes to from 0 to 200,000, all right. And then I'm going to say the axis label arrow so we'll call it x axis T in seconds and then the y axis will be pressure in atmospheres and then the plot legend. So the reactant for this example is SO2Cl2, we could put in nice subscripts if we want but I'm not going to do it. And then we'll suppose that the product here is either SO2 or CL2 because according to the stoichiometry they behave the same, all right. And then I'll say legend size arrow 0.5, legend shadow which I don't like, I'm going to get rid of it so arrow none and I don't like the border a whole lot either so I'm going to get rid of that, legend border arrow none and then finally I'm going to put the legend in a nice place so legend position arrow 0.2 minus 0.2, all right, yes. Your first time in K for this? Yeah, oh, okay, I'm sorry I probably didn't mention this previously, this is like a little different way of doing the same thing, this is like saying 2.2 times 10 to the minus 5, you can put in the 10, it's certainly, you know, it's easier to debug if you have the times 10 in there. But that should work, all right, let's have a look and see if it works, oh, nope, maybe did I not put that in in the right way, well let's go ahead and just get this right and then maybe worry about it later. Okay, hmm, okay, something's wrong, oh, right, thank you. Right, so I didn't unpack this, right, all right, so slash dot, solutions and then the replacement rule, thank you, okay, always solution, we'll get it right one of these days, thank you, right, I should have known it turned blue, okay, that looks good. And now just for fun, let's see if this other thing would have worked, gives the same thing, so that's a little shortcut. Okay, so lots of work, but we actually made a nice plot to sort that you might actually find in your general chemistry textbook in the kinetics chapter, here we can see that reactant SO2Cl2 starts out at one atmosphere and then over this time period it decays to a very small pressure and then we see the product starts at zero and it's basically a mirror image of the exponential decay and we end up approaching one and certainly as time went to infinity the pressure of the reactant would go to zero and the product would go to one because this reaction as written is essentially going completely to the right. Okay, now once we have this in here of course we can play around with parameters, so you can ask how do things change if I change the initial conditions a little bit, so you can start out with half and half, wait a minute, ah, because I didn't change this one, okay, so you see you get a different behavior here. Well, the curves look to have the same shape, but different in the details. Okay, so that's, you know, simple first order reaction and now what I want to do is make it just a wee bit more complicated, all right, so I'm going to go over here to the board, all right, so to make it a little more complicated let's consider the case where we have an equilibrium, okay, and now we're going to say the rate constant for the forward reaction is K sub 1 and the rate constant for the reverse reaction is K minus 1. Now, the question is then how should I modify my rate equations? Well, this equation tells me that the concentration of A, the rate of change of the concentration of A goes away minus sign in proportion to the amount of A that I have, all right, and that's for the forward reaction so I should put a K1 here. Now, how else can A be produced? Well, if we have the reverse reaction going, that produces A, correct, correct, all right, at what rate does it produce A? Plus, well, the rate of the reaction in that direction is K minus 1 and that would be proportional to the concentration of B, okay? How about B? Well, the forward reaction produces B, K1 times A is the rate, and then the reverse reaction takes away B so we should have a minus K to minus 1 times B. See how it works? Okay, so just by putting in the equilibrium we have slightly more complicated equations, it's still not difficult to solve those but let's go ahead and just do it with Mathematica and then we'll see the equilibrium actually shows up in our calculations, all right? So what we're going to do is we'll just take all of the stuff that we already did and we'll just modify it, okay? So here, let me call this, actually I'm not going to call the reverse rate constant minus 1 because that's going to look kind of funny and I call it K2, okay? So we'll put a K1 here and then minus K2 times CB of T, okay? And then here we have K1 and then minus, should be minus K2 times CB of T and I made a mistake here, this should be a plus, sorry, because we're producing A by the reverse reaction. All right, otherwise we're good and now we can go ahead and generate the solutions and you see it's a bit more complicated but no problem for Mathematica. So now let's go ahead and make a plot and for this one I'm just going to go ahead and make a generic reaction. I'll start out with A equal to 1, B equal to 0, K1 is going to be 2 times 10 to the minus 2 and then K2 will be also, no, 1 times 10 to the minus 2. Okay, now let's go ahead and just mouse that in and put it here and I'm going to call this, well, we'll get rid of the Y label because it's going to be either A or B and then the first species will be A and the second species will be B. Okay, that should do it. Oops, what happened here? Mm-hmm, plot's still bad though. They're not supposed to be straight lines according to these equations here, are they? Ah, my time is really, really off here because these rate constants are small, right? So let's go ahead and say 200. Oh, okay, and it looks like my legend's in a bad place so let's go ahead and put this out at 1.1, there we go. Okay, so what's interesting about this example? Well, notice how it's different from the previous one. So notice that the concentration of A doesn't go to 0, it levels off. Concentration of B doesn't go to 1, it levels off. What do we call it when it levels off? That's the equilibrium, all right? And you see the equilibrium sets in after a little more than say 100 seconds here, which kind of makes sense because the rate constants are on the order of 10 to the minus 2, okay? And what else? What's the equilibrium constant for this reaction? Is it greater than 1 or less than 1? Well, it should be the equilibrium concentration of B divided by the equilibrium concentration of A. So it looks like it's about 0.6 over about 0.4, so it's about 1.5, okay? Now, again, once you have it in, you can play around. You can change the parameters a little bit. So let's go ahead and change the first rate constant. Let's slow it down. Well, let's do this in a different plot so we can actually see, compare the two, all right? So I'm going to put in, I'll decrease, oh, you know what? This is weird. We should have had a 2.0 here, okay? It didn't change it much, but, all right, so let's go ahead and make K1 0.5 times 10 to the minus 2. Kind of screwed that up, all right? 0.5. Now notice, see the difference? Takes longer to get to equilibrium. That's one thing. What about the equilibrium constant? Is it the same? Doesn't look like it. The equilibrium concentration of A, let's go ahead and go to longer time so we can actually see the equilibrium a little better, so let's go to, let's say 300, all right? So it takes maybe around 300 seconds this time. Let's check again, 400. Around 300 seconds or a little less to get to equilibrium. And now you can see that the equilibrium concentration of A is greater than B. So the equilibrium constant is different. Does that make sense? You remember that for a simple reaction like this, that the equilibrium constant can be written as the ratio of rate constants, remember that? It's called detailed balance, all right? So we can see that here in this example. All right, so it looks like we can do one more or at least we can talk about it. Okay, so back to the board. Excuse me. All right, so now we're going to do a slightly more complicated example and what we're going to have is two reactants and they're going to be in equilibrium with an intermediate which I'm going to call I. And then in the second step the intermediate will react with B to produce the product which we'll call C. Okay? You remember what an intermediate is? Something that's produced in one step and consumed in another. It doesn't show up in the overall chemical equation which here would be A plus 2B goes to C, all right? Okay, so now let's see if we can write down the rate equations for this guy. If I call this K1, the rate constant for the reaction in the forward direction, K2 reverse and K3 for the second step. All right, so help me out here. What I need are three rate equations. Four, actually, if I want to solve for all the concentrations. So I need that one. I need that one. I need the intermediate and I need the product. Okay, so what should we write down here? Yes? Yes, that forms A so we can put that in. K2 times the concentration of I, okay? But we also lose A by the forward reaction and the forward reaction has molecularity of 2. Remember molecularity? We're assuming that these are elementary steps, right, in a mechanism so that we can write down the rate equations according to the stoichiometry. All right, so what's the rate at which A is removed by the forward reaction? K1, make sense? All right, all right, what about B? Well, B is removed in the same way as A, minus K1 times A times B, okay? It's also removed in the second step, okay? Anything else? That's it for B, right? How about I? Yes. Oh, you're right, yes, indeed. Sorry, I forgot about that. Yeah, he just pointed out that as I goes backwards in the first step, we produce B so we have to include that too, which I left out, okay? So that's plus K2 times I, okay? Thank you. And now for I, we produce I by the first forward step and we lose it by the reverse and we also lose it by the second step, okay? And finally, for C, we have only one source of C and that's the second step, okay? Now, just a couple of statements about this, we'll actually solve the system tomorrow. But first of all, you can see that we obviously have a more complicated set of equations that are all coupled, right? Because each of these rates depends on the other species who each have their own rate equations so you have to solve them together. And, you know, you look at this and you might think, wow, to solve that by hand looks like quite a chore. And it is quite a chore because if I recall correctly, you can't solve that set by hand. So what you would normally do, and you'll learn about this in Chem 131C probably, is you make some sort of approximation that can help you simplify these equations. And in cases like this, that approximation would be called the steady state approximation which assumes that the amount of intermediate that you produce is small and essentially constant. And in that case, then you could set this guy equal to zero and then you get some relationships that can help you to express the concentration of I in terms of the concentrations of reactants and products. And then you have, you start going in the right direction toward being able to simplify these equations and solve them by hand. So what we'll do next time is we'll actually solve this exactly using Mathematica and then we'll have a look at how this steady state approximation works and see when it works and when it doesn't. Okay, so that's it for today. We'll see you tomorrow.