 Okay, we'll go ahead and get started now. Last time, we finished up with a little introduction to the solve command, so the solve command as we've seen allows us to solve equations. And today we're going to solve one equation again, one at a time. We'll do a few examples and I'll show you a couple of ways of getting around problems when you encounter equations that can't be solved in a closed form. And then we'll briefly talk about solving systems of equations and then we'll do several chemistry-related examples from chemical equilibrium, which is where you often have coupled polynomial equations that are easy to handle in Mathematica as we shall see. All right, so I want to begin by revisiting what we finished off with last time just to remind you of a couple of things. And so what we're going to do is we'll start with the general cubic equation, so solve. And then I'm going to put in A times x cubed plus B times x squared plus C times x and then plus D equals equal 0 and solve that for x. All right, so we saw last time that that gives us a general solution that takes up a lot of real estate on our screen. And what I also showed you then last time is that if you want you can have that evaluated for particular values of the parameters, A, B, C and D, by saying something like, give me the last result and use replacement rules to specify the constants A, say it goes to 1, B to 2, C to 3 and D to 4. So this will take those formulas that resulted from the solve command and then plug those numbers in. Okay, so we get nice exact forms. If we want numerical approximation we could say n percent. Oops, percent. Okay, and so there we have nice numerical values for our three roots. One of them is real and two of them are complex for this set of coefficients. Now, suppose we wanted to get straight to the answer without having to do these additional steps. Well, one thing we could do is we could combine this, that back down here, and then we could add the replacement rules to the end. So here to the end of the equation, all right, so we could say put that right here and if you let that rip you get the straight solution. Now, what if you wanted the numerical approximation straight away? Well, there's various ways you can do that. If you make any one of these numbers non-exact, not an integer, you'll get numerical answers. Okay, we've seen that before, so maybe that would be useful in the present case. There's another way to do it, so let me go ahead and put this, well, let's grab this guy here and put it back and then I'm going to make this back to an integer, so if we do that we get the exact numbers. There's a numerical version of the solve command, okay? And if you put in end solve, that's the numerical version, that will take you straight to the numerical answers. All right, now the numerical version, as we'll see in a minute, is useful for getting solutions, numerical solutions, when an exact solution doesn't exist, okay? So let's try one of those cases where the exact solution doesn't exist. So let's try this Quintic polynomial. It's going to be x to the fifth minus 2 times x cubed and then plus x and plus 5. We'll set that equal to 0, equal equal 0 and try to solve that for x and notice we get something out that doesn't look very useful. This is a sign that we were unable to get an exact solution. So when that happens, do not despair if you need, if numerical values will suffice and in this case they have to suffice, you could go ahead and put in end solve and then you see that you get out five roots, one of which is real and four are complex, okay? So the end solve command can be very nice when you don't have exact solutions. All right, so far what we've done is we've seen how to use the solve command for polynomial equations. It can be used for non-polynomial equations also. So we'll do a couple of examples here. So we can say solve and this time we'll put in the square root of a polynomial. So this will be 1 plus x plus x squared and we'll set that equal to 2 and solve for x and you see we get out two solutions. If you want numerical values you can say n percent, all right? Now, one thing that's useful to do is to see what is it exactly that we're doing here when we solve? What do these roots mean? What's their interpretation? Say a graphical interpretation. Well, the interpretation would be, so I basically have, if you like, two functions here. I have y equals square root of 1 plus x plus x squared and then I have y equals 2, so just a horizontal line and what the solve command is doing is telling me where those two curves cross, so where they're simultaneously true, okay? So let's have a look at that. This is kind of a useful thing if you're hunting around for roots, we'll see in a minute in cases especially where it's not so obvious what they should be. It's always nice to be able to do a graph to convince you that you have the right answer. So what I'm going to do now is I'm going to plot. We'll plot square root of 1 plus x squared and then I'm going to plot 2 and I'm going to use a curly bracket because this is a list of things that we're plotting and then I'm going to plot them over a range of x that spans those two roots. So we'll say we'll go from x equals minus 3 to x equals 2, all right? And the other thing I'm going to do here is I'm going to turn on the mouse so that when I run it over the graph, it will tell me where I am in terms of the coordinates of the graph, so that's kind of a useful thing to be able to check up close. So there's this command called dynamic and then we're going to put in their mouse position and then that has an argument graphics, okay? So you'll see what this does in just a second. Now if we enter this, we see the two curves, okay? So here's the square root of 1 plus x plus x squared and then here's 2, all right? And our roots should be where those two cross. That's what we get when we solve the equation. Now notice when I run my mouse over the graph, it tells me where I am in the graph. So I can go over here and see when I'm at this crossing over here, x is equal to about minus 2.3. So that corresponds to the first root, that crossing there and when I go over to this side, if I can get close, there you see x is about 1.3 and so that corresponds to the second root on the right hand side, okay? So this is kind of a useful thing to do and also it helps you to appreciate what you're actually doing when you solve these equations. All right, let's do another non-pollinomial equation. So this one's going to be solve x to the power 1 fourth equals equals 2 times x, all right? So you see we get two roots to that equation. One is the trivial solution where both sides of the equation equals 0 and then the other one is this 1 over 2 times the cube root of 2, okay? You could get numbers by doing n percent. All right, now let's try another non-pollinomial equation that doesn't look too challenging but it turns out it doesn't have an exact solution. So this is going to be e to the x equals x squared and we solve for x, all right? So notice when we do that we get the brown messages which is usually not a good sign and we get solutions but they're written in terms of this thing called product log so we can find out what that is by doing the question mark and it basically says that product log is what we asked the thing to do so that's not very helpful. So what about if we try n solve? We'll just put an n in front and we get some numbers, okay? So notice we got a real root and a complex root and but we also got this message and the message, you know, might make you be a little bit concerned. So here's the case where we definitely would like to make a plot and check. Suppose we're interested in this real root, we can check to see if in fact that is correct, all right? So we can plot e to the x and x squared, all right? And we should put these in curly braces and then we can go over a range of x that covers our root so let's say minus 1 to 0. Okay, so here you have it and you see where the curves cross it looks like it's right around minus 0.7 so in fact this root is trustworthy. Now, there's another command that can generally succeed when you have problematic cases so here in fact we saw that solve gave us something that didn't look very useful and solve produced a number but it has this sort of worrisome warning. There's another command that will definitely find roots but it does them one at a time and it needs an initial guess. Okay, and that command is called find root, okay? So it'll find one at a time. So the way that works is you say find root and then we're going to put in this same equation here, okay? And then what we do is in addition to specifying what we want to solve for we put in our guess, okay? So we've seen the plot here so we can say well I can see it's around minus 0.7 and then if we put that in that's a pretty good guess then we'll get a more precise answer and you see that we get the one that n solve gave us. Okay? So find root is in general you can consider it to be very, very good at finding the root without any superfluous information. That can be handy if you're looking for them one at a time. Okay, so let's see another example where find root might be useful. Okay, so this one is going, we'll try to solve this equation, another non-pollinomial equation which is going to be log of x equals x cubed, all right? Minus 2, all right? So let's try that one. So we try that one and we get this funny product log thing again. So what do we do? Well let's make a plot and then we'll sort of see approximately where the roots are and then we can use to find root to find them one at a time. So let's say plot curly log of x, x cubed minus 2 and I'm going to plot this between, what am I going to plot it between 0 and 2? So x goes from 0 to 2, all right? And if I do that I see that there ought to be two roots. One is over here at about a little more than 0.1 and then the other one's over here at x is about 1.3. So I can mouse this in here, this equation and use find root. So the first one, I'll say x is around 0.1, all right? So that gives me actually 0.135674 and then the second one I find, let's put in 1.3 this time and I get 1.31498, okay? So there you see, you have a very robust way of finding the roots when you have a decent guess. How decent does it have to be? Well, let's check. So suppose I put in here 0.5, which is not that close. I get the same answer. What if I put in 0.7? Now you see it finds the other root because it's closer, all right? So you do, if you have closely spaced roots, you may find the wrong one if you don't know something about your functions, which you can do by making graphs, okay? So this is a few examples on using solve, end solve and find root for a single equation. What happens if you have more than one equation? Well, no problem. You can use solve and end solve to find solutions. So let's do an example. So we're going to say solve and make a list. Y equals equals X plus 2. And Y equals equals X squared minus X squared plus 10. Okay, so here we have a line and we want to find out where it crosses an inverted parabola, all right? And then we're solving for X and Y. Okay, so notice we get now a list of two lists, okay? And the first list gives us the X and Y values corresponding to the first solution and the second one to the second solution. If you want numerical values, there's various ways of doing it. One way is to just use end solve, which I'll do here. All right, so there's your two solutions, each consisting of coordinates X and Y. Now, let's see what this means graphically, all right? So let's plot X plus 2 and minus X squared plus 10. So I need a curly bracket and we'll do this over values of X that span our two solutions. So let's say X goes from minus 4 to 4, all right? So there's the two curves, here's Y equals X plus 2 and here's the inverted parabola. And so what our solutions are are the X and Y values of this point and the X and Y values of this point, okay? So you can see in fact that the first solution is this one over here and then the second root is this one here, okay? So looking at the graphs helps you to appreciate what you're actually doing when you ask to solve those equations, okay? I'll do one more example and then we'll move into some chemistry examples that will be hopefully a little more interesting. So another thing you can do is you can generate solutions that contain non-numerical parameters. So, you know, for example, just variables to be determined. So here's a simple example. Say solve A times X plus B times Y equals equals C and then we'll have D times X plus B or E times Y equals equals F, curly and then we solve for X and Y and instead of getting out a numerical answer we get out solutions that contain the parameters A, B, C, D, E, F, okay? And that one's a pretty easy one that you could do easily by hand but it's just to illustrate that you can actually do this generally without having numerical values, okay? Now, can any of you give me an example of a class of problems that you encounter in chemistry that results in polynomial equations? I'll give you a hint. It starts with an E, equilibria, all right? So let's do an example to remind ourselves how that works, okay? So I'm going to go over to the chalkboard and then we'll do an equilibrium calculation. Actually, that's what we're going to do for the rest of the time today, all right? So the first example we are going to consider is we're going to have this reaction. So methane gas plus steam in equilibrium with carbon monoxide plus hydrogen, okay? And this is called the steam reforming reaction and it's one way that you might be able to take a fossil fuel like methane and turn it into hydrogen and then the hydrogen you could use to burn clean in a fuel cell. So this is potentially an important reaction. One of the main problems is it requires a lot of high temperature to be effective. And the reason is if you look at the equilibrium constant which would be, how do I write the equilibrium constant Kp for this reaction? The law of mass action. The pressure of carbon monoxide times the pressure of hydrogen cubed divided by the pressure of methane times the pressure of steam, okay? And so that thing equals 1.8 times 10 to the minus 7 and that's at 600 Kelvin, all right? So it's pretty small. All right, so what I want to do now is we'll solve a particular problem corresponding to some given initial pressures of methane, steam and carbon monoxide. Now, when we want to set up an equilibrium calculation what's one of the procedures that we've learned in general chemistry that helps us to write down the law of mass action in terms of some unknown concentration or pressure? We have a table that we make. Ice table, right, all right, so what is an ice table? Well, an ice table is we put in our various reactants and products and then we write down what's the initial values of our concentrations or pressures? We express the change in terms of an unknown and then we write down the equilibrium values and then we plug them into the law of mass action and we solve for the single unknown, all right? So the case we're going to consider here is we start with 1.4 atmospheres of methane, 2.3 atmospheres of steam, 1.6 atmospheres of CO and no hydrogen. And what we're going to want to know is what's the pressures of all the gases at equilibrium, okay? Now, the change we can express in terms of an unknown which I'll call X and since methane is going away, I'll put a minus sign here if the reaction goes forward. By the stoichiometry, H2O is the same and then CO is going to be plus X and then what should I put for hydrogen plus 3X because of the stoichiometry, okay? So then at equilibrium, I have 1.4 minus X, 2.3 minus X, 1.6 plus X and plus 3X, all right? And now I plug those into the law of mass action and so I have now we have to start with 1.6 plus X times 3X cubed divided by 1.4 minus X times 2.3 minus X and that's going to be equal to 1.8 times 10 to the minus 7. Now, what kind of equation is this? Well, the whole thing. It's a polynomial in X, correct? What order is it? It's fourth because we have a term that's got X cubed times X, all right? Now, normally we can't solve this by hand, exactly, right? You're laterals if you could, it would be pretty rough. So what would you normally do in general chemistry class if you wanted to do this problem? Well, you would see that you have a very small equilibrium constant, so you would imagine that the reaction's not going to go very far to the right. It's going to go to the right and produce a little bit of hydrogen. So you might say, well, that means then that the change X is going to be small. And you might say it's small compared to these initial pressures. So you would replace 1.6 plus X with 1.6, in other words, say X is negligible compared to 1.6 and you do the same here and here. You can't say X is zero here because then the whole thing is zero. And then you would have 3X quantity cubed equals that and you could solve that in your calculator. It turns out for this particular set of initial pressures that's going to work. We'll check it in just a minute. But suppose you had a situation where you couldn't make that assumption. Well, then it's nice to be able to have an equation solver because as you'll see in just a second, Mathematica will take care of this like that, all right? And then once we have it in, we can play around with the numbers and see under what situations the approximation might actually be worth using and what cases it's not. Okay, so let's go ahead and plug this in and then we'll play around with it a little bit, all right? So then what we need to do is I'm going to go ahead and say equation or let's make it sound chemical. Let's call it mass action equals curly and now I'm just going to plug that equation in, all right? So we have 1.6 plus x times 3 times x cubed divided by parentheses, parentheses, 1.4 minus x times 2.3 minus x, parentheses, parentheses, equals equals and then we put in the equilibrium constant, 1.8 times 10 to the minus 7, okay? All right, so there's my mass action, expression and now I can say solve, whoops, bracket, mass action, 4x and because I have numbers with decimal points, I'm going to get a numerical answer. Okay, so I do that and notice this is a fourth order polynomial so I do get four solutions and two of these turn out to be real, okay? So even though I have this nice tool that allows me to solve that equation, I still have to know some chemistry in order to pick out the answer, all right? So first of all we know that pressures are not complex quantities so we can rule these two out and now we have a choice, well how about this one? No, why? I can't have negative pressure of hydrogen, right? Okay, so that means the answer is the last one, okay? So then let's go ahead and see how we can pull the root out and calculate the equilibrium pressures of all of our species. All right, so for example I can say the pressure of methane is equal to 1.4 minus x and then I have to pull out the value of the root that I want from that list and the way I do that, we saw this last time as I say slash dot, oh sorry, let's make this, let's set this first equal to roots because I want to be able to just refer to it that way, all right, so I'm just going to re-enter that and then down here I say roots, the fourth element of the list of roots, okay? And what that's going to do, it's going to grab that fourth root and it's going to take off the x arrow and the curly brackets and just give me a number, okay? So then I get 1.398 or 763 atmospheres, okay? And you could convert that to the correct significant figures, all right? And then we won't do them all but let's say how about the pressure of H2, let me just put this back here, okay? Pressure of H2 is going to be 3 times x, okay? So we can do it like that, all right? So there's the pressure of H2 at equilibrium, all right? So this example I hope is useful because first of all it shows you how to set up an equilibrium problem, solve it and then how to actually pull out the roots in a way that you can use them, okay? Now let's put on our chemist hats again and think a little bit about this problem and ask whether or not we actually really needed to solve this quartic polynomial. So notice that the root that we decided was the right one is 0.002, is 0.002 negligible compared to 1.6, 1.4, and 2.3? Generally speaking I think the answer is yes. It may not be if you want to be really super, super precise, okay? But at least according to the standards that we have in GCAM that would be perfectly fine, okay? And we can see that by just repeating the calculation, okay? So let's go ahead and pull this in, put it back and we're going to just compare the roots with and without this approximation. So now we're going to make the approximation. We have to leave this X here but we can get rid of this one and this one, okay? And we solve and notice to the precision of the problem three significant figures we got basically the same answer. Actually it's only two significant figures the way I've written it, okay? So we get the same answer either way. So in this case the approximation was definitely good and we could have gotten away without Mathematica. But what if we, let's try starting with much lower pressures, all right? So instead of 1.6, let's start with 0.016 and instead of 3 say 0.03 and instead of 1.4 say 0.014. So 100 fold less in each case, 0.023, all right? So let's go ahead and let that rip, all right? And now you see the root that corresponds to the answer we seek is this one which is 0.013. And I think you would agree with me that that is no longer negligible compared to the values, the initial values, all right? So in that case the approximation wouldn't work. And just to see what we would get if we did make the approximation let's just go down here and put the same numbers in, 0.03, 0.014. And 0.023, all right? And to notice the physically meaningful root, the positive real root here is quite different. We can compare 0.05 versus 0.01, okay? So the approximation here would have given us garbage. All right. So there you have a gas equilibrium problem. And now what I want to do is to solve a series of acid-base equilibria problems, all right? So we're going to start simple. We'll start with the GCAM approach. And then we'll work our way up to increasingly complicated acid-base equilibria problems, including coupled equilibria. All right, so I'm going to go back over to the board now. Any questions on this example? All right, so next we'll start with a simple single acid-base equilibrium problem. So the one we're going to do is acetic acid which I'll denote HAC, aqueous. So acetic acid reacts with water and then produces an equilibrium where we have the protonated water plus the conjugate base acetate ion, okay? And we remember from general chemistry that we can write down the law of mass action in terms of the acid dissociation constant as concentration of H3O plus times acetate divided by the concentration of the undissociated acid. And for acetic acid at room temperature that's 1.76 times 10 to the minus 5, all right? Now, suppose we want to calculate the pH for an acetic acid solution where the initial concentration is equal to 1.00 molar. What do we do? Well, we can write down our ice table, okay? So we start out with 1.00 and I can write a zero for that and a zero for that. Now, when I write down a zero here, what am I assuming? But isn't there H3O plus in water? There's H3O plus in water, right? And that is 10 to the minus 7 molar at room temperature. So when I write down zero here to make life easy, I'm assuming that that's going to be negligible. Now, in a little while, we'll see that what we can do when that's not negligible. But certainly in G chem, we assume that and for the problems you're asked to solve in G chem, that's usually a safe assumption, okay? So then we can say minus X plus X and plus X. So we have 1.00 minus X, X and X. And so then our problem to be solved is X squared over 1.00 minus X, all right? So that gives us a quadratic equation which we can solve using the quadratic formula if we need to. Or in cases like this, the equilibrium constant is 10 to the minus 5. We start with a big amount of acetic acid. We can assume that X is small compared to one molar and so this would give us X squared. All right, so then we just take the square root of the acid dissociation constant, we get X and then we can calculate the pH as minus log 10 X. All right? So let's go ahead and we'll do this problem. We'll set it up in Mathematica. We'll do the calculation and then we'll start playing around with it and see about this approximation, okay? That's what we'll do right now. Okay, so let's go ahead and put in the K a, 1.76 times 10 to the minus 5. And then I'm going to get the roots of the equation to be solved which is solve X squared divided by 1.0 minus X equals, equals K, solve for X. Actually, let's first do the approximation. All right, so we get rid of that, solve. Okay, so we get two roots. Obviously, the second one is the one we want. All right? And so now we can say give me the pH or I can, another way I can do is I can say CH3O, the concentration of H3O at equilibrium is equal to X slash dot roots second element. And then I can say pH equals minus log 10 of CH3O, okay? Oops, minus log 10. Sorry. So I must have, oh yes, I, this one here is a zero when it should be an O. All right, there we go, thank you. Okay, so there you get a pH, 2.377, is it acidic or basic? It's acidic, fairly acidic and great. But, you know, we did that in GCAM. So let's just try for fun, redoing it, but now we'll do it exactly. So I'm going to go ahead and mouse that in. And then I'll just put everything all together here in the same cell, all right? And now we're going to put back the minus X. So this is an exact solution. We enter and we see that out here to the third decimal place, well to the second one here, that the answers are the same. Okay, so you can see here that the approximation was good. And how good will depend on your criteria, how much precision you want to have. But certainly according to GCAM standards, that would be perfectly acceptable. Let's try another case. Let's reduce the concentration by a factor of 1,000, 0.001. And, okay, so we can go ahead and do that. And go ahead and do that. Okay, and you notice now the pH is not as low. We didn't have this concentrated solution, one millimolar as opposed to one molar. And now let's do the same thing here. Well, first of all, let's ask, how does this compare to the initial value? It's 10%. If you can tolerate that kind of imprecision, then it may be okay. But let's see how far off we are, say, on the pH, okay? Now you see there's a bit more error here, all right? You're off in the, basically, in the second place. If you go down further, you start to see very substantial errors, okay? Now, you know, one of the things they don't emphasize in GCAM, what the error is depends on what you're doing. What the tolerable error is depends on what you're doing. In general, though, this would not be considered very acceptable. Okay. Now, if you keep going down, now you're starting to get some pretty serious issues. So notice here, when we solve this one exactly, well, first of all, the pH is totally different. The approximation here would be garbage. But notice this number. This is the amount of H3O plus that's being produced by the very small amount of acetic acid that we put in. This is starting to approach the amount that would have already been present. Due to the water dissociation. And certainly, if you go down another notch here, you run into the problem now where you're producing only 10 times as much as would have been there from the auto-dissociation. And so, if you were really interested in what's happening here and being very accurate, you need to actually worry about the water auto-dissociation, all right? So now, we're going to solve that problem. And here's a case where Mathematica can be quite helpful because now we're going to have to solve a series of coupled equations, the coupling corresponding to the equilibria that are interconnected, all right? And this is something that those of you who have been in analytical chemistry, Chem 151, have had some experience with. All right. So I'm going to go back over to the board because we have to talk about how to set up this problem. Okay. Now, what do I mean by coupled equilibria? Well, what I mean is that now, if we want to include the water dissociation, in addition to this chemical equation, we have this one, okay? So these two both share a common species that's going to affect the equilibria, okay? Now, we're going to see how to solve this in a very, very general way that will apply to any, any of coupled equilibria like this. It doesn't have to be acetic acid. In fact, we can get rid of the Cs here. It can be just any acid and it's conjugate base, okay? And we're going to assume just for the heck of it, it doesn't, we don't have to be precise here, but we'll say that this guy may also be present as a salt, a sodium salt. So we may, in addition to having some acid in the solution, we may also dump in some of the salt of the conjugate base and just to make things more interesting and complicated. Okay. So now, let's think about how many unknowns we have if we want to understand what's the concentration or we want to know what's the concentration of all species present at equilibrium. How many unknowns do we have? We don't know that until we solve the problem. We don't know H3O plus. We don't know OH minus. We don't know A minus. And we do know sodium plus, but let's just keep it here for now. So these are all the species present at equilibrium. Now, if I have five unknowns, how many equations do I need to determine the solution for five unknowns? I need five. How many do I have so far? One. So we have to come up with four more equations. All right. Well, one of them's easy. We can say that sodium plus, because it's a spectator ion, its concentration is whatever we started out with the concentration of the sodium salt, okay, of the conjugate base. So I'll just call that little c sub b. So the concentration of conjugate base that we started out with, okay. What else do I know? Well, I know the equilibrium constant for this reaction. So I'll go ahead and write that over here. That's k water is equal to H3O plus times OH minus divided by, well, that's just it, no water in there. And that's equal to 1.00 times 10 to the minus 14 at room temperature. This is for acetic acid. All right. So now we have three equations. We need two more. Anybody from Chem 151 remember what to do next? Well, one thing we know is that the total charge has to be zero. And what that means is the concentrations, the sum of the concentrations of all the cations has to equal the sum of the concentrations of all the anions, right? Okay. So now I can say then that Na plus concentration plus H3O plus concentration is equal to OH minus concentration plus conjugate base concentration at equilibrium. Okay. Make sense? Okay. We need one more. This last one's a little tricky, but once you hear it, you'll be, oh, okay, I see. So let's have a look at this equation here. This equation here has an A on both sides. What's the A? It's whatever the molecular species is, in this case, it's written as an anion that makes up the conjugate base, or when it has a proton on it, it's the weak acid. This species A is conserved. It's not made or destroyed in the reaction, right? It either loses or gains a proton, but A is conserved. So we can write down a fifth equation that expresses the conservation of A, all right? And so if I say that the initial concentration of acid that I started with when I made my solution is Ca, all right? So that's the initial amount that I put in. And we already said that the initial concentration of our salt of the conjugate base is Cb, so that, this is all the A species that we put in it initially. And so we can say that that has to be the same as the concentrations of the A species at equilibrium. And so that means we can write Ha plus A minus, okay? So just to be clear, these are numbers that are given. We decide what the initial concentration of acid and salt of conjugate bases. So I might say, okay, I'm going to start out with 0.1 molar acetic acid and 0.1 molar sodium acetate, and I want to know what the pH of that buffer solution is, taking into consideration the water dissociation, all right? Now, so we have this equation here basically eliminates sodium. We don't need to have it because we've basically put it in here, all right? So we have this equation to solve, and we have, or that one to include in our solution, this one, this one, and this one, all right? Now, if we were going to solve this by hand, what would we do? You'd have to start combining the equations and eliminating variables, and then finally you'd get down to one unknown. So for example, the H3O plus concentration if you wanted to solve for the pH, and you'd get a polynomial equation for that, that you would either solve or use an approximation to simplify and solve. Okay? Well, the cool thing is we don't have to do that. So there's an additional Mathematica command that we can use where all we have to do is type in the four equations, and then there's a command called eliminate, which will allow us to eliminate all the variables we don't want, and it will give us the polynomial equation and the variable that we want, which we can then pipe in to solve, and then we get the answer. It's actually pretty cool, all right? So let's go ahead and do this problem for the general case where we make possibly a buffer, or we just have a weak acid solution, and we're going to solve for the pH. Sound like fun? I hope so. Okay. All right. So I want to emphasize to you what we're going to do now. This is the general solution to this problem. So you pick any salt of a conjugate base, a monoprotic acid, and any weak monoprotic acid, and we're going to have the solution for that, for any concentrations. Okay. So what I'm going to do now is I'm going to clear CH3O because we used that already, and then I think we're okay. All right. So now I'm going to make a list of our equations. Okay? And I'm going to write them in a way that they're easy to see. So I'm going to say equations, equations equals, return, and the first one I'm going to put in is the acid dissociation equilibrium. Okay? So I'm going to say Ka equals equals the concentration of H3O at equilibrium times concentration of OH minus, oh no, sorry, it should be A minus, so Ca minus divided by Ca. So this is the equilibrium concentration of H3O plus equilibrium concentration of the conjugate base, equilibrium concentration of the undissociated acid. All right? Then I'm going to put in a comma, and then I'm going to put in the water dissociation equilibrium, KW equals equals CH3O times COH, all right, comma, return. Now I'm going to put in the conservation of the A species equation, so that's the initial concentration of acid plus initial concentration of salt of conjugate base equals equals CHA plus Ca minus, comma, return. And then finally the equation that expresses the conservation of charge or neutralization condition. So that's the concentration of sodium, which is the initial concentration of conjugate base plus concentration of H3O plus. So all the pluses equals all the minuses. So that'll be Ca minus, sorry, lower case, and then plus COH, okay? Now I don't need a comma here. I can hit return, put a curly. I should have put a curly up here, okay? And then I'm going to put a semi-quolline, okay? So now you can see by typing them in this way, we have a nice tidy array of equations that's just easier to read than if we typed them out on one line, okay? Now this next step is a new command, but as you'll see, it's really cute, all right? So I'm going to do the following. I'm going to put in simplified. I'm going to define that as the equation that I'm going to get by eliminating all the variables here except for H3O. So it's basically going to combine all these equations and eliminate all the variables that I specify. So I say eliminate, oops, eliminate bracket, equations, and then I put in a list of all the things I want taken out. So I don't want Ca minus. I don't want Ca and I don't want CoH, okay? So those are variables that I'm getting rid of. I have four equations. I get rid of three unknowns. I'm going to have one equation and one unknown, all right? Now if you let that rip, oh, we've got a bunch of numbers in there. We're going to have to clear some more stuff. You think it's K, yeah it's K, it's black there. Yeah, let's get rid of Ka here, all right? Okay, that's what I wanted. Now that's interesting, isn't it? So notice that the only unknown in here is CaH3O because I know I'm going to, I put in this concentration. I know Ka in principle. I know K water, all right, and I know this concentration. So the only unknown is CaH3O and what order equation do I have here? I have a cubic so I wouldn't want to solve this by hand. I would either have to use some approximations if I was in a regime of concentrations where that would be sensible or since I have it typed into Mathematica, I can get the general solution, all right? And the way I could do that is I could say roots equals solve, simplified for CaH3O, okay? And as we've already seen, a cubic gives quite complicated looking solutions, all right? So in fact, what you might normally want to do is put that in there, okay? And now we could actually evaluate CaH3O for a particular, so this is the totally general solution. For this problem, all right? We don't care what acid it is. We don't care what the initial concentrations are, all right? So let's go ahead and use these to actually do a problem where you need to worry about the water dissociation, all right? So what this is going to be is we're going to consider a 10 to the minus 5 molar solution of HCN. HCN has a Ka of 6.17 times 10 to the minus 10. So let's see what we would get if we use the approximation, the weak acid approximation and ignored the water dissociation, all right? So the concentration of H3O would be, for that case, it would be square root of the initial concentration, so 1.0 times 10 to the minus 5. And then times the Ka, so that would be 6.17 times 10 to the minus 10, okay? So this is the concentration of H3O plus if we use the usual weak acid approximation. Notice that says we have actually less H3O plus than comes from water, so obviously that's no good. Wouldn't you agree? All right, so let's go ahead and do it exactly. We have the solution already in our hands. We just need to plug the numbers in, all right? So what we can do is we can say CH3O, no, no, sorry. Let's have a look at what it is. So we say roots slash dot, no, sorry, we have to say CH3O. This is a little confusing. Yes, small c. All right, so we have CH3O and then slash dot, roots, and then now we're going to use replacement rules to put in the known numbers, all right? So slash dot, list. So our concentration of acid, I said, was 10 to the minus 5 initially. We did not put in any conjugate base, so I'll set that equal to zero. We said that Ka is equal to 6.17 times 10 to the minus 10. And we know at room temperature, K water is equal to 1.0 times 10 to the minus 14. Can you say K is equal to minus 10? Yeah, it should be minus 10, thank you. That would give a very strange result. Okay, now let's go ahead and enter that and notice, notice what? Well, we got three roots, okay, that's to be expected. Okay, I think that's okay. Now notice we got complex roots, okay? And it's really hard to tell, though, what to do here, right? Because these imaginary parts, they're small. So for all intents and purposes, we can assume that they're negligible. Now the thing I'm a little confused about, though, is that this doesn't exactly match my notes. So let's go ahead and do the pH equals minus log 10. Of CH3, well, let's just go ahead and put all this stuff in there. Okay, that makes more sense. All right, now we got three complex numbers, but it's pretty clear that this is one that is for all intents and purposes a real number because this is tiny, whereas these ones give substantial imaginary parts, okay? So, how can you get rid of these? So this thing is sort of within what you might call machine precision, and there's a nice command that will clean that up for you. And that command is called CHOP. CHOP will chop off numbers that fall within the range of numerical error in a calculation, okay? So if I say CHOP, bracket, and then bracket, you see now that this guy becomes real because that imaginary part was negligible. And so this has to be the correct solution, all right? So the pH of 10 to the minus 5 molar HCN, we predict to be about 6.9. Does that seem reasonable? Seems reasonable. We put in some acid, so we expect it to be acidic, right? But it's a very weak acid, and so we expect it to be very close to neutral, just below 7, and in fact it is. All right, last thing I want to do is now let's ask the question, instead of putting in just the acid, I'm going to make a buffer by putting in a salt sodium cyanide, okay? And in fact what I'm going to do is put in 10 to the minus 4 molar. What's going to happen to the pH? It's going to go down if I put in sodium cyanide. It's tricky, all right? So I'm putting in sodium cyanide. Cyanide is a weak base, correct? Sodium cyanide can hydrolyze water and make the solution basic. And so if I actually put in more sodium cyanide than I have HCN, you might expect that the solution is going to become basic. Now, based on what we've done here, how can I do that calculation? All we have to do is change one number here. We've got the general solution for this problem. We just changed CB, exactly. So let's put in 1 times 10 to the minus 4. And the answer will be right there. And there you have it, 9.5, basic. All right, so the point is we've solved this very general problem. You see that using Mathematica, treating coupled equilibria like this is a piece of cake. And we'll do another example next time involving a diprotic acid and amphoteric equilibria. And then we'll move on to a new subject, differential equations. So we'll see you on Thursday.