 Hello everybody. So the last time we met, we very quickly got a taste, a glimpse of the command that we use in Mathematica to plot functions of two variables and produce three-dimensional surfaces. So today I'm going to spend more or less the whole discussion period showing you various ways that you can manipulate and add important functionality to your three-dimensional plots, okay? And we're going to use the same function at the start as we did last time and that function is going to be the wave function for a two-dimensional particle in a box. And so here's what it looks like. It's a function of x and y and then there's some indices and these are the quantum numbers that indicate which state the motion in x and y are in. And so this function looks like this. Sine nx pi x over l and then sine ny pi y over l. Okay, we're going to set, just makes it a little easier. We'll just set l equal 1 in both so that it's a square box with l equal 1. Okay, so let's go ahead and type that in and then we'll start playing around with the three-dimensional plots. So psi of x and y, so we need underscores, defining a function and then colon equals 2 times sine nx star pi star x. I'll leave out the l since it's 1 and then times sine ny times pi times y. All right, so there's our function and now what I'm going to do is plot that function. So plot 3D is the name of the command and then I'm going to say psi of x and y. And now what I'm going to do is I'm actually going to use replacement rules to specify the quantum numbers nx and ny. So we'll have an easy way to modify them. And so for replacement rule I say slash dot and then since I'm going to have 2 at once I'm going to put them in the curly brackets, a list. So I'm going to say nx arrow 1 and then ny arrow 1. Okay, so that will plot the ground state wave function and then I have to put in my ranges of x and y and so I'll say x goes from 0 to 1 and y goes from 0 to 1. Okay, so now we can enter that and you see we get a plot. Now, what do I want to say? There's lots of things to say about this. So first of all in these 3D plots it may not be especially because the ranges are the same here for both dimensions. It's not obvious what the x and y axes are. Okay, it's pretty obvious that the vertical one is the function axis. So let's go ahead and put some axes labels on there and the way we do that is the same way as in the plot command. So we say axes, label, arrow and now we can put in 3 labels. So I'll say x and y and psi. Okay, so go ahead and let that rip and now we see that the x axis is the one closest to us and then y is over there. Now I wanted to use this as an opportunity to tell you that I know a lot of you open up the notes which I think is great and you look at them while we're doing things in the class. But I also know that some of you fall behind because you're typing everything that's in the notes and I often am doing shortcuts here. I'm not typing all the details. Those are there for you to see more details but often times while we're working together in the lecture or the discussion I don't type everything that's there. Another thing is that this is not a super complicated plot command but I think it's always a very good idea when you're entering commands in Mathematica to start with the simplest version of that command that's going to give you an opportunity to check and see if you have it right. And then add options because sometimes you type in a very complicated long command. You're missing a comma or have the wrong kind of bracket or there's just something small wrong. It's hard to see when you have a huge long command. So for example in this one I generated the plot and then I added the axis and then we'll be adding more options as time goes on. As soon as I generated the plot I knew that I had the basic plot was okay. Okay now let's play around with this a little bit. The nice thing about having this particle in box wave function typed in now is that we can actually explore some of its properties. So this is the ground state. Suppose I wanted to find out what's the probability of finding the particle in the box when it's in the ground state. What does that probability distribution look like? Well those of you who are in Chem 131A now know that Max Born told us that the proper way to interpret the wave function is that if you square it that gives you the probability density of finding the particle. Alright so we could square this guy here. Let's mouse that in and actually we don't need the definition of psi. We already have that and so we could just very simply change psi to psi squared and if we re-enter that it's not too surprising that the probability density looks a lot like the function itself. Okay because this function is positive everywhere so is the probability density. Alright but what happens if we change the quantum state? So if I go up here for example and I put in instead of the ground state 1, 1 I put in let's say 2, 3. So we'll have 2 quanta in the x direction and 3 in the y and then you see that you have a more interesting looking function where in the x direction now we have a complete cycle of design and in the y direction we have one and a half there. Okay so you can kind of see what adding more energy in these degrees of freedom does. It produces more oscillations in the wave function. Okay so if we go down here now and look at the probability for the same one notice here the amplitude goes plus and minus when we square the probability square the wave function to get the probability we'll get a positive everywhere function where now we can see that there's an interesting nodal structure. So for example the particle will not be able to be anywhere in here along the x-axis in the middle of the box and then there's two nodes in the y direction. Okay so this quantum particle is if you like enhanced at certain regions of the box but and forbidden from being other places in the box and having the ability to look at the wave function using a simple plotting command in Mathematica helps us to appreciate the quantum behavior of this of this particle. Okay now actually if we wanted to be a little more accurate here in our labels which we could say a prob dense or something like that that's the square of the wave function. Okay now a few other things to point out so one is that by default when you make a three-dimensional plot a certain coloring scheme is used that coloring scheme is called lake colors and it's a fairly attractive one in my opinion. We'll see how to change that in a moment and I encourage you all to use your favorite color schemes. There's a lot of really nice ones. Another thing is is that the default is to put a grid on the function the grid is kind of useful to help you to be able to follow the behavior of the function. We'll see that you can modify that and get rid of it all together if you wish and then another thing I want to point out is that Mathematica decides based on the behavior of the of the function as it's calculating it so it evaluates that function and draws it. It decides you know how well actually yeah it decides how coarse or fine to evaluate the function as it's making the plot. Now this particular representation is pretty nice this is a fairly oscillatory function and you can see if you look on the places where it's turning around where it's kind of sharp it does a reasonably good job of catching that shape very accurately but if for some reason you want to make it either more or less resolved this is something that you have control over okay so I'll show you how to manipulate the coarseness or fineness of the of the plot. So the default is I believe to use 17 17 points along each dimension to draw the function. Now if you wanted for some reason if you had a very complicated function and you wanted it to be displayed relatively quickly so you can see if it looks right you could actually decrease the resolution by changing the grid and so the command to do that it's an option it's called plot points and you put arrow and then you say how many points you want to use along each direction okay so for example if I put 10 what that's going to do is that's actually going to decrease the resolution of the display here because I'm using less points to represent the function. Alright so you can kind of see that it's a little it's got a little more of a sort of roughness to it and you can also see that there the grid lines have been changed suppose you wanted to make a finer version of the plot well then you can increase the plot points and so for example if I change to 40 see it takes a little longer but now I think you can see that this function is plotted very very smoothly compared to when we only had 10 points. Okay so what about now the mesh suppose you wanted to make the mesh finer as well well there is another option which is called mesh with an arrow okay and this gives you the number of lines that are drawn in each direction okay so we put mesh equal 40 and now you see we have a much finer mesh and that may be something that you want to add to your plot. Now this particular function just the way it's colored it actually looks pretty good and you don't need a mesh to really see quite well what the behavior of the function is you may want to actually get rid of the mesh and the way you can do that is just turn it off by saying mesh goes to none. Okay so if you do that now you see you've got the surface drawn and colored nicely but there's no mesh drawn. Alright now I mentioned that you have control over the coloring schemes so I'm going to go ahead and get rid of this plot points we'll go back to the default and then we'll play around with the colors okay so just re-enter that you see now it's a little rougher. Alright so to to see what kind of colors you have available to you you can go to the documentation center and if you type in color schemes the first thing that come up there is a guide on the various color schemes and so what you have down here now is a list of all the predefined color schemes and some of them are very attractive some not so much and basically the way these will be used is if you change to one of these color schemes the lowest value of the plot will be plotted with whatever the color is on the left end of the bar and the highest at the right end okay so for example suppose I go back to this plot and I'll go ahead and put the mesh back in by removing that option I could change the color scheme from the default which is the lake colors by adding the option color function and then an arrow and then I give the name of the scheme that I want so for example maybe I want to use mint colors see what that looks like so I type in mint colors and see what we get that's kind of nice what else how about fuchsia tones oops I guess I misspelled it where is it off fuchsia okay I have this that's in the wrong spot all right there you go so that's kind of nice a little more noirish anyway the point here is that there's lots of really nice color schemes here and you could waste a lot of time checking them all out and finding the ones that appeal most to your aesthetic sensibilities in general I will I will not micro manage you on this and I encourage you to play around and make your plots look nice by choosing a color scheme that you like the default is always fine okay all right so let's see another one that's I'll just point out one more that's nice remember that it's it's occasionally useful to be able to do black and white plots and so there is a version of the color scheme that is appropriate for black and white it's called gray tones and so now you can see that the lowest value of the function is plotted with the darkest black and then there's a gradation toward white okay now there's other things that you can do I'm just in fact there are many many things that you can do so you notice the surface is kind of drawn like matte it's you know you can kind of see that there's a light shining on it to give you some good depth perception but the actual surface itself is kind of a not it's not shiny right looks kind of like a matte photograph you can actually change the surface characteristics and so I'll just show you one example this will be kind of nice when we're displaying orbitals which we'll do probably next time so let's let's see how we can make a couple of different kinds of surfaces so the first thing I want to show you is let's let's make the surface more see through okay so what I'm going to do I'm actually going to use the the wave function itself for this all right so we put this back and I'm just going to re-enter it okay now notice that the orientation is pretty nice you can tell that there's a hump here and that there's a valley behind it all right but the valley is somewhat obscured by the fact that this surface here is you can't see through it right it's opaque all right so you may want to reduce the opacity so that it you can see through it partly maybe that will be important for depicting whatever it is that you're trying to depict with the surface all right so there is an option here called opacity and sorry it's plot style goes to opacity plot style arrow opacity and then within square brackets you put a number so let's put to start 0.5 this number is between 0 and 1 okay so now notice the surface is see through okay and maybe it's even more confusing now but in any case we've made it see through so to get a feeling for what opacity is let's let's crank it up a little bit let's say 0.8 you can see that the larger the number of opacity the more opaque the surface becomes and if you go to really small values it becomes practically transparent completely transparent all right so that's something you could play with if you want to be able to see through your surface all right now what if you want to take it to the other extreme and make a surface that you can't see through so if I copy that I'm going to get rid of this one and for this version I'm going to get rid of the mesh mesh goes to none and then I'm going to change the characteristics of the surface in a couple of different ways okay so the first and the way I'm going to enclose these couple of different ways and this is a strange syntax so if you ever want to do it just look to the example and play around with the options I'm going to use what's called a directive and within this directive I can change things more than one thing at a time so the first thing I can specify if I want is the color so I'm going to put in pink and then the next thing I'm going to specify is a quantity called specularity and roughly speaking this is this is a measure of the shininess of the surface okay and so what I can put in specularity are a couple of options one of which is the light color all right it's going to be white light and then the second is a number which basically indicates the shininess okay and this number its default is around one I think it's one and a half and the higher the number you put in the more shiny it is so I'm going to start with a big number 100 okay and so now let's see we need one more bracket and then let's see what happens if we enter that so now notice you get what looks to be a nice solid surface and you can really see where the light is hitting it by where you have the reflections and you can change the specularity to get a feeling for what it's like so suppose we reduce it now to 10 you see the the appearance of the light on the surface is kind of spread out it's not as it doesn't look as sharply focused and if you go back to say one point five which is the default it's not eleven point five you get a very kind of washed out looking object so if you crank it up you get this really nice feeling of a solid surface with a bright light hitting it in very tightly focused areas all right now another thing that you may want to do is you may want to change what's called the point of view okay so notice that every time we we do a three-dimensional plot we're always sort of looking at it with the axes oriented in a particular way and that what that means is that we're out here looking at the surface at a particular set of coordinates and I don't remember what the default value is for the coordinates but I do know that you can play around with that and change it and the way you do that is you actually put in the set of coordinates for the observer so for example the way you do that is you say view point and then you put an arrow and then you need to give your x y and z coordinates so if I say x 2 y 2 and z 1 you can see that now I'm basically looking along the the bisector of the x y axis and I'm a little bit elevated off the surface which it's zero here all right and you can you can modify that and see what it does so I could put say two to four here now I'm more looking at it more at the top and you can change these guys here and see what they do okay so those are all possibilities for making your surface more informative you could also of course use the left mouse to play around with it by hand you don't need to just set the view point right okay now so as I've mentioned already there are many many many things that you can play around with and we've hardly scratched the surface here so if you have any interest in finding other interesting features that you may wish to add to your 3d plots you should consult the documentation center now the next thing that I want to do is to introduce you to another way of depicting three-dimensional functions and that's through what is called a contour plot okay and so what is a contour plot does anybody know what a contour plot is has anybody seen a topographical map a topographical map is an example of a contour plot essentially what it is is it's it's defined in terms of sets of numbers that define lines or lines of constant values of the function okay so one contour in a three-dimensional function would have the form f of x and y is equal to a number a constant another contour would have f of x y equal to a different constant so by drawing a series of these so-called level sets once you get used to looking at these plots and most of you probably have used topographical map so you know how that works then it's a it's another informative way of being able to see the features present in a three-dimensional surface alright so I'm going to introduce that to you now and we'll go ahead and go back to our simple plot here and then I'm going to replace plot 3d and I'm also going to get rid of the z because what we're going to see here is that it's a two-dimensional representation of a three-dimensional plot okay so the name of the command is contour plot okay so if we enter this now you see we have a different representation of our function you can see if you're familiar with contour plots you can see that obviously it has peaks and valleys so typically the way the coloring's done this is the late color scheme the default scheme is that the lightest color in the late colors will be the smallest values or in this case most negative values and then the darkest colors are the most positive values so you can see here we have a hole a peak and a hole and we can see that we have nodes in between each of these features alright so this is another way of depicting the behavior of that function this time in terms of its level sets which are drawn here with lines around them okay now as with many things in Mathematica there's a certain default number for how many of these contour lines are drawn and that's something that you have control over as well as the style with which the contours are drawn so suppose we wanted a little more resolution then we can increase the number of contours alright and I'm not sure what the default is but it may also be something like 11 but in case you can change it so you say contours arrow and then you put in the number that you want okay so if I wanted to increase that I could put in say 20 and now you see there's a lot more contours drawn here that's the number of contours between the highest and the lowest values of the function suppose you wanted to make the lines dashed lines then you can add an option contour style arrow dashed and so now you can see that you have dashed lines alright now another thing we can do which is sometimes useful because notice we don't have a z-axis so it's not obvious here what we're plotting and also notice that when I have the axis label option in this command I don't get any axis label well the reason for that is because this type of plot is is similar to what we saw when we did plotting two-dimensional functions it's considered to be a framed plot and it seems strange maybe but if you have a framed plot and you want to put in labels you have to use a different option so axis label doesn't work what you have to put in is frame label okay and so if you do that now you see you have X and Y labels on your axes okay now another thing we don't have the Z as I said so if we want to say what it is we're plotting we may wish to to include a title of our plot okay so the way you do that is you put in the option plot label arrow and then the string your title so I might say 2D particle in a box wave function alright so now I have a an informative title to my plot okay now another thing about contour plots is because we don't have the Z axis explicitly shown for us we don't really have an accurate indication of what are the values okay we can see that the most negative values are drawn white and then as they become more and more positive they get more and more color and then the positive features start out sort of in the middle of the spectrum and become darker and darker blue as we go up in positive values but we don't really know how the color variation is mapped on to the values of the function and so in contour plots it's especially useful to add a legend alright and the legend for contour plots is a bit more complicated than that for an XY plot and I'm going to show you how to do it and to show you a couple of things that you can change in the legend but it's a very non-intuitive command and so this is a very good example of a case where having an example sitting in front of you is the best way to actually get it right okay so another thing I want to remind you of is that when we want to put in a legend to our plots we need to load a package because legends are not part of the default machinery that's loaded in when we fire up Mathematica alright so let's go ahead and do that so we say less than less than and then the name of the package plot legends and then backward single quote and then we can enter that and we can have a look to see if we got it dollar packages and now we see that in fact we have plot legends loaded in okay now when we were doing the two-dimensional plots it was pretty easy to add a legend we just added an option within the plot command for contour plots it's substantially more complicated so the first thing that we have to do is we're going to use the legend in a different way it's we're going to include in our plot command or what I call a wrapper so this is a command that's going to be wrapped around the plot command sort of like animate what we did last time and the command is called show legend okay and then we're going to put something inside so inside this is going to be the command specifying the plot that we want the legend for okay so I'm just going to go up here and grab this guy and I'll go ahead and just use the plain old default here with some labels for the axes so grab that put it in down here and then I'm going to put a bracket at the end okay so you see the show legend is wrapped around the contour plot all right now we're not done not even close so one thing we need to specify is the color scheme that's going to be used for the legend and I think it goes without saying the color scheme should be the same as the scheme that you're making the plot okay so the default color scheme is called lake colors all right so what I'm going to do to specify that is put in this curly bracket with a specification color data and then within that the name of the color scheme so it's lake colors okay and bracket and now there's a very funny construction that's basically just instructing Mathematica how to draw the graphics object that's going to ultimately be our legend okay and I won't say much more about it except that you have to put it in as I'm doing it now or your legend will be screwed up okay so there's a funny little thing that's got a square bracket and then one minus pound sign one and then a square bracket and then a space ampersand all right just remember you can always look at an example and you should type it just like this okay now the next thing we do is we put in how many different slabs do we want to represent in our legend and this will be obvious once we do it I'll show you what this number means so I'm going to put in 11 so this means my legend is going to have 11 different colors spanning the range of the function okay and then I put in the upper and the lower limits of my function so here you need to know something about your function and you may recall when we plotted the 3d plots we can see that our function goes between minus two and two okay so I'm going to put those limits in now and they're in quotes because they're going to be used as labels on the legend let's start with two that's the maximum value and minus two okay all right now we should be good to go let's hit enter and we see that something's wrong I missed a curly bracket did I where should have I put that I should put that here thank you all right okay so now you see you have a legend okay and notice a couple of things oh sorry I was saying something wrong before the lightest colors are actually the most positive okay sorry about that that's right because the sine wave goes like that okay well now we can see right shows you legends are important because I was guessing incorrectly the values of the function now I know for sure all right the lightest colors are the most positive and then they go to the darkest colors most negative all right now the other thing is what's the 11 okay the 11 is the number of different colors I have here so if you wanted you could change that you can say put it to five or something okay and now you see you only have five okay now a couple of other things this is a really inconvenient spot for the legend right this happens in general we saw this already with the two-dimensional plots so let's move it so we can now add within our wrapper the legend position arrow and I played around with this one and found that 1.1 and minus 0.4 looked good to me so that's what I'm gonna put in whoops we don't need a quotes here I don't know why I have that quote all right and so now if we re-enter nothing happened hmm oh the problem is this is outside the curly bracket sorry about that so control X and put it in here control V all right now it should work and there you have it okay so that's a much nicer place for the legend now what else about the legend well suppose you want to get rid of the shadow you can say with another option inside the curly bracket here legend shadow arrow none which I prefer personally that's now you see the shadow is gone okay what else another thing is you may want to change the size of the legend all right so let's go back to 11 here and enter that notice the legends now maybe a little too small for your taste well if you want to crank up the size you can say legend size arrow let's say 1.5 now you see it draws it bigger and in this case then you may want to change the position a little bit say to minus 0.6 or something in the y direction so it's more centered okay so now we have a rather nice looking plot suppose you want to change the color scheme all right so I'm gonna change it to something I'm gonna call fruit punch colors one of my favorites so now what we have to do is we go back within our plot command here see it ends here and we add a option to the plot all right so we say color data bracket and then put in the name so I'm gonna say fruit punch colors okay and let's go ahead and enter that one oops wow oh the problem is it doesn't need the brackets sorry I'm getting all confused with my complicated color data is for the the legend what we need to do is say color function goes to sorry all right all right now if you do that notice you got a nice different color scheme for the plot but you have to also remember to make your legend consistent with the plot all right so we have to put in fruit punch colors in both places to make them consistent all right and so now if you do that you have a lovely looking plot with the slightly more let's say bold color scheme okay all right now I'm going to finish up just in the last minute or two here with a variation on the contour plot which is actually quite nice for plotting functions of the sort that we're plotting here and this type of plot is called a density plot and I think the best way to see how that works is just to make one so if I go in here and change contour to density and enter it notice I get this kind of fuzzed up version of a contour plot okay it's exactly the same function same information we have you know the same legend but you notice there's there's a subtle difference here right I mean that it doesn't have these sort of pretty obvious demarcations it's it's kind of fuzzed out and this is a particularly nice way of drawing functions that represent quantum objects because as we learned very early on when we're learning about quantum mechanics is that you know that you don't talk about where a particle is with with great precision because of the uncertainty principle and so often we're looking at things like probability densities or the amplitude of a wave function and it's kind of a nice way to help you to remember that about this uncertainty if you have a plot like this which kind of gives you this fuzzy quantum particle look to it okay so that's the density plot very very similar in all respects to the contour plot except without the demarcations let's just go back to contour so you can see the subtle difference okay so notice we have these lines if you get you could get rid of the lines by saying contours arrow none whoops what was that command contour style contour style okay but still you see you have this sort of each contours drawn in a different color whereas in the density plot there's sort of a smoother variation between the colors have to get rid of this guy now okay so that's another way to do more or less the same thing but in a slightly different way that for a problem like this might actually be more appealing okay so that wraps it up for today what we're going to do next time is we're going to see how to plot four-dimensional functions okay so something to look forward to see you tomorrow