[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.38,0:00:01.75,Default,,0000,0000,0000,,Hello, and welcome to the screen cast, Dialogue: 0,0:00:01.75,0:00:05.17,Default,,0000,0000,0000,,where we're gonna do a real simple example\Nof plotting a single variable function in Dialogue: 0,0:00:05.17,0:00:09.72,Default,,0000,0000,0000,,MATLAB using only an m file, using a step\Nwe would use only from the command line. Dialogue: 0,0:00:09.72,0:00:13.00,Default,,0000,0000,0000,,I'm picking this function just basically\Nby propping open my calculus book and Dialogue: 0,0:00:13.00,0:00:15.70,Default,,0000,0000,0000,,picking a random number\Nfrom the exercise sets, and Dialogue: 0,0:00:15.70,0:00:21.00,Default,,0000,0000,0000,,happened to see the function f of x\Nequals x divided by x squared plus 4. Dialogue: 0,0:00:21.00,0:00:23.90,Default,,0000,0000,0000,,I have no idea what this looks like,\Nand this is a. Dialogue: 0,0:00:23.90,0:00:27.29,Default,,0000,0000,0000,,Function from the book and the section\Non first and second derivative tests, so Dialogue: 0,0:00:27.29,0:00:29.62,Default,,0000,0000,0000,,the shape of this graph is\Nactually pretty important. Dialogue: 0,0:00:29.62,0:00:31.68,Default,,0000,0000,0000,,This is something I would do\Nif I were doing homework. Dialogue: 0,0:00:31.68,0:00:34.11,Default,,0000,0000,0000,,So let's begin with a blank M file and Dialogue: 0,0:00:34.11,0:00:40.09,Default,,0000,0000,0000,,we're gonna first define our variable x\Nequals, let's just go with linspace -5,5. Dialogue: 0,0:00:40.09,0:00:44.67,Default,,0000,0000,0000,,This turns out to be a bad choice or\Nneed different values of x, Dialogue: 0,0:00:44.67,0:00:49.81,Default,,0000,0000,0000,,I can come back and redefine x or\Nchange the axis limits later on. Dialogue: 0,0:00:49.81,0:00:56.94,Default,,0000,0000,0000,,So x put a colon there and on my function\NI said was x divided by x squared +4. Dialogue: 0,0:00:56.94,0:01:01.47,Default,,0000,0000,0000,,This is gonna give me all kinds of error\Nmessages right now because remember, Dialogue: 0,0:01:01.47,0:01:05.72,Default,,0000,0000,0000,,x is a vector and so any time I'm\Ndividing or exponentiating by a vector, Dialogue: 0,0:01:05.72,0:01:08.42,Default,,0000,0000,0000,,I need to make element-wise operations. Dialogue: 0,0:01:08.42,0:01:10.35,Default,,0000,0000,0000,,So.\Ndivided by. Dialogue: 0,0:01:10.35,0:01:12.66,Default,,0000,0000,0000,,squared, that should do it. Dialogue: 0,0:01:12.66,0:01:16.30,Default,,0000,0000,0000,,Now the basic plot I would get\Nis plot x,y, and we're going Dialogue: 0,0:01:16.30,0:01:20.91,Default,,0000,0000,0000,,to change a lot of things from here,\Nbut let's just get a basic plot going. Dialogue: 0,0:01:20.91,0:01:27.25,Default,,0000,0000,0000,,I'm going to save this to my\NMATLAB folder as a simple example. Dialogue: 0,0:01:29.68,0:01:32.53,Default,,0000,0000,0000,,And so I'll save it and when I plot it,\NI get something that looks like this. Dialogue: 0,0:01:32.53,0:01:33.89,Default,,0000,0000,0000,,Actually that's not too bad. Dialogue: 0,0:01:33.89,0:01:38.49,Default,,0000,0000,0000,,I'm kinda wondering what happens here at\Nthe ends as x increasing without bound and Dialogue: 0,0:01:38.49,0:01:40.04,Default,,0000,0000,0000,,decreases without bound. Dialogue: 0,0:01:40.04,0:01:43.27,Default,,0000,0000,0000,,Maybe there's an asyms out there, so\NI think I may make a few changes here. Dialogue: 0,0:01:43.27,0:01:47.77,Default,,0000,0000,0000,,And again, not from the plot tools\Nwindow but straight from the m file. Dialogue: 0,0:01:47.77,0:01:49.93,Default,,0000,0000,0000,,Let's change some of the style elements. Dialogue: 0,0:01:49.93,0:01:54.97,Default,,0000,0000,0000,,First of all let's make this a dotted\Nred line as a little thicker than usual. Dialogue: 0,0:01:54.97,0:01:57.05,Default,,0000,0000,0000,,That would be single quote. Dialogue: 0,0:01:58.60,0:02:02.76,Default,,0000,0000,0000,,I'm sorry a dotted red line\Nwould be a single dot redline. Dialogue: 0,0:02:02.76,0:02:06.10,Default,,0000,0000,0000,,And let's just do that much and\Nthat makes a bunch of dots, Dialogue: 0,0:02:06.10,0:02:10.64,Default,,0000,0000,0000,,now that I see it I'm not so keen on that,\NI think I'd rather have a dash line. Dialogue: 0,0:02:10.64,0:02:12.56,Default,,0000,0000,0000,,So I'm gonna go back and\Nchange this to a dash, Dialogue: 0,0:02:12.56,0:02:17.36,Default,,0000,0000,0000,,you get a dash line we have to 2\Ndashes in here in this plot option. Dialogue: 0,0:02:17.36,0:02:19.31,Default,,0000,0000,0000,,Now when I click this,\Nnow it looks pretty good. Dialogue: 0,0:02:19.31,0:02:22.67,Default,,0000,0000,0000,,I would like to make\Nthis a little thicker, so Dialogue: 0,0:02:22.67,0:02:28.13,Default,,0000,0000,0000,,I'm gonna change the line width like so\Nto let's say to 3 Yeah, Dialogue: 0,0:02:28.13,0:02:32.51,Default,,0000,0000,0000,,that's pretty nice, and I think I will\Nleave the markers alone for right now. Dialogue: 0,0:02:32.51,0:02:34.28,Default,,0000,0000,0000,,So I'm done with changing the style and Dialogue: 0,0:02:34.28,0:02:37.93,Default,,0000,0000,0000,,color of my graph right now,\NI'm not gonna add any markers. Dialogue: 0,0:02:37.93,0:02:40.90,Default,,0000,0000,0000,,Now one thing I said was looking\Nat this graph on the right here, Dialogue: 0,0:02:40.90,0:02:45.44,Default,,0000,0000,0000,,it makes me wonder if there's a horizontal\Nisotope somewhere further down the x axis. Dialogue: 0,0:02:45.44,0:02:49.69,Default,,0000,0000,0000,,One thing I can do here is if I want to\Nlook further than negative five to five, Dialogue: 0,0:02:49.69,0:02:52.95,Default,,0000,0000,0000,,I'm going to have to change my x value,\Nso let me go back and Dialogue: 0,0:02:52.95,0:02:56.75,Default,,0000,0000,0000,,change this to something\Nrelatively double that, -10,10. Dialogue: 0,0:02:56.75,0:03:00.65,Default,,0000,0000,0000,,And reclick and\Nit will automatically change that and Dialogue: 0,0:03:00.65,0:03:05.59,Default,,0000,0000,0000,,maybe I even want to go further than that,\Nlets' go -20,20. Dialogue: 0,0:03:05.59,0:03:07.68,Default,,0000,0000,0000,,I think that should be good enough. Dialogue: 0,0:03:07.68,0:03:10.31,Default,,0000,0000,0000,,We plot and that looks very nice there. Dialogue: 0,0:03:11.68,0:03:15.00,Default,,0000,0000,0000,,Now one thing I might want to\Ndo is look at the graph here. Dialogue: 0,0:03:15.00,0:03:16.88,Default,,0000,0000,0000,,I think a graph grid would be useful for\Nyou. Dialogue: 0,0:03:16.88,0:03:21.18,Default,,0000,0000,0000,,So, I'm going to type grid on and\Nevaluate that and it puts a grid on here. Dialogue: 0,0:03:23.11,0:03:26.31,Default,,0000,0000,0000,,I'm pretty happy with the placement of\Nmy tick marks and I'm pretty happy with Dialogue: 0,0:03:26.31,0:03:29.78,Default,,0000,0000,0000,,placement of my tick marks over here so\NI think I'm gonna leave those alone. Dialogue: 0,0:03:29.78,0:03:33.03,Default,,0000,0000,0000,,Although if I wanted to change them\NI would use the set command and Dialogue: 0,0:03:33.03,0:03:35.91,Default,,0000,0000,0000,,then feed a GCA for the argument. Dialogue: 0,0:03:35.91,0:03:38.01,Default,,0000,0000,0000,,And then set the x-ticks\Nto whatever I want. Dialogue: 0,0:03:39.32,0:03:44.15,Default,,0000,0000,0000,,Now one thing I will do is, I'm gonna\Nmake the vertical limits on the axis Dialogue: 0,0:03:44.15,0:03:49.15,Default,,0000,0000,0000,,a little bit taller cuz I see the peak\Nhappen right here but it's almost like Dialogue: 0,0:03:49.15,0:03:53.37,Default,,0000,0000,0000,,I would like a little more daylight\Nup above this so I can see it. Dialogue: 0,0:03:53.37,0:03:57.21,Default,,0000,0000,0000,,So, I'm gonna keep the x minimum and\Nx maximum at -20 and 20 but Dialogue: 0,0:03:57.21,0:03:59.86,Default,,0000,0000,0000,,I'm gonna change the y minimum and\Ny maximum. Dialogue: 0,0:04:00.90,0:04:06.20,Default,,0000,0000,0000,,Let's say to -0.35 instead of -0.25 and Dialogue: 0,0:04:06.20,0:04:10.14,Default,,0000,0000,0000,,+0.35 to plus from +0.25. Dialogue: 0,0:04:10.14,0:04:12.44,Default,,0000,0000,0000,,I am gonna do that by typing axis and Dialogue: 0,0:04:12.44,0:04:16.24,Default,,0000,0000,0000,,then just feed it a vector\Nthat's got my limits in it. Dialogue: 0,0:04:16.24,0:04:18.97,Default,,0000,0000,0000,,So keep (-20,20) and\N-0.35 to 0.35 for the y. Dialogue: 0,0:04:18.97,0:04:23.54,Default,,0000,0000,0000,,And again, that's just gonna give\Nme a little bit of daylight so Dialogue: 0,0:04:23.54,0:04:27.58,Default,,0000,0000,0000,,I can see those peaks\Nhappen a little bit better. Dialogue: 0,0:04:27.58,0:04:30.41,Default,,0000,0000,0000,,You've got a nice looking\Nsquare grid on here. Dialogue: 0,0:04:30.41,0:04:32.61,Default,,0000,0000,0000,,Let's move on now to titles. Dialogue: 0,0:04:32.61,0:04:38.26,Default,,0000,0000,0000,,And we don't have any context here,\Nbut I will give the xlabel, Dialogue: 0,0:04:38.26,0:04:43.00,Default,,0000,0000,0000,,and just out the letter x on the x-axis,\Nand ylabel. Dialogue: 0,0:04:43.00,0:04:46.94,Default,,0000,0000,0000,,How to split the f(x),\Nbecause that's what I'm plotting, is f(x). Dialogue: 0,0:04:46.94,0:04:48.41,Default,,0000,0000,0000,,Let me run those, there are labels. Dialogue: 0,0:04:50.05,0:04:52.42,Default,,0000,0000,0000,,Finally, let's end off\Nby giving this a title. Dialogue: 0,0:04:53.91,0:04:59.50,Default,,0000,0000,0000,,And let's put as title just\Nthe function definition, Dialogue: 0,0:04:59.50,0:05:03.64,Default,,0000,0000,0000,,f(x) = X divided by x squared plus 4. Dialogue: 0,0:05:03.64,0:05:09.01,Default,,0000,0000,0000,,And when I do that,\Nthere's my function up here. Dialogue: 0,0:05:09.01,0:05:12.48,Default,,0000,0000,0000,,So that's a very simple example of\Nstarting with a mathematical function, Dialogue: 0,0:05:12.48,0:05:16.18,Default,,0000,0000,0000,,plotting it, and making a few changes to\Nmake it nice and attractive, thanks for Dialogue: 0,0:05:16.18,0:05:16.74,Default,,0000,0000,0000,,watching.