0:00:00.110,0:00:05.520 Hi guys, I'm gonna give you a quick[br]crash course tutorial on MathLab for 0:00:05.520,0:00:08.070 first timers or[br]approximately first timers. 0:00:08.070,0:00:11.680 When you first open MathLab you're[br]gonna see stuff like these, 0:00:11.680,0:00:14.150 get rid of these as soon as you can,[br]that's just getting in the way. 0:00:14.150,0:00:18.050 You can still use them, they're[br]still there, you just have to hover. 0:00:19.940,0:00:21.820 This is the command window. 0:00:21.820,0:00:23.790 You can use it like a calculator. 0:00:23.790,0:00:27.420 Do all of your code immediately,[br]and get response back. 0:00:27.420,0:00:31.950 I like to open up a script, and open[br]up the editor so I can write a script. 0:00:31.950,0:00:33.220 And it's really clean in here. 0:00:33.220,0:00:37.090 And then you can evaluate,[br]over in the command line. 0:00:37.090,0:00:38.540 Notice, they're right next to each other. 0:00:38.540,0:00:39.890 You can see. 0:00:39.890,0:00:42.830 All the code heightwise. 0:00:42.830,0:00:45.680 You can actually do this as well,[br]minimize the tool strip if you wanted to. 0:00:45.680,0:00:54.410 I've already got a file here[br]that we're gonna run through. 0:00:55.760,0:00:58.370 And then go through all of[br]this as quickly as possible. 0:00:58.370,0:01:00.680 So just pause, rewind if you have to. 0:01:02.790,0:01:06.410 When you start evaluating code in[br]the editor, you can set these break points 0:01:06.410,0:01:12.228 here to evaluate up to that point,[br]and then you can continue stepping. 0:01:12.228,0:01:18.990 You can also set modify condition,[br]so this is a Boolean condition here. 0:01:23.210,0:01:25.850 So to run, I like to use hotkeys. 0:01:25.850,0:01:27.650 This is function F5, to run. 0:01:29.140,0:01:32.810 Or you can just use one of the arrows,[br]up here, when there's a run arrow. 0:01:34.120,0:01:37.810 Anyway, so[br]now that it's running in debug mode, 0:01:37.810,0:01:42.190 I can continue stepping by clicking[br]this or just use the hotkey. 0:01:44.250,0:01:51.370 So this first line, I stored a row vector, 0:01:51.370,0:01:54.860 an array in a row into x1. 0:01:56.020,0:01:57.940 And it goes from minus 2 pi to 2 pi. 0:01:57.940,0:02:01.330 Or at least it's supposed to[br]go from minus 2 pi to 2 pi. 0:02:01.330,0:02:04.480 It defaults,[br]when it's just one colon there, 0:02:04.480,0:02:07.140 it defaults to integer value increment. 0:02:08.350,0:02:11.640 So you see over here it went[br]from -2 pi but it didn't quite 0:02:11.640,0:02:16.290 hit positive 2 pi because[br]the incrementation didn't allow it. 0:02:17.670,0:02:22.355 So the next line here allows[br]it to do that because I 0:02:22.355,0:02:27.480 enforced the conditions that it[br]reaches a total range of 4 pi. 0:02:28.660,0:02:34.320 And it reaches that over 13 increments,[br]so there was a total of 14 points. 0:02:35.530,0:02:39.000 And if you look at here, X2,[br]it goes from minus 2 pi to 2 pi. 0:02:40.230,0:02:44.870 And he's our way to do this without[br]having to think about how to increment, 0:02:44.870,0:02:47.180 is just to use the linspace command. 0:02:48.610,0:02:51.400 And you just tell it how[br]many points you want. 0:02:51.400,0:02:55.560 This one, in this case, it's 14 points[br]that it's identical to this, x2 and 0:02:55.560,0:02:59.797 x3 are identical, if you look over here,[br]they're identical. 0:03:02.198,0:03:04.210 Just easier to use lens space sometimes. 0:03:05.690,0:03:07.050 There's also log space. 0:03:09.210,0:03:12.930 I created lens space again,[br]and using these for later. 0:03:12.930,0:03:15.430 100 points for log spacing. 0:03:16.480,0:03:23.190 This log space gives me ten to[br]the zero to ten to the six. 0:03:23.190,0:03:27.760 So it goes from one to a million[br]over a hundred points. 0:03:31.120,0:03:35.109 So if you see, you look over here, 0:03:35.109,0:03:38.961 this is the very largest number, 0:03:38.961,0:03:45.025 it's a 1 times 10 to the sixth,[br]it's a million. 0:03:45.025,0:03:46.929 Here's a matrix. 0:03:46.929,0:03:51.171 It's a this is the first row,[br]second row, and they're separated, 0:03:51.171,0:03:53.380 rows are separated by a semi colon. 0:03:54.490,0:03:57.210 This a row vector B,[br]this is a column vector C. 0:03:59.370,0:04:02.310 The same values just one is[br]a transpose of the other. 0:04:03.570,0:04:10.000 It was three by four matrix of zeros,[br]three rows, four columns. 0:04:12.160,0:04:15.390 Matrix of ones,[br]three by three identity matrix. 0:04:17.050,0:04:24.310 Now, when we started[br]doing matrix operations, 0:04:24.310,0:04:29.720 let's take a look at how to solve this,[br]A times Y is equal to B. 0:04:31.130,0:04:35.210 If we know A and we know B,[br]how do we solve for Y? 0:04:37.460,0:04:42.980 So we invert A, so[br]I'm gonna grab this and put it down here. 0:04:44.230,0:04:47.620 This operator says,[br]invert A and operate on B. 0:04:48.670,0:04:52.620 This is going to give me an error because[br]the matrix dimensions must agree, 0:04:52.620,0:04:59.380 which means MathLab doesn't know how[br]to operate a matrix on a row vector. 0:05:00.720,0:05:05.509 So this row vector for the least, 0:05:05.509,0:05:10.040 the less obscure mathematical operation,[br]which is just matrix 0:05:10.040,0:05:13.130 multiplication that has to be a column[br]vector, it has to be a column vector. 0:05:14.140,0:05:18.660 There's also a way to do a row[br]vector here but it's a more 0:05:18.660,0:05:23.025 obscure operation,[br]out of product of some sort. 0:05:23.025,0:05:26.660 MathLab doesn't know how to[br]do it unless you massage it. 0:05:28.840,0:05:33.680 So you come over here and you put this[br]transpose operator, this tick mark, and 0:05:33.680,0:05:36.200 that'll allow it to do[br]the correct operation. 0:05:37.390,0:05:39.340 So that gives me a solution. 0:05:39.340,0:05:43.119 My solution Y for this linear system. 0:05:44.410,0:05:48.510 And then YY is gonna be the same thing[br]because C is already the transpose of B. 0:05:48.510,0:05:52.625 [COUGH][br]This is to check to make sure that I get 0:05:52.625,0:05:55.190 B back, so there's B back. 0:05:57.050,0:05:59.130 When I got my solution Y. 0:06:00.790,0:06:06.400 Now here if I have an array of[br]input values into this function, 0:06:06.400,0:06:10.050 then this function automatically[br]loops through all those values, so 0:06:10.050,0:06:12.000 you don't have to write[br]your own four loop. 0:06:14.362,0:06:18.530 So that's the output here is the sign[br]of every one of those individually. 0:06:18.530,0:06:23.526 Now I'm gonna use these down below here. 0:06:23.526,0:06:28.580 So this dot here 0:06:28.580,0:06:33.020 doesn't mean dot product it means[br]element wise multiplication or 0:06:33.020,0:06:38.500 in this case element wise multiplication,[br]down here it's element wise division. 0:06:39.790,0:06:45.560 So it just takes the first element here[br]multiply it with the first element here. 0:06:45.560,0:06:49.485 Second element here, multiply it by[br]the second element here, and so forth. 0:06:49.485,0:06:52.620 And stores it in W. 0:06:52.620,0:06:56.820 So if you look at the size of w, compare[br]it with the size of either Y1 or Y2, 0:06:56.820,0:07:00.990 it doesn't matter,[br]they're both the same size. 0:07:00.990,0:07:03.339 And size returns all dimensions. 0:07:04.610,0:07:08.440 As compared to length which I[br]have suppressed the output so 0:07:08.440,0:07:09.760 I have to actually bring it over. 0:07:11.790,0:07:16.720 Let's say for example, length of B,[br]B if you look up here, 0:07:16.720,0:07:21.970 B is 3 by 4 and C is 4 by 3. 0:07:21.970,0:07:26.100 So the length of either of these 0:07:26.100,0:07:29.610 is the same because length[br]finds the longest dimension. 0:07:31.980,0:07:36.600 So going into the plotting, 0:07:38.550,0:07:43.440 you can just call up the plot function and[br]it brings up a figure. 0:07:43.440,0:07:48.150 Applies to that figure, you can come in[br]here and insert labels, title, legend and 0:07:48.150,0:07:50.895 all the stuff right here[br]if you wanted to but 0:07:50.895,0:07:55.440 I suggest since we're gonna be coding[br]a lot just get used to writing your code 0:07:55.440,0:07:58.520 to do everything for[br]you at least as much as possible. 0:07:58.520,0:08:02.120 So there we added a title to it,[br]we added a label. 0:08:02.120,0:08:05.740 Now if I wanna add another[br]plot to the same figure 0:08:05.740,0:08:07.193 I have to hold on to the figure. 0:08:07.193,0:08:12.560 [COUGH] So then I can throw in another[br]plot under that same set of axis, 0:08:12.560,0:08:14.550 let go the figure. 0:08:15.850,0:08:20.720 Just because I've let go of it,[br]you might assume that you can now 0:08:20.720,0:08:25.430 start another plot and it'll create a new[br]figure for that plot, but it doesn't. 0:08:25.430,0:08:28.450 It overwrites on top of this,[br]it writes to the same figure. 0:08:30.540,0:08:35.570 So that's an obvious problem,[br]the way to get over that is by explicitly 0:08:35.570,0:08:40.740 calling the figure,[br]this is just a quirkyness with MathLab, 0:08:40.740,0:08:43.710 there's probably a way around it,[br]I just, I'm not aware of it. 0:08:43.710,0:08:47.740 So create a whole new figure,[br]and then plot to that. 0:08:49.730,0:08:51.670 So it's the same thing with subplot. 0:08:51.670,0:08:55.610 If I just start subplotting, it's gonna[br]write over the top of this figure. 0:08:56.890,0:09:04.280 Then it's gonna create a subplot axis or[br]set of axis and 0:09:04.280,0:09:09.500 then it's gonna plot to that set of axis[br]and it's gonna tie it all to that axis. 0:09:10.800,0:09:15.660 Now this X label, notice how I've[br]done this, it's a carrot for 0:09:15.660,0:09:19.840 a super script and[br]then an underscore for a subscript. 0:09:21.582,0:09:26.760 And the curly braces are if you have[br]multiple characters that you need to 0:09:26.760,0:09:30.941 include in the scripts,[br]in the subscripts, super script. 0:09:30.941,0:09:37.440 So then the subplot it says[br]make me a 2 by 1 region 0:09:38.470,0:09:42.580 and here is populate in[br]the first region and 0:09:42.580,0:09:46.340 now it's populating in the second region,[br]these plots. 0:09:48.200,0:09:53.000 So there's the second region of the plot,[br]title, label, okay? 0:09:53.000,0:09:56.379 So if I continue going now since[br]I have called figure again, 0:09:56.379,0:10:01.260 this is going to override this and that's[br]fine because I'm done looking at all this. 0:10:03.316,0:10:07.406 Well okay, so notice that it[br]didn't override the whole thing, 0:10:07.406,0:10:09.840 it just overwrites the current axis. 0:10:11.420,0:10:12.700 So this is an exponential. 0:10:14.030,0:10:17.640 We have a linear set of[br]points on the input and 0:10:17.640,0:10:19.480 then we have the exponential[br]set of the output. 0:10:21.370,0:10:24.620 I want to get rid of,[br]I want to look at this on, 0:10:24.620,0:10:28.800 let's call our new figure, whoops. 0:10:31.430,0:10:36.610 So now I can look at both of these[br]if I choose to at the same time. 0:10:38.420,0:10:39.390 So notice how I have. 0:10:41.290,0:10:43.950 Just gone from plot to send their log Y. 0:10:43.950,0:10:48.828 So it suppress the exponential[br]growth in the Y direction by scaling 0:10:48.828,0:10:50.490 it logarithmically. 0:10:52.159,0:10:58.172 Now, if I give inputs that[br]are growing exponential and 0:10:58.172,0:11:04.590 then the output is exponential[br]of the exponential input. 0:11:06.230,0:11:08.700 It wants to be a double[br]exponential growth. 0:11:09.710,0:11:10.920 So let's see what that looks like. 0:11:12.380,0:11:19.030 Well, the problem here, you won't be[br]able to see it, unless we plot it. 0:11:25.853,0:11:30.902 That's a straight line,[br]notice the X-axis here 0:11:30.902,0:11:37.400 doesn't come any where near[br]the largest X values of X log. 0:11:37.400,0:11:41.170 Remember this is,[br]one million is the largest value. 0:11:41.170,0:11:45.710 So what's happened is it's gone to[br]the maximum that this can possibly go to, 0:11:45.710,0:11:46.640 on the Y value. 0:11:46.640,0:11:50.500 That's the maximum it can go to, before it[br]thinks that all the numbers are infinity. 0:11:51.730,0:11:55.890 So this actually goes infinitely higher,[br]and this goes much further to the right. 0:11:55.890,0:12:00.070 So this is a totally garbage,[br]a total garbage plot here. 0:12:00.070,0:12:01.060 It doesn't, it's meaningless. 0:12:02.400,0:12:07.480 So I'm gonna rescale, I'm gonna create 0:12:07.480,0:12:12.820 X log small enough that it'll[br]actually plot those values. 0:12:15.844,0:12:20.570 So now you can see,[br]I should probably get rid of these dots. 0:12:22.450,0:12:26.230 Let's replot this new set of points. 0:12:26.230,0:12:28.380 Just a default solid line. 0:12:29.490,0:12:33.530 So this is,[br]this actually is the exponential growth 0:12:35.420,0:12:39.240 of the inputs and it goes over all[br]possible values of the inputs. 0:12:40.860,0:12:45.540 So that's still not very[br]appealing to look at so 0:12:45.540,0:12:51.020 let's create a new figure and[br]suppress the logarithmic or 0:12:51.020,0:12:54.654 the exponential growth in the X-axis now. 0:12:54.654,0:13:00.029 So we we semi log X and[br]notice that I don't have 0:13:00.029,0:13:05.840 to repause a million times,[br]but let's do this. 0:13:11.288,0:13:16.528 So it is an exponential growth, it's[br]doubled the exponential because the input 0:13:16.528,0:13:22.090 is, the inputs are growing exponentially[br]and the output is growing exponentially. 0:13:23.580,0:13:28.290 It's tough to see it's exponential because[br]there, it's doubled the exponential. 0:13:28.290,0:13:32.300 So if you have a doubly[br]exponential growth, 0:13:33.830,0:13:36.810 the input and the output then do log log. 0:13:39.702,0:13:42.090 And that shows you[br]the exponential characteristic. 0:13:42.090,0:13:47.010 All right, that's about it for this video. 0:13:47.010,0:13:48.830 The next one will go into more depth.