 I thought I'd start out by asking if anyone has any questions or anything you want to discuss before we move on. Everybody got the homework done? I hope not. You haven't even seen it yet. Okay, so today we're going to start out with an introduction to one of the most useful things that you'll learn how to do using Mathematica, and that is to make nice plots. Right? So we all know as scientists that cleverly plotting data is a very nice way to convey a message. And the message is best conveyed when you have a very meaningful and informative plot. And so what I'm going to do today is introduce you to some, a few features that will help you to begin to make nice looking X, Y plots. So plots of, functions of one variable. And then a little later in the course we'll learn how to make 3D and even 4D plots. And like I said, I think this is one of the more valuable things that you'll learn how to do. All right, so we're going to start with a very simple example. And what I'm going to do is show you how to plot a simple function. So it's going to be the sine function. And we're going to do it over one cycle. So it'll be from 0 to 2 pi. All right? And the name of the command is called plot. This is the very simple plotting command for plotting a function, either one that exists in Mathematica or one that you've defined and we'll learn a little later today how to define our own functions. And in its simplest form, all you do is you say, what's the function you want to plot? So in our case it's going to be sine x and don't forget that arguments to functions go in square brackets. And then we need to give a range, okay? And by the way, the variable doesn't have to be x. This is just a very common one to use. It could be y, it could be t, it could be a, it could be your name just so long as you're consistent in referring to it. All right? So then I put a comma and then I put a range and this is going to be our first introduction to the use of the curly braces and as I think I previewed to you last time, there are lots of different ways to use parentheses, braces, and square brackets in Mathematica. And braces are generally used to enclose lists. And in this case we need to make a list of what's the variable, so we've said sine x so we should put x and then we put the minimum and maximum value over which we want x to be plotted. So I'm going to go from 0 to 2 times pi. Remember pi is capital P, lower case i. All right? And then I close my square brackets and I enter. And if you did it right, congratulations because you have your first plot in Mathematica. And so let me start by saying just a couple of things about it. So first of all, there is, unless you specify otherwise, a fixed dimension to the plot. Okay? So there's a Mathematica decides to use a certain amount of real estate in the vertical direction and then it by default uses about 1.6 times that in the x dimension so you get this rectangular plot. And if you wish, you're certainly free to change this and many other attributes of the plot. And I'll show you a few and also show you how you can use documentation to unravel and uncover a universe of possibilities for customizing your plot. Now the next thing is that notice that this sine wave fits very nicely within the plotting frame. In general, Mathematica is going to try to fill as much of the plot as possible and so it's going to adjust the limits in y, so in this case from minus 1 to 1, that happens to be the limits of the function, and x so as to use as much of the plotting frame as possible. Now this isn't necessarily what you want and as we'll see, you can change that too. Okay? And then the third thing that I'll mention here is that Mathematica has, when you first fire it up, a default coloring scheme that it uses. And according to that default coloring scheme, the first curve when you're plotting plots in a given plot frame is going to come out blue. Once again, this is something you can change and I'll show you a couple of ways that you can do that. All right? And then if you plot another curve, which we'll do in just a second, it will come out in a different color. Okay? So that's kind of useful to know if you're plotting multiple plots. All right. So this is a very simple plot and you can see that the command for it is also very simple. Okay, so what can we do now? Well, this is a good time for me to emphasize something that you should start thinking about all the time, which is as soon as you do anything significant as you're working, you should save your file. All right? So if you haven't already seen how to do that, let's go ahead and do it now. All right? So what we're going to do is uncover the menu here and then I'm going to say File, Save As and if I click on local disk, there's a folder called Save Here. Okay? So on these lab computers, you're allowed to save files in that directory. All right? So let's go ahead and click on that and then you can put in a name. All right? So yesterday I saved a file called dug1.nb. Today I'll call it dug2.nb. You can call it whatever you want. Okay? Now, another very important thing to keep in mind is that this file may not live very long after you leave the class. Okay? In principle, they wipe these disks, all these Save Here directories automatically every 24 to 48 hours. So the next thing you should do, especially when you're working on your homework and double especially when you're working on your exams, is to save a backup copy. Okay? So all of you have probably been using computers for some time now and I would bet that most of you have some tales of woe about how you've worked for hours on some precious document right near the deadline and the computer crashed or the program crashed and you lost everything and you cried and you were really stressed out about it. So what I recommend that you do to avoid that stress is to get into the very, very good habit of making backups. Now in this course I can recommend say three that are very easy and take a very small amount of time. One is just immediately email a copy to yourself. Another is create a drop box on your EEE that you have waiting for you and upload a copy of your file to your say Chem 5 miscellaneous drop box. And another thing you can do is you can have a thumb drive at the ready in the computer and move a copy over to your thumb drive every now and then to create a backup. In this class, losing your data because of a computer crash is kind of like turning in a paper late because you're dogged it. It's not an acceptable excuse. Okay? So I've given you three good ways to backup your data and I will assume from now on that you'll be doing so. All right? Okay. Now back to our plot. So the next thing we're going to see how to do is how to plot two functions at the same time. Okay. So the way you do that is you make a list of the functions that you wished to plot. And so a list is enclosed in curly brackets. So I'm going to put some curly brackets around this. And then I'm going to add the second function which in this case is going to be cosine, cos of x. And now if I press enter, you see that I have two curves. Now, how do you know which is which? Well, first of all, you should know the difference between cosine and sine, but if you didn't, you could infer it because as I said, mathematics always draws the first one with the blue. And now you can see that by default, it draws the second one as purple. Okay? All right. So there's an introduction to plotting more than one function. Now I want to show you another way to plot something. So this will be, if you like, an arbitrary function of your choosing. And then we'll see how we can manipulate some of the attributes of the plot because this plot is not extremely informative, right? It doesn't have any axes labels. It doesn't have any units. It doesn't have a title. It doesn't have a legend. And unless you knew that the blue curve was first and the purple curve was second, you may not know which is which. So we'll have a quick look at a few of the various ways that you can customize your plot to make it much more informative. Now, before I do that, though, I want to just introduce you to the documentation center in Mathematica. This is an extremely useful resource. You may not use it too much in this class because, as I said, I'm going to show you how to do everything that you need to know in this class. But in future, you may want to look up how to do things. Or even in this class, you may want to look up how to do some snazzy things that I'm not going to teach you just because there's not enough time. Okay? So what you do is you go under the help menu and then if you want, you can search for anything you want. Okay? So suppose you were interested in finding out more about the plot command, the various options that you may have. Just type in plot, hit return, and notice that the first thing to come up here is documentation on the plot command. But you also can take a tutorial if you want. This is often available. And there are additional guides like general algorithms for data visualization, et cetera, et cetera. So let's go ahead and click on this. And you see that you get, first of all, a very, very basic introduction to the syntax of the command. And then there's this box that says more information. And usually, the useful stuff is in that box. And so now, if you look at this list of things, these are all lists of options that you have for changing the attributes of your plot. And it looks pretty intimidating, but most of the time, you won't care about most of those things. I'm going to show you a few of these. But I just want to let you know that this exists because you may be curious and want to waste some time making your plot look really super cool. Okay. Now, another thing that's occasionally fun to look at is the examples. All right? So these just generally show some very simple things. It's by no means exhaustive. And then down at the bottom, they usually have something called neat examples. So this one's particularly cool because it's actually a chemistry example. And this may not look familiar to you, but as soon as you take Chem 131A, you'll know exactly what this is. This happens to be a very nice representation of the first 1, 2, 3, 4, 5, 6, 7, 8 wave functions, or I guess those are the probability amplitudes for the harmonic oscillator, which is a simple model for molecular vibrations. Has anybody heard of that before? Aha. Are you in Chem 131A or took it already? No? Okay. Cool. All right. Well, you'll get a massive coverage and introduction to that in Chem 131A. Those of you who are in that course will be getting this probably within a couple of weeks from now. All right. But anyway, you can see that if you really wanted, you could make such a beautiful plot yourself in Mathematica, and it's not that complicated. Okay. So that's the documentation center, and I encourage you to consult it from time to time. Like I say, for the most part, though, you won't need it in this course. All right. So next thing we're going to do is we're going to plot a function that we define ourselves in the plot command itself, and then we'll manipulate it. Okay? So here what I'm going to do is I'm going to say plot, and then instead of typing in a predefined function like sine or cosine, I'm going to plot an equation for a parabola. So it's going to be 2 times x minus 4, quantity squared, and then plus 1. Okay? And I'm going to plot this between x equals 3 and x equals 5. Okay? Now, what should this look like? Well, it's a parabola that's going to be displaced along the x-axis by 4 and along the y-axis by 1. All right? So let's go ahead and let it rip, and there you have it. And as before, Mathematica chooses the limits while we chose the limits of x, but chooses the limits of y so as to fill up as much of the frame as possible with the graph. And you can see that it's chosen to use the lower y-limit as 1. All right? So there's your parabola. Now, what if you wanted to represent this in a different way? So suppose you're teaching someone how to interpret the equation of a parabola. You might want to plot it in such a way that you can easily see that it is in fact displaced by 4 and x and by 1 and y. In other words, you may want to plot it so that the origin of the plot, which here was chosen for us, happens to be 3 and x and 1 and y, is at 0 and 0. So you can really see that it's displaced from the origin. Well, that's something that's easy to change, and this will be our first introduction to a long list of potential plotting options, okay? And it's also an introduction to a new piece of syntax. So if you want to change the origin or specify the origin, you use an option called axes, so it's capital A, and then origin with the capital O. And then what you do is you use an arrow construction to point to where you want the origin to be. And the way you make an arrow is you make a hyphen and then a greater than, and then you put the coordinates that you want the origin to be at, all right? So I'm going to do 0, 0, and I put those in curly braces, all right? And now, if I enter that, notice that it's drawn the same curve, but now the origin of the plot is where I told it, 0, 0. And now we can see very clearly by looking at the plot that it's displaced, the minimum is displaced by 4 and x and 1 and y, okay? So it's exactly the same data, but it's plotted in such a way as to convey a new point, all right? It's a very simple example of a manipulation that you may want to do from time to time to make your plot convey the message that you wish to convey. Okay. Now, one more comment. We're going to be learning more and more of these options, and you might be thinking, man, this is super confusing. I don't remember when to use curly braces, when to use arrows, what the words are that I'm supposed to be using to do this or the that. Don't worry about that, because the best way to make complicated constructions in Mathematica is to look at an example and then modify that example to do what you want to do. And as I already emphasized last time, anytime you're doing anything in this class, you will always have available to you the notes from the class, and everything that I'm going to ask you to do, there will be an example of that in the notes, okay? So don't get bogged down memorizing all the syntax, all right? So another thing that you can do, so here we've changed the origin, okay? Another thing that we may want to do is we might want to actually manipulate the range over which the function is plotted, okay? So here, Mathematica chose to plot it between 0 and 3, and since we didn't specify the range of X, it uses the full range that we specify, which was 3 to 5, plus if there's an origin, it also includes whatever's between that and the origin, okay? So to customize the plot range, what you can do, so let's go ahead and mouse this in here. So control C to copy, and then control V to paste. So there's another option, which is called plot range. So plot, and then capital R-A-N-G-E, and here what we need to do is include two ranges, one for X and one for Y. So suppose in X I want to go between 1 and 10, all right? So that's the X range. Now I have to include another set of curly brackets, and then put a comma and specify the range of Y. So Y, I may wish to make, let's say, just for fun, 0.525, okay? So if we enter, whoops, I need another curly bracket here, then I get this plot, okay? So there's no particularly compelling reason why I chose that range other than just to show you that you can change it. And as you see, the plot goes between 1 and 10 and 0.5 and 5, as we told it, okay? All right, what else can we do? Well, I'm going to start by going back to our very simple plot. I'm just going to nuke all this stuff here and re-enter. All right, so so far all the plots we've made are pretty lame, actually, because we don't know what we're plotting, all right? So how can we specify what we're plotting? Well, one thing we can do is we can label the axes, okay? Another thing we can do is we can actually give the plot a name or a title, a label, okay? So now I'll show you how to do that. So these are additional options, and the first one to label the axes is called axes label, and then we need an arrow. And then we need to make a list of two names, one for the each axis. And these should be in quotes, because they're going to be written exactly as whatever you put in the quotes. So in the first set of quotes for the x-axis I'm going to call it x. And for the second axis, y, I'll call it y. Now, if you enter that, you see that you have a microscopic label over here for x and another microscopic label here for y. And I'll show you in a moment how you can change the sizes and fonts and things like that. Okay, now what about the label? Well, we can put in another option. It's called, ironically enough, plot label, arrow, and then in quotes you put in whatever you want. So you can say this is a cool plot or whatever you want to say about it. You might want to say this is not a cool plot. Okay, and if you enter that, now you see that you have axes labels and a plot label. Now, as you can see, I wear reading glasses. So for me, these microscopic axes labels are very hard to see without putting my glasses on. So if I want to be able to read my plot without my glasses, I need to make those bigger. So I'll show you how to do that. In addition, I don't know about you, but I'm not a big fan of the times font, which is the default font that you get when you make plots. I actually like the sans serif faults like Helvetica. You want to change that? No problem. Here's how to do it. All right, so more options, which we just tack on to the end. Now, the syntax for changing these things looks pretty intimidating, but like I say, don't worry about it. You can look at the notes, for examples. So these attributes, things like the font face, the font size, these are what's part of a broad array of attributes called base style, okay? So the way we change them is we say base, style, arrow, and then we have some curly brackets because we're going to make a list of things that we want to modify, all right? So the first is what's called font family, and I'm going to put it, whoops, I spelled it wrong, font family, and then I put in an arrow, and then I'm going to change it to one of my favorites, Helvetica, okay? And then the other option I'm going to put in is the font size, arrow, and I'm going to crank it up to 16, 16 points. I think the default is 10, all right? And I got an error. I forgot the curly bracket before the 16, where? Here? I don't need a curly bracket there. I have a curly bracket here that includes both of the base style options, and well, we could see what it has to say here. So, you know, this is going to happen a lot, right? And it's good for you to see how to fix things. Oh, you know how to fix it? Oh, yeah, I don't need quotation on the numbers. That's right, thank you. All right, let's see if that works. Okay, there you have it. All right. So now you can see we have the Helvetica font and you can read it. The axes, labels are bigger too. Okay? So as time goes on, you know, you're going to learn how to make more and more modifications to your plots. In the homework, I'll often give you very specific instructions about what I want you to do. And so you should always do that. But in addition, I encourage you to let your creative juices flow and use colors or plotting attributes to spiff you up your plots to your heart's content. You'll impress your TAs when they're grading. So the minimum requirement is include all the elements that I tell you to, but after that, the sky's the limit as long as you don't, you know, modify the information content of the plot. Okay? All right. Now, let's do some other things that are very important if we want to make scientifically meaningful plots. Okay? So now I'm going to go back to our previous example of the sine and cosine. All right? So I'm going to mouse this in and put it back, control V. Okay? And we'll go ahead and enter that to remind ourselves what that looks like. So here we have our two curves. All right? And what I want to do is I want to play around with the curves so in various ways so as to make them distinguishable, more distinguishable. Okay? And also while I'm at it, I'll show you how to make plots in black and white or grayscale. This is sometimes nice because if you have, say, a black and white printer, if you were to plot these two curves, they'd probably be really hard to tell apart. So you may want to make your curves in black and white and then use other attributes like line thickness or dots and dashes and things like that to make the plots look different. Okay? So we'll do that first. All right? So now what we're going to do is we're going to make both of these curves black. All right? And this can be accomplished by using an option called plot style. Okay? And I'm going to put some cur, whoops, it has to have an arrow and then some curly brackets. And then for each of my plots, I'm going to specify some attributes inside plot style. Okay? So one of those can turn these plots into what are called grayscale. All right? So let's do that. So for the first plot, I'm going to say gray level and I'll explain to you how this works in just a second. Bracket zero. So that's an option for the first plot. And then if I put a comma, then I can specify an option for the second plot. And I'm going to make it the same. And if I enter that, you see that I converted both of these plots to black. So gray level is the number between zero and one. Zero is black, one is white. Okay? So if I wanted to make one of these plots gray so as to make it distinguishable from the other one, so for example, the second one, I could change this number to say 0.5. If I do that, then you see that the cosine curve actually comes out gray. But still, that's not a very impressive difference. So what I'm going to do instead is I'm going to go ahead and keep this one black, except now I'm going to add an additional option for the second curve that will turn it into a dashed line. Okay? So if I'm going to add an additional option, I have to put in another set of curly brackets so that I can make a list of options for the second plot within those. Okay? And to make a dashed line, all I have to do is say dashed. Okay? And if I enter that, I see that it didn't do it. And one problem is I have this curly bracket in the wrong place. Okay. So there you have it. All right? So that's kind of nice. And, you know, I'm not going to go into all the things that you can change, but if you look in the documentation, there are many other options besides dashed. And you can also change the size of the dashes for each curve. You may want to make several curves with different size dashes so as to distinguish them. Okay? So we have a question. I'm sorry, I can't hear you. Well, to change back to blue and red, you just remove all the stuff that we did to change it away from blue and red. Okay? So here, I'll show you how. So we mouse this back in and if we could just go down here and remove all this stuff that we changed, we'll go back to the default. Okay? All right. So it may not be obvious to you why you might want to do this. I guess the most straightforward example is you may have a black and white printer and you want to make a meaningful plot. Another is this maybe isn't so relevant to you at this stage of your life, but when you publish stuff in journals, sometimes the publishers will charge you a lot of money to get your figures plotted in color. And so whenever you can make plots in black and white, you tend to do so to save money. And because we have things like dashes and as I'll show you in a minute, line thicknesses, things that we can change, we can still make perfectly beautiful, meaningful plots without using color at all. Nowadays, color printers and color toners are pretty cheap, but when I first started, my education, color was very hard to come by and when you could come by it, it was very expensive. Okay. All right. What else can we do here? Well, we can change the thickness of the lines. All right? So what I'll do is I'll change the thickness of the first curve. So I'm going to put in curly brackets around this guy and then there's a command or an option called thickness and there's a number that goes inside and this number happens to be the fraction of the plot width. Okay? So if I put in 0.01, what that's going to do is it's going to draw the first curve in solid and the thickness of the line will be 1% of the width of the plot. Okay? So if you enter that, you see that you get a fat black curve for the sign. Okay? So these are just a couple or a few of the various ways that you can manipulate your plots to make them contain more information. Now, the next thing I'm going to show you is, well, actually I'll show you a couple of things. The next thing I'll show you is how you can make the plot frame look a little bit different. This sometimes is preferable. Some people like to have a frame that goes completely around the plot. Okay? Now, the way you do that is you put in another option. The default is to not put one, right? Here we've got just the two axes. If I put in an option here that says frame arrow true, it'll draw a plot frame. Notice the difference? You may want to do it. You may not. If you do, this is how you do it. Now, one little idiosyncrasy about having the plot frame is that the way you label the axes is different. I didn't invent this, so don't blame me. But I'll show you how to label the axes. So remember when we had the regular plot that doesn't have the frame, we labeled the axes by saying axes label. Here, if we have a plot frame, that doesn't do anything. What we have to do is say frame label. Okay? So let's try that. So we say arrow, and then after that it's just like before we put in the labels we want. So I'll just say x and y. All right? If you do that, notice it puts the labels at the middle of the axes, which is aesthetically pleasing to some. And suppose you want to label the plot. It's the same command as before. It's called plot label. So maybe you want to say my favorite trig functions. All right. Now, the next thing is, again, so far we've done a very nice job of distinguishing our two plots. But if we hadn't taken trigonometry class yet, we wouldn't know which one of those is which. So what we want to do now is we want to include some labels that tell us which curve is which. Okay? And one convenient way of doing that is by using what's called a plot legend. Okay? So what a plot legend is is it basically a little sample of each curve and next to each sample you have some name that you give it that tells you something about what you're actually seeing here. So for example, I might want to label this one sine of x and this one cosine of x. All right? Now, plot legends for some reason, the geniuses at Wolfram Research decided is not something that you're going to want to do all the time. And the way Mathematica is written, it's actually a very, very big and complex program. And if you try to load all of its capabilities at once into memory, you'd be using up a lot more memory than you really need to to do most things. Well, to do pretty much anything you want to do. So what they've decided to do is to load in, when you fire up the program, you load in a small number of what are called packages that you're likely to use a lot. And then there's additional capabilities that you use less frequently that are available, but they have to be loaded, okay? And it happens, turns out that plot legends are one of those things. So if we want to include legends in our plot, we actually have to load what's called the plot legends package, okay? So the first thing I want to do is just to show you how it is that you can see what's already loaded. So if you type dollar and then packages, and enter that, you get a list, all right? And this list probably doesn't mean a whole lot to you and it certainly doesn't mean a whole lot to me. These just happen to be the names of the packages that are loaded by default when you fire up Mathematica. Okay? So one of this, this one looks kind of familiar. That's the searching program. All right. Now, if we want to load a package, it's got a funny syntax, but again, you always have examples to look at. We do the following. We say less than, less than, and then we say the name of the package, so in this case, it's going to be plot legends, capital L, and then you put a backward single quote, which is the upper left-hand corner of your keyboard. All right? And now you enter that. Now, if you type dollar packages again with a capital P and no A, then you see you have an additional one that you didn't have before, which is called plot legends. And now you can actually use commands that are required in order to install a plot legend. So let's go ahead and mouse this guy in here and put it down here and enter it. Okay? And now what we're going to do is we're going to label these two curves with a plot legend. Okay? Now, the way you do that is you add an option, and by the way, this option will not be available to you until you load the plot legends package where you say plot legends, plot legend, arrow, and then you have a list, in our case it's going to be two items because we have two curves, a list of the names that you want to give to each curve. Okay? So for the first one, I'm going to call it sign of X and that should be in double quotes, sorry. And the second one will be cosine of X. Ah, my quote here, I don't have a closing quote here. Okay? There it is. All right. By now, you've probably already noticed that if there's anything wrong with your command, like missing brackets and things that you get these color coded alarm bells going off, so they kind of help you to figure out what you're missing. All right. So let's try that. There you go. So here is a plot legend that tells us that the blue curve is sine and the purple curve is cosine. This is very, very useful, right, for making a meaningful plot. Now, what's not so nice is that by default this thing is placed so that its center is at the lower left-hand side of your plotting frame, which is in many cases not a very pleasing place to put it. So we'll see how to move it in just a second. Another thing that I don't like about this default legend is that they have this shadow, which later on we'll learn how to nuke that, and also you can, we'll learn how to change spacing between these guys and you can get rid of this frame if you want. So there's lots of things you can do, but for right now I just want you to see how to put it there and then move it someplace so that it's out of the way. All right. So now if we want to move it, what we do is we put in another option, which is called legend position, except we have to spell it right, arrow, and then we put in coordinates. So we have to put in x and a y in. And what these coordinates are is they're coordinates in fractions of the plotting frame, all right? So if I want to move this guy all the way off to the right so that it's not sitting on top of my plot, I should put a number greater than 1. And then I can play around with the vertical to get it to a place where I like how it looks. So let's try 1.1 and then I'll put in minus 0.3. So that's going to be the y, where it is in the y. And if you enter that, you see that now your legend is in a much nicer place where it's not sitting on top of your plot, okay? Why am I playing around with 3 more than 6 here? No, because these coordinates are in units of the dimension of the plot. So what 1.1 means is it's 0.1 beyond the edge of this in terms of the width of the plot, okay? Yeah. But usually when you're dinking around with these things, you kind of play with the numbers until you get something that you like. So I just so happen to like this because this is roughly centered on y and it happens to be off the edge of the plot. Change the numbers, see what happens. By the way, that's something I should encourage you all to do while we're sitting here dinking around. You don't have to do exactly what I do. If you're curious to see how something works, play around with the things. The worst thing that can happen is it won't work, okay? All right, any other questions? Okay, so this is all I'm going to say for now about plotting, okay? This will be enough to do a good job on your homework. And as time goes on, we'll see new ways of making plots and we'll get more and more sophisticated. But already right now, you can make really cool plots. And hopefully you're all very happy with yourselves. Okay, now we have a couple of other things that we need to do in order to be able to do the homework. And these are things that we're going to use a lot. So if you have any questions whatsoever in the next 10 minutes or so, please make sure we get them answered. Okay, so the next thing we're going to do is we're going to learn how to assign variables, okay? So let's see how to do that. So the assignment of a variable works the following way. Name of your choice equals something of your choice that you wish to associate with that name. I mean, it's kind of like algebra, right? And then once you've assigned a variable, you can use it subsequently. And you can change the value if you want and use it again. Okay, so your introduction is the following. What I'm going to do is I'm going to define a equals 2 and b equals 3 and then I'm going to add a plus b. I'm going to multiply a times b and I'm going to raise a to the b power just so you see how this works. Okay, so if we enter this, we get a sequence of numbers. This one is just telling us that we've assigned a to 2. This one tells us we assigned b to 3. This one here is the result of a plus b. This one's the result of a times b. And this one's the result of a to the power b. Okay? Now, I want to show you one more thing because, you know, here we've executed a bunch of commands in a row and we have to be, you know, sort of like map them on to each other. It's kind of a pain, right? So there's a very useful thing to be able to do because you don't necessarily want to see the results of all these things, right? You might want to hide the first two, for example. The way you do that is you use a semicolon. This will suppress the output of a given operation. So to see how that works, let's go back and put a semicolon here. And a semicolon here. Wow. And do it again. Now you see that the initial assignment of a and b has been hidden and in general there will be lots of things we don't want to see. We may want to do a whole bunch of calculations and only see the last result, right? And then we get the things in a row here. All right. Now, what else can we do? Another thing we can do is we can make expressions, all right? So now I can say, for example, x equals 2 times a plus b, all right? And if I enter that, I get 7 because I've assigned 2 to a, so 2 times 2 is 4 and I've assigned b equals 3 so 4 plus 3 is equal to 7. All right? Now, suppose I want to go back and just have x defined as an algebraic expression but without any numbers assigned. There's a very useful command that allows you to remove the assignment of a variable name to a number. And this is very useful if, say, within the same notebook, you're using the same name for a number that may, you may use it in one set of units in one place and another set of units in another place so the numerical value changes. So for example, the gas constant might be, you can have that in SI units or you can have it in liters, atmospheres, moles, Kelvin. And as you know by now in chemistry and physics and sciences, we oftentimes use the same letters to refer to different things, okay? And if you're using the same letter in multiple places in a notebook, you may forget that you assigned it to one thing somewhere and you'll get some bogus answer down below when you try to use it in a different context. So there's a very useful command that I will use a lot when we start doing more complicated things which removes the assignment of a variable and that's called the clear command, all right? And so the way I can do that is I can say clear and suppose I want to clear the A, okay? Put a semicolon and now I ask what is X? A, that wasn't supposed to happen. Oh, X, sorry, X was already assigned. Let's clear A and X and now you see X is no longer defined. If I look at A, it's no longer defined. If I say X equals 2 times A plus B, notice, I get 2A plus 3 because B is still assigned to 3, okay? If I clear B and then ask what's X, I get back to my, oh, I'm sorry. So actually this is showing something that's really, it's gotten me confused today and probably get me confused and you confused later. X was already defined as 3 plus 2A here, right? Yeah, so I have to clear it again and redefine it if I want to use it, all right? So if I clear X and now I say X equals 2 times A plus B, now I get back to my pure expression. So you have to be really careful when you assign things if you're going to make assumptions about using those expressions later. It's always helpful to clear things and reassign your variables if necessary, okay? All right, so those are some simple examples of defining variables, assigning numbers to them and then using them in expressions, okay? And you'll get to do some of that in your homework. All right, now the next thing, and this is another very, very important thing that we'll be doing a lot and so I suggest you pay close attention, is we're going to learn how to define functions, all right? This is extremely useful. And so the first thing we'll do is we'll take that parabola that we plotted earlier and we'll assign it to a function which I'm going to call f of X. And what I want you to do here is pay very close attention to the syntax, the way the definition works because this is probably one of the most common sources of mistakes that we'll encounter this quarter, all right? So what I'm going to do is I'm going to define f of X equals that parabola we saw earlier, all right? So the way I do that is I say, give my name, it doesn't have to be f, it could be whatever you want, f. And then remember, arguments of functions come in square brackets. Now, the next thing I do is I put in the argument. And here's one thing that maybe it doesn't make sense but you have to do it otherwise your function won't work. When you define a variable argument to a function, you have to put an underscore. Why is that? Well, why is that is because you may have several arguments to a function but some of them you may wish to remain constant or you may want to put in a particular value so that it's not actually an independent variable. This is so you can distinguish between true independent variables and some parameter or something, all right? So if you want to indicate the variable, when you define the function, you have to put in the underscore and leaving that out is a great source of error. The next thing is when you're first defining the function, you don't just use the equal sign. The function definition is special and it has colon equal. All right, now we define our function. So at this point we could put anything we want in here but I'm going to put in that parabola. Two times x minus four, quantity squared plus one, okay? So I enter that and if I did everything right, usually I won't get any feedback. Now I can check at any time to see if I've assigned f to a function. There's, if I say question mark f, it will tell me whether or not it's assigned and if it is assigned, it will tell me what it's assigned to. So if I enter that, you see that I've, this just means that it's a globally defined function and it tells me how I've assigned it and so I can actually check to make sure it looks like what I want it to look like, okay? Now, once I've defined this function, I can do lots of things with it. So for example, suppose I want to evaluate it for a given value of x, like say x equals one. All I have to do is say give me f of one and you see I get 19. Does that make sense? X minus four is minus three, squared is nine, times two is 18, plus one is 19, okay? You can put in whatever you want. Suppose you say f of pi. If you put in pi, as I told you last time, Mathematica will keep the exact result, so in this case it just puts in the pi. If I want a numerical value for that, I can say n bracket percent like we learned last time. And so there's my numerical value. Another thing I can do is I can plot it by referring to x, I mean f. So I can make the same plot as we made before by saying plot f of x comma and then x goes from three to five. If I do that, I get the familiar plot that we made before, okay? So this is a very, very useful thing to be able to do. Now, yes? Okay. Is there a way you can clear all the variables that you can assign numbers to? Yeah, you just say clear, put in brackets and list them all. Any other questions? Yeah, you sure? Okay. All right. So the next thing I want to do is I want to define a quite complicated function that's relevant to chemistry. And the reason I want to do this is because I want to emphasize to you that oftentimes the way we type functions in this command line of Mathematica looks a lot different from the way it's written in the textbook or on the homework assignment or whatever. Now a little later we'll learn how to typeset our things. But for now anyway, I want to teach you the brute force way to do it. And the main point of this is that as time goes on, we'll be working with fairly complicated functions. And there's lots and lots of ways that you can make mistakes. And so I want to point out a couple of those here. All right. So what we're going to do, I'm going to write the function on the board, is we're going to plot something that you've seen before. You may not have ever seen the formula, but you've certainly seen the function. And it's called the Maxwell-Boltzmann distribution. Does that ring a bell to anyone? Okay. Well, I'll remind you, since I know you know what it is. This is the probability that comes from kinetic theory that an ideal gas molecule has a certain speed. And you may remember seeing this in your G-chem textbooks. It looks something like this, right? It's a distorted bell curve. Okay. And often the variable used for the speed is u. And that's in meters per second in SI units. And then the y-axis is often called f of u or p of u. And it's just the probability that a gas molecule and an ideal gas has a speed within a small increment around u. Okay. Now, the formula is as follows. And this is what we're going to type in, and then we're going to plot it. And hopefully you'll see that it's kind of cool, because you can quickly remind yourself of some things that you were probably asked about on your G-chem final exam in Chem 1A, probably. All right. So this formula looks like this. Okay. So if you look up the Maxwell-Boltzmann distribution in your favorite textbook that may have it. Oh, yeah, let's turn on the light. Oh, thank you. Did I turn off the light? Oh, okay, there we go. All right. So 4 pi times quantity m over 2 pi RT, m here, if we're in SI units, would be the molar mass in kilograms per mole. R is the gas constant, 8.314 joules per Kelvin per mole. T is the absolute temperature. Use the speed in meters per second, and that's everything. Okay. Now, another thing about somewhat complicated formulas is that it's never a bad idea to see if you can't predict before you actually plot it what it might look like. That's not always going to be the case, but whenever you can, it'll be helpful, because there's a lot of ways to screw this up when you enter it in, and when you make a plot, you want to be able to kind of tell whether or not your plot is bogus or it seems to be correct. So let's ask ourselves, what does this thing look like when u is very small? Well, when u is very small, how does this thing look, this exponential? It goes to 1. So the dominant functional behavior is u squared. u squared is a parabola. So it should look like a parabola at small u. What about at large u? At large u, this guy starts decaying very quickly, because it's got u squared in an exponent. So the large u dependence of this function is going to look like a fast decaying exponential. So that's why you have this tail here. Okay? So that helps so that when we make a mistake typing this in, we'll recognize it, and when we get it right, we'll say woo-hoo. All right? So let's go ahead and type that sucker in, and then we'll play around with it a little bit. All right. So notice I already defined f here, and I want to use the same variable. So to keep from getting in trouble, I'm just going to write ahead, right away, say clear f. All right? Okay, now I start typing. So f of u, remember underscore for the variable, colon equals. Then I have 4 times pi, capital pi, and then times parentheses. Another thing that I want to recommend to you is even though the formula over there has some capital letters, and usually you can get away with using capital letters, all of Mathematica's predefined stuff, variables, and functions, they start with capital letters. And so to avoid accidentally stepping on one of those or using them where you don't want to and getting an error, I recommend that you always begin your variable and function names with a lower case letter, even if it doesn't look pretty. Okay? So I'm going to go ahead and use little m for the math. So m and then divided by 2 pi r t. So I say 2 times pi times little r times little t. Okay. Yes. So already one of you sees a problem with this. So how is this going to be interpreted? What it's going to do is it's going to divide m by 2 and it's going to multiply all of that by pi r t, which is not what that formula says. That formula says multiply all these together and then divide m by that. So in order to make sure that that actually happens, I have to use parentheses to keep the pieces of the denominator all together. Okay? All right. Now, I want to raise the whole thing to the 3 halves of power. So carat and then to make sure I get my 3 halves, I put that in parentheses. And now I want to multiply by u squared. And then finally, I have to put in that exponential. So remember capital E and then carat and some parentheses. And now I'm going to use parentheses to group the numerator and denominator of the argument to the exponent together. So the first one is minus m times u carat 2 parentheses. And then divided by parentheses 2 times r times t. All right? So does that look right? Let's enter it. Okay. Now what we're going to do is we're going to plug some numbers in. And we're going to see if it looks like what we remember from GCAM. All right? So I'm going to do N2. So it'll be like a typical gas molecule in the air in this room. All right? So I'm going to say the mass is equal to 0.028. That's the molar mass of N2 in kilograms per mole. Okay? I'm going to put a semicolon because I don't want to see it. I'm going to put in room temperature. So 300 Kelvin. All right? And what else do I need to specify? R, the gas constant. So I'm working in SI units. So I'm going to say r equals 8.314. And that's Joules per mole Kelvin. All right? And now what I'm going to do is I'm going to plot F of U. And what you may or may not remember from GCAM is that the average speed of a typical low mass gas molecule at room temperature is a few hundred meters per second. So that tells me that if I want to see the full range of this curve, I might want to go out to say a couple thousand. That's going to be my range for U. So U goes from 0 to 2,000. All right? And let's let it rip and see what happens. And sure enough, I get something that looks like the Maxwell-Boltzmann distribution. Look familiar? By the way, another thing that you can do anytime in this class is if you need to go look something up somewhere, to check your result because maybe you think, oh, I've seen that before, but I don't remember what it looks like. Feel free to Google Wikipedia, whatever you want in this class. I encourage that. Okay? So anyway, if you were to Wikipedia, the Maxwell-Boltzmann distribution, you'd find a curve that looks like that. All right, now we have a learning tool because now we can say, oh, I forgot how that changes when I change the mass. So suppose I want to say, hmm, what happens if I look at a heavier gas molecule like chlorine, Cl2? Well, I can change the mass. So let me go ahead and just, well, let's go down here so we can see it. So now I'm going to change the mass to M equals 0.079. That's the molar mass of chlorine, Cl2, in kilojoules or kilograms per mole. And now I can just mouse this guy back in and put it here and replot. And now I can remember what happens when I change the mass of a gas molecule. Notice that I've moved the most probable speed from over around 500 down here to, you know, around 300. And this makes sense, right? Because we remember from GCEM that heavier molecules move slower at a given temperature than lighter molecules. What if you wanted to see the effect of temperature? What happens as you crank up the temperature to the speed of a gas molecule? It increases. All right, well, let's go down now and have a look at what happens if we change the temperature to 1,000 Kelvin and then replot. So now this is going to be chlorine at 1,000 Kelvin. And sure enough, you see that the peak moves to the right and the distribution becomes broader. So you can compare these two to see the temperature effect. All right? So there you have it. That's a somewhat complicated looking thing there. And we successfully typed it in and we actually used it to dust the cobwebs off of our knowledge about kinetic theory of gases. All right? Okay, so we have a few minutes left. And what I'm going to do now is just show you a couple more little miscellaneous things that you may find useful in your homework. And then I'll spend about three minutes going over telling you exactly how to do your homework. Okay? So first of all, everything we've done so far is we've just put in a bunch of random commands in our notebook. Now, what you'd really like to be able to do if you, say, are doing your homework and you want your TA to understand which problem you're working on and maybe you even want to provide some information about what you're actually doing so that if you do happen to make a mistake, they can at least tell whether or not you knew what you were doing or supposed to do. You want to add information in your notebook that's not actually executed but is just meant to be informative. This is useful if you have a very complicated notebook and you want to give it to somebody else and have them be able to read through it and understand it. Okay? So there's a couple, there's lots of ways to do this. I'm just going to show you two. Okay? So the first is and simplest is to use what's called a comment. Okay? So a comment you can type directly in without doing anything else and the way that works is if you say parentheses star, that's a signal to Mathematica to ignore everything that comes after it. So for example here I'm going to say plot MB distribution for CL2 at 1,000 Kelvin. Now to end the comment what I do is I say star parentheses. Alright? And now if I enter that nothing happens because it's ignored but it does appear in the notebook. Alright? So you might want to say, you know, you might want to put another line in here that says this is homework one, problem one. Oops. And that will help your TA to see what it is you're actually working on. Okay? So that's one way. Another way which I find that most students prefer because it's a lot snazzier is you can go anywhere in your notebook and you can introduce a different type of area, okay? So so far all we've done is we've been in this sort of command mode but you can change into different modes. So for example, format style, I can change from input mode to text mode, okay? And now I can say this is a text box and if I want I can do all the usual things here like change the font and the font size. I can change the color of this to make it look different so that my text is say with a lime green background as opposed to just the white. You can play around with this stuff and make your notebooks look really snazzy and easy to read. Okay? So you're welcome to do this. You don't have to but I do advise at least at bare minimum the use of comments to make your notebooks as easy as possible to read. All right, now let's have a look at the homework. All right, so there should be a drop box set up for you. This is section A so it's going to say homework 1A and when you're done with your homework you can turn it in there by the deadline is Saturday 5 p.m. You should be able to get it done tomorrow. Easily within your two-hour lab session. So here it is. It's five problems. The first two problems are just to give you practice on putting parentheses in the right places. So first one you're going to see the difference between 2 to the 3 quantity to the 4th and 2 to the power quantity 3 to the 4th. You should get quite different numbers as you may be able to anticipate and then you can do this fraction of fractions. You can do this with exponents, okay? And for the second one you'll get an exact representation which is going to be a ratio of a couple of integers and I want you to convert that to a numerical value with 15 places using the N command. All right, then the next thing I want you to do is define these two things, okay? So these happen to be the radius and velocity within the Bohr model of the atom for the Nth Bohr orbit where N is the principal quantum number. M is the mass of the electron. R is this here. Z is the nuclear charge which for atomic number which for hydrogen is one. This E here is not the base of the natural logarithm so here's an example where we use the same symbol for two different things. As I say here E is the electron charge in Coulombs so all this is in SI units. H is Planck's constant, pi is pi and E0 which you can type in as if you want you can have little E0 next to it to make it different from E. That's what's called the permittivity of free space and it's numerical values given here in SI units. I'm sorry? You can use whatever you want, yeah, as long as the formula is right, okay? Now what I want you to do is to define these two things and then define the values of all the constants and then there's going to be one left over that's not defined, that's N, the principal quantum number and then I want you to evaluate both of these for N equal 1 and N equal 2 so the ground state and the first excited state of the hydrogen atom, all right? So you can think a little bit about how best to plan that. Because you need R to calculate V you should define R before V, okay? And then I ask you and you can give your answer in a comment or a text box, what are the units? And my hint to you is everything's in SI units so R is a distance in SI units and V is a speed in SI units. You don't actually calculate anything there, you just think about what are the units. Okay, next thing is I want you to plot this and this on the same plot. I tell you the range of X and the only stipulation here is that the second one, X over 2 minus 1 should be using a line that's twice as thick as the first one, all right? So you can make whatever color you want, I just want to see you change the thickness. So you might want to define a certain thickness for the first one and then twice that for the second one. Okay, and then the last problem, I'm sorry, I'm eating up a minute or two of your time here. It looks complicated but it's mostly because I'm trying to explain to you what it is that you're going to be doing in case you're interested. But what this problem boils down to is that I want you to define this function and later I'll teach you how to actually put things like lambdas in there so they look nice but for now you might want to just type it out lambda as a variable name. So you're going to define this function, H's Planck's constant sees the speed of light, those are given there, K's Boltzmann's constant is given here. So define that and the constants and then you're going to define another function down here which is also a function of lambda. And I want you to plot those two on the same plot. Here's the range of lambda I want you to use. And I tell you the range of in the y-axis that I want you to use so that you can see the difference between the curves and put in a temperature of 5,800. So what this is is that this formula here is the formula Planck derived for the spectral radiance of a black body as a function of wavelength. And when you were first learning quantum mechanics and general chemistry you learned that Planck introduced the quantization of energy E equals H nu and he did that so that he could derive this formula which correctly describes the shape of the spectral radiance versus temperature. And what you're going to see is that it's going to look something like the Boltzmann distribution. It's going to be a distorted bell curve. Now the reason that was so important is because it showed that his hypothesis E equals H nu was actually consistent with experimental data on black body radiation. And this curve is the best that physicists could do before Planck came along. This was based on classical electromagnetic theory. And what you're going to see by plotting these on the same plot is that this thing is really, really wrong. If this was correct there would be no such thing as darkness. Okay? So in any case, for us though it's just an exercise in plotting two curves on the same plot and I forgot to tell you somewhere in the instructions it says you have to include a legend. Okay? All right. So good luck, enjoy and we'll see you I guess on Thursday.