© Distribution of this video is restricted by its owner
00:01 | so, mm hmm. What I I should do. Mhm Start a |
|
|
00:10 | bit all over so the outline of doesn't want to do as the following |
|
|
00:17 | I said, so we'll see how interact with them kind of training users |
|
|
00:26 | virtually Alright. So these are some the aspects of that time that will |
|
|
00:34 | covered today and that was than the coming assignments for the class. Mhm |
|
|
00:44 | that stands for Matrix lab and it originally created by Professor Clean moller when |
|
|
00:55 | was faculty in New Mexico University in university, New Mexico maybe it is |
|
|
01:03 | Albuquerque and he also worked a lot the national Tv labs, particularly those |
|
|
01:11 | and Oregon mhm And the uh tools created um got picked up by quite |
|
|
01:26 | few in the academic world to use teaching numerical analysis to simplify kind of |
|
|
01:38 | assignment by having it effectively both the and associated um support functions and the |
|
|
01:48 | emphasis would be on the numerical the algorithms and not so much about |
|
|
01:54 | programming and it's really caught on. I would say the software package known |
|
|
02:04 | Meth lab today is probably the most or is the most successful software packages |
|
|
02:14 | not only in your algebra a lot other things too, it has really |
|
|
02:22 | developed by academics mostly that does new and their courses and and then this |
|
|
02:35 | known as math works that is responsible the math lab products is and taking |
|
|
02:42 | of it up and thank you too and support it. So a lot |
|
|
02:47 | the content and the math is really from academia and also verify that things |
|
|
02:59 | of good american quality and because of very large user base it also got |
|
|
03:06 | well developed. So nowadays it's put as a collection of toolboxes that covers |
|
|
03:19 | wide range of domains and there's just list of a few um we will |
|
|
03:26 | engage with and they are the toolboxes my recollection and what they do is |
|
|
03:33 | do the basic, simple the neuralgia that doesn't require in one of the |
|
|
03:41 | boxes. Mm hmm. And here kind of very brief listing of what's |
|
|
03:50 | Math lab as well as a companion in on a similar thing so that |
|
|
03:55 | things sort of comes together and it was listed on there previous slide as |
|
|
04:02 | . A lot of things also in kind of usage in terms of deep |
|
|
04:09 | and hey I as well as signal and all kinds of other stuff and |
|
|
04:16 | for stimulation tech tools. So it a very wide range including also cogeneration |
|
|
04:26 | not just standard processors, you know in the IBM and whatever you have |
|
|
04:35 | also for actually being able to generate for F P G A. S |
|
|
04:39 | programmable devices at the hardware level. they also have application tool boxes for |
|
|
04:48 | domains. So it's indeed quite a set of tools so that and because |
|
|
04:56 | the wide distribution is released, something very valuable to know, not just |
|
|
05:02 | this course, but for life after the course and or to age or |
|
|
05:10 | academia or in industry since it's so used. All right now, a |
|
|
05:16 | bit about the overall structure on that . So on this side, I |
|
|
05:25 | the first thing on the top is the task, graphical user interface and |
|
|
05:32 | sure suggestions on demo how to use graphical user interface and then there's a |
|
|
05:38 | of other ways and that you can that you do work. But matt |
|
|
05:45 | it has kind of its own set files types, what's known as m |
|
|
05:52 | , meta files of codes and matt are data files and then there's also |
|
|
05:59 | command line interface. So I think some of all three of these or |
|
|
06:05 | of these things will be touched upon suraj from a graphical user interface and |
|
|
06:13 | can do a lot of things access boxes, built in functions and report |
|
|
06:21 | and performance measurement tools and it kind looks like this. But I'm not |
|
|
06:26 | to go through the different fields. sure josh will do that. And |
|
|
06:34 | as I said, there are files code. So yes, you can |
|
|
06:37 | things that they want to do directly the prompts from meth lab, but |
|
|
06:45 | it may be more effective in actually the script and then saving it as |
|
|
06:52 | the top M file and then you the script file and then they want |
|
|
06:58 | , the change makes changes and playing the trial and errors for algorithms or |
|
|
07:07 | . It's kind of very easy then make yourself m fights. And the |
|
|
07:14 | part is the data files that are of binary files that Math Lab uses |
|
|
07:21 | store variables and the specifics for the that you use and running your bad |
|
|
07:32 | scripts at one point about this in addition to that statement is that |
|
|
07:42 | Math Club does file compression and so store files, unless you for something |
|
|
07:51 | are compressed funds. So that means takes a little bit of time to |
|
|
07:58 | . But of course the weakest system part in the system when it comes |
|
|
08:05 | larger data set is the data path storage or disks that compared to many |
|
|
08:13 | things in the systems are quite So even though it says here that |
|
|
08:18 | , it does tend to increase the for store for writing, but it |
|
|
08:26 | speeds up things when you're loaning because , un compression is pretty fast compared |
|
|
08:32 | the data bowling rates but of depending upon how effective the compression |
|
|
08:40 | there's no guarantee that you always, when it finally small already to start |
|
|
08:45 | , it probably doesn't pay. And the file is such that it's hard |
|
|
08:53 | get a large fire science reduction and them, it doesn't really improve |
|
|
09:02 | The loading either. So compression depends basically finding patterns yet you can describe |
|
|
09:10 | effectively than the data itself. So of things about racism. Out time |
|
|
09:23 | designed to work with the race. it's kind of the language, the |
|
|
09:29 | and languages a language with a narration and in that regard it's not all |
|
|
09:35 | different from other languages that also have syntax. So that means two operations |
|
|
09:45 | be done on a race and conceptually way as you operate in single |
|
|
09:52 | If you can I had the rage doing sort of a plus operation and |
|
|
09:57 | right thing happens. You don't have explicitly create oops that as each individual |
|
|
10:08 | pair of elements individually. So I'll a little bit about that but that |
|
|
10:14 | sure when the coverage Yeah some detailed Swedish and talk briefly about data types |
|
|
10:22 | storage and referencing which is just a feature. Um that one can use |
|
|
10:29 | times. So I will do things quickly. So as I said, |
|
|
10:36 | ray are the it's designed for the . So that's basically it's the premier |
|
|
10:42 | type in math lab. So even you asked that the scalar, it's |
|
|
10:48 | basically stored as if it were in right arrangement. Having a number of |
|
|
10:53 | that you're is convenient for the So it's not just one or 2 |
|
|
10:59 | like typical dr emergencies so it can any number of dimensions but it is |
|
|
11:06 | to the point that for every dimension to every other dimension, the number |
|
|
11:11 | elements needs to be the same. basically it in two dimensions will be |
|
|
11:18 | of a square dr ray and but did mention some form of empathetic structure |
|
|
11:26 | in the degenerate case cube, it be ragged. Um Then size is |
|
|
11:37 | of an important function that is coming that plan and the sizes of actress |
|
|
11:44 | says that tells you how many dimensions already has and how many elements there |
|
|
11:50 | in each of the dimension. And probably demo mode. And another thing |
|
|
12:01 | um as it says and then thinking you reference an element in the array |
|
|
12:11 | his on the right hand side which sort of the middle example you point |
|
|
12:19 | something that is not part of the . That's an arab. On the |
|
|
12:24 | hand, if it's on the left side that means kind of assigning values |
|
|
12:32 | something that originally was not included in array the Iraq has extended. So |
|
|
12:40 | illegal. And the thing to Okay. And then he was just |
|
|
12:46 | as various forms of assignment and I suggestion will probably demo that. But |
|
|
12:51 | one part I wanted to stress is by being in language or with raising |
|
|
13:02 | it tends to use or triplet notation often the work can is legal and |
|
|
13:08 | has the structure. It's the first an increment and I last and If |
|
|
13:14 | is submitted, that means the increment by the 4th 1. So it's |
|
|
13:19 | of an easy way of initialize things basically having the looping built into the |
|
|
13:31 | structure. I will go through. didn't want to take too much time |
|
|
13:38 | I'll let this. There are examples the slides that you can look at |
|
|
13:43 | and I'm sure. And so the demonstrate, there's a couple of things |
|
|
13:51 | variable naming that it is case So one has to be careful and |
|
|
13:57 | unused variable names to make sure you kind of mess up by not paying |
|
|
14:04 | to exactly once you do um to data types as available, you |
|
|
14:15 | single and double. The one thing want stressful, I want to stress |
|
|
14:21 | get to be stressed and assignment is default, everything is in double |
|
|
14:28 | So I'm when my wants to study effects are the accuracy outcome using single |
|
|
14:37 | double position. One needs to be clear and explicitly declare things variables as |
|
|
14:43 | in single position and also make sure um in sort of consistency things does |
|
|
14:53 | get promoted to double precision in Um Okay, that was what I |
|
|
15:02 | on that. So here's what I to point out in terms song, |
|
|
15:10 | the race are these calls, sequence storage associations or if you are multidimensional |
|
|
15:18 | raise, they always get flat into dimensional erase before things are laid out |
|
|
15:24 | memory that happens in C. And and everything. So it's just |
|
|
15:28 | Rised when it's signed to memory and uses call a major order. So |
|
|
15:38 | just shows how then this um array to a what kind of a matrix |
|
|
15:50 | . But it also means that since are effectively laid out As one dimensional |
|
|
15:59 | and look here at the memory, means one can reference elements within the |
|
|
16:09 | but just figure out what if location is in memories of a component. |
|
|
16:14 | doesn't have to have multiple indices to a particular element. One can just |
|
|
16:21 | by its order in the linear And I will let probably you can |
|
|
16:29 | at the slides and different ways of it and you can get subsections and |
|
|
16:35 | it on with that. So it's convenient to into um subsections of arrays |
|
|
16:41 | blocks of arrays and work with blocks this section and type form function in |
|
|
16:50 | . Yeah. And I'll try to something about theory operations. So, |
|
|
16:57 | that's probably what the bulk of the will be and telling you about how |
|
|
17:02 | can reference elements in this thing. then it's sort of one thing that |
|
|
17:08 | amazing. Often convenient is then how can Reshape arrays between one and 2 |
|
|
17:17 | or and the number of dimensions from linear space to some multidimensional array or |
|
|
17:28 | or introduce a number of dimensions by a revision. And I guess that |
|
|
17:36 | and I like to look at the on the slides, transport diseases in |
|
|
17:42 | time. This prime thing that allows to um change your order between there |
|
|
17:49 | the arguments it supports reduction, which and it also has a built in |
|
|
17:56 | brand that shows here and some that things along various dimensions depending upon how |
|
|
18:04 | use this argument. Um and uh comes quickly as I've warned because the |
|
|
18:14 | is really On the demo and I to take not more than about 15 |
|
|
18:20 | to see Ashley has enough time to his demo and then time for doing |
|
|
18:25 | couple of simple exercises. But let see. And so you can do |
|
|
18:33 | concatenation of a race that has to shaped consistent and then here's something built |
|
|
18:39 | functions that are quite useful already mentioned . And the number of function you |
|
|
18:45 | also initialize erasing the different ways to or ones by using the corresponding in |
|
|
18:55 | but that was really quick and a bit um not a good job but |
|
|
19:00 | because that should hopefully be covered but heads up for things to pay attention |
|
|
19:08 | when um so just do the So I think you can take over |
|
|
19:16 | here. Yeah, I'll start Okay, can you see my |
|
|
19:27 | Yes. Okay, great. so we're just starting with what the |
|
|
19:35 | workspace looks like in in Math So when when you open it you'll |
|
|
19:40 | a window. Probably something like you won't have these many scripts open |
|
|
19:46 | . Um so there are mainly two for writing Math lab scripts. One |
|
|
19:53 | just using a simple dot m script you can use open using this new |
|
|
19:58 | , but then over here in the tab, um and then another using |
|
|
20:03 | live script, which I'll show you that looks like later on for |
|
|
20:07 | I'll simply just work with the dot scripts. Then here in between you'll |
|
|
20:14 | your workspace where you write your commands everything in the bottom, you have |
|
|
20:21 | command window where you'll see most of outputs and you can have your workspace |
|
|
20:27 | as well, which contains all the basically that you declared through throughout the |
|
|
20:34 | of your script. Um So so one thing I would suggest everyone |
|
|
20:43 | to use these two commands first, your in your script, always because |
|
|
20:48 | been sort of helpful for me and me not run into many issues. |
|
|
20:54 | first cl c c stands for a console. So if you do the |
|
|
20:58 | you run this command then it basically out the whole command window where you |
|
|
21:02 | your any output that you may have from your previous executions, it just |
|
|
21:08 | remove all the clutter get makes things confusing. And the second is clear |
|
|
21:14 | which you can also achieve by just this clear workspace um button on the |
|
|
21:19 | and what that does is it basically all these variables that you that you |
|
|
21:24 | have in your workspace. So in , whenever you run the, run |
|
|
21:28 | program, all the variables get stored the workspace and if you run the |
|
|
21:32 | again and you try to redefine that's the variables with the same name |
|
|
21:38 | you try to do something else. Math lab throws an error because it |
|
|
21:42 | confused between two variables of the same . So it's generally a good idea |
|
|
21:47 | clear your workspace every time you run code, it may not be the |
|
|
21:53 | idea. If you have loaded a very big data set in that |
|
|
21:57 | try to avoid that because loading a dataset takes time, in that case |
|
|
22:02 | do that. But if you're just simple programs, you can simply just |
|
|
22:05 | that and clear out your workspace so you avoid any issues later on for |
|
|
22:14 | demo, I'll just close the it's not going to be needed. |
|
|
22:17 | can simply drag and drop command window well for now, I'll just put |
|
|
22:22 | on the right side um to run of any of your scripts, just |
|
|
22:29 | go to the editor tab on the and press the run button. So |
|
|
22:35 | will clear out the command window and will come out. Clear out the |
|
|
22:40 | and once you run it, I'll to this plot later on. |
|
|
22:46 | starting from variable description, if you used python then it's very similar to |
|
|
22:53 | you do in python. Just without data type, you can just simply |
|
|
22:56 | any variables and their assigned values against against the hence the command. But |
|
|
23:04 | you emit the semicolon, that's still valid statement. Mad love. Will |
|
|
23:10 | give you any other what that basically is whatever is the output of executing |
|
|
23:15 | particular line will also be show reflected the in the command output in the |
|
|
23:21 | window. So if you don't want see output of every single line that |
|
|
23:26 | execute, just put a semicolon at end and as dr johnson just said |
|
|
23:32 | the variables that you define are by . Double precision. Yeah. So |
|
|
23:38 | these two variables are double precision. can also check the type by using |
|
|
23:43 | class function. So here this is output here that tells you that class |
|
|
23:48 | a is double. If you want cast it to single precision then just |
|
|
23:53 | a typecasting as you would do in other programming language using the single statement |
|
|
23:59 | that converts that variable into a single variable. And here we store that |
|
|
24:05 | to see um operators, multiplication. as any other programming languages. If |
|
|
24:13 | multiply two double precision numbers, the you get is double precision. I |
|
|
24:19 | think it printed it printed up So double precision divan. If you |
|
|
24:27 | double precision numbers and cast it to precision then the output a single precision |
|
|
24:32 | that's the two which is a single number here. Um Addition of a |
|
|
24:40 | and single precision results in single precision which again you see here the three |
|
|
24:45 | a single precision number and multiplication of and single precision results in a single |
|
|
24:52 | number. So before here is a precision number. Um The power |
|
|
25:01 | you can use it to raise any to any power that you want. |
|
|
25:06 | here just squaring up a so a whatever the way what value was got |
|
|
25:12 | and got stored into T. one colon operator again as you saw in |
|
|
25:18 | slides that generates a vector. And here the initial value of the vector |
|
|
25:25 | one we gave it an instrument of and the upper limit was 10. |
|
|
25:30 | so the vector that was generated, had all these values from 1-9. |
|
|
25:36 | that's all Values in increments of two till 10. Um Similarly you can |
|
|
25:45 | um use um this colon operator to um an interval with equally distant values |
|
|
25:55 | you can use inbuilt functions like sine provided the the variable as input that's |
|
|
26:04 | times T. So that's by times whole the vector that you generated. |
|
|
26:12 | that will give you the value of function for all those values as a |
|
|
26:20 | and that will be stored in And if you want to plot it |
|
|
26:25 | can simply give it. Uh I X comma Yes. Oh sorry |
|
|
26:31 | Yeah X comma. Y. And will be a plot those values. |
|
|
26:38 | Inside a inside a line plot So that's generating plots is also very |
|
|
26:48 | . Um Right if you want to input from a user that's also very |
|
|
26:53 | , you can just use the function input and if you want to associate |
|
|
27:00 | message with that you can simply give string as an input to that function |
|
|
27:03 | whatever message you want to show up that and that causes the program to |
|
|
27:10 | until you get input from the let's say I give it 10. |
|
|
27:15 | then you can use the F. F function which has a similar |
|
|
27:21 | A few of you see before you percentage of F as the variable declaration |
|
|
27:27 | variable definer, for a floating point and just a message and then the |
|
|
27:33 | name to get the output on the . So any questions on that. |
|
|
27:41 | are just some very simple concepts to started with. Alright, I have |
|
|
27:54 | questions so feel free to just bother in between if you have any |
|
|
28:03 | Alright um you can also write conditional . So the syntax for the NFL's |
|
|
28:14 | in Math lab is like this you if then your conditional on the condition |
|
|
28:21 | you wanted to run for whatever you to do for that condition and then |
|
|
28:26 | F followed by else and then each or I should say any structured block |
|
|
28:34 | Math lab ends with whatever keyword it's to start with and then it ends |
|
|
28:40 | the keyword end. So that marks end of that structured statement. So |
|
|
28:47 | and marks the state end of this structured block. Um you can also |
|
|
28:55 | switch statements like any other programming So here I defined a variable called |
|
|
29:01 | with a string that has been it then the switch statements Sin taxes like |
|
|
29:07 | , a switch and then the variable which it's supposed to run for. |
|
|
29:12 | then you define all the cases for you want to run different statements for |
|
|
29:21 | if I remember correctly, she has uh as the default keyword for the |
|
|
29:29 | where you have no specific input for Math lab, that's the same |
|
|
29:35 | Can be achieved by using the otherwise . Um Yeah. And if I |
|
|
29:43 | it. Yeah. So if X 50, So the else if statement |
|
|
29:48 | executed for the first part so I X is equal to 50 and then |
|
|
29:53 | switch statements since grade was be the be got executed and great, bigger |
|
|
30:00 | out there on the console. Any on the switch? Can you do |
|
|
30:10 | fall through between cases? Like you see languages, I'm sorry say that |
|
|
30:16 | . Can you do a fall through say I have case A and then |
|
|
30:19 | case B basically a case that handles cases. Uh I'm not sure I |
|
|
30:28 | really tried that. You might be to I don't, I don't think |
|
|
30:32 | this should be a big deal. you can give a comma here, |
|
|
30:35 | not aware of the right syntax but can, you can probably do |
|
|
30:45 | Alright. Um then there was conditional you can also write for loops and |
|
|
30:50 | loops in math lab. So let just quickly run that so we can |
|
|
30:54 | the output as well. So here equal stem and then you can write |
|
|
31:00 | while loop by using this syntax awhile less than 20 condition and then inside |
|
|
31:06 | via loop you also give the increment A and then you finish it up |
|
|
31:11 | the end statement and so that runs Those 10 penetrations from 10 to |
|
|
31:22 | Um Yeah. Ah for loop you also, you have a couple of |
|
|
31:30 | ways to to run it um here for loop I defined for x equals |
|
|
31:38 | . And remember this is the colon . So by default the increment as |
|
|
31:45 | . So this uh this for luck run from Then all the way to |
|
|
31:50 | . And remember, these are the indexes where whenever you use a colon |
|
|
31:56 | . So 10 and 20 are included the in the sequence that you run |
|
|
32:03 | . If you want to change the , let's say bye to rather than |
|
|
32:08 | default of one you can provide to the increment in that colon operator. |
|
|
32:13 | then the loop will run for The are implemented by two from 10 to |
|
|
32:18 | . And as any other structure you ended with the with the end |
|
|
32:26 | . Any questions on that. So are just simple ways to run the |
|
|
32:33 | . Look, I'll show you how run them with vectors and matrices as |
|
|
32:41 | . So yeah, just quick Is that it's not a big deal |
|
|
32:45 | matt lauer, it's just a slight in in the in syntax of how |
|
|
32:50 | write it. But otherwise the whole , it's pretty much the same as |
|
|
32:54 | other programming languages. You might have no one thing to remember that array |
|
|
33:03 | disease when default starts by one. Maryland was supposed like fortune, but |
|
|
33:11 | that starts at zero. Right. , I was about to get to |
|
|
33:15 | . Okay, Alright. Yeah. , okay. I think and chad |
|
|
33:23 | said that for fall through case for cases, switch statement is conditioned one |
|
|
33:29 | condition too. So you can just multiple conditions separated by commerce. |
|
|
33:37 | Thank you for that. All So yeah. Alright, I run |
|
|
33:47 | code again, so we can see output. Um Again I haven't given |
|
|
33:52 | colons everywhere, so we can see output right away rather than putting everything |
|
|
33:57 | print effort. Any display commands. is another command called display which you |
|
|
34:01 | use to print out state anything on console. Um Alright, so Coming |
|
|
34:10 | vectors, just simple one directors. you can define a row vector um |
|
|
34:18 | elements spaced by just blank spaces, it also works with commas. So |
|
|
34:25 | can just simply provide commas in And that also defines a row |
|
|
34:31 | Ah Right. For column vector, define each column, each roll separated |
|
|
34:38 | a semi column. So every semi basically starts a new new role. |
|
|
34:45 | if you have one element in each that basically makes it makes it a |
|
|
34:50 | vector. So here B is a vector where each row is 4567 all |
|
|
34:56 | way to 10. So that's one vector over there. Right? Um |
|
|
35:01 | yeah, here's the indexing part. indexes in math lab start from |
|
|
35:06 | Uh as compared to zero in other languages. So the first element you |
|
|
35:12 | if you index using uh these uh place is over here. Um You |
|
|
35:21 | from one. So the first the first element in one was |
|
|
35:25 | So you get that four. Second was five, you got five and |
|
|
35:29 | on. Um you can also get of the elements of from the |
|
|
35:38 | So that you can do, we using the colon operator. So here |
|
|
35:44 | can provide the start and end index which you want the elements from. |
|
|
35:51 | again these indexes are inclusive. So get index 234 and five from |
|
|
35:57 | So that's 56 and 78 values in . Um If you want something from |
|
|
36:06 | specific index all the way up to end of that vector, you can |
|
|
36:11 | provide the end keyword as the as last index. And that should give |
|
|
36:18 | all the indexes, all the values from whatever. Starting index you give |
|
|
36:23 | what whatever. And the last index that vector, if you want specific |
|
|
36:33 | from our vector, let's say I Element at Index one. Index 5 |
|
|
36:40 | Index six. Then I can simply a list containing all those indexes as |
|
|
36:45 | Parameter ah to the to the indexing . And that returns those specific uh |
|
|
36:56 | from that particular vector. If if want kind of a reversed reverse order |
|
|
37:05 | the of the elements, you can simply switch the statement to just to |
|
|
37:11 | the starting index from end. But you have to provide the increment or |
|
|
37:16 | I should say a detriment um value that it knows how many elements elements |
|
|
37:22 | jump every time while going back and the way up to the index number |
|
|
37:27 | . So here is upset four. the values from last index jumping to |
|
|
37:34 | every time and all the way up The second index in the in the |
|
|
37:39 | the vector. So that's 10, and six in the a vector over |
|
|
37:44 | . If you want to just reverse entire entire vector and store it in |
|
|
37:51 | variable or even in the same you can do that, you can |
|
|
37:56 | the command flip and provide the name the vector that you want to reverse |
|
|
38:00 | that that will give you a reversed . Um looping through a vector again |
|
|
38:09 | couple of ways to do that. First is simply you can provide the |
|
|
38:17 | uh the indexes starting from 12 length A. That that means the number |
|
|
38:24 | elements in the um in that So it starts from 12 length |
|
|
38:30 | And then you can index it um this indexing statement here and that will |
|
|
38:37 | you the loop output for all those the variables, all the elements in |
|
|
38:45 | question. Um So um this is mike working for. Okay so can |
|
|
38:51 | like put like a set like at own vector? For like a for |
|
|
38:54 | like that. So let's say you a vector that's like 1567. You |
|
|
39:00 | do that with the for loop to you you can do that too. |
|
|
39:04 | simply just replace this with like I above and it will run for these |
|
|
39:11 | values. So that's 15 and six then you can index using the ai |
|
|
39:17 | or whatever indexing variable you've used. was what my next example was going |
|
|
39:24 | be. You can simply just assign to the name of that vector. |
|
|
39:29 | here I equals if you write that the output is simply just printing out |
|
|
39:37 | values. And in this case i not the index but those are the |
|
|
39:41 | values inside the vector. So you look through a vector just by directly |
|
|
39:49 | its value to the indexing variable as . Does that answer your question |
|
|
39:58 | Yes. Okay. Mhm. Um right. So for vectors you can |
|
|
40:08 | perform transport and that's simply just the operator. So remember be was a |
|
|
40:16 | vector and if you transpose it you a roll victor. So that's |
|
|
40:24 | Um addition of two vectors is element edition. So if you add A |
|
|
40:31 | B transports, it's going to simply add each pair wise elements with each |
|
|
40:38 | . The multiplication operation is the one need to be careful about. So |
|
|
40:43 | are two versions of multiplication operation. is just simply the asterisk operation and |
|
|
40:50 | other is dot and asterisk, just simple asterisk is a matrix multiplication. |
|
|
40:58 | that's going to perform a inner product an outer product based on whatever the |
|
|
41:03 | of two vectors are the dot star the element wise multiplication. So here |
|
|
41:10 | line 43 what I'm performing is an wise um product of A and |
|
|
41:18 | Transport. So in that case it multiplies be transposed. Which was this |
|
|
41:25 | and A which was this guy. that's just basically square of each elements |
|
|
41:34 | 16, and so on Online what I'm doing is a matrix |
|
|
41:41 | So that's only just the asterisk operator . And that in this case is |
|
|
41:48 | row vector times a column vector. it was a row vector and B |
|
|
41:51 | a column vector. So that performs inner product. And inner product is |
|
|
41:56 | , if you're aware it's a multiply operation, you perform element wise multiplication |
|
|
42:01 | then you add up all the all all the products. So that's uh |
|
|
42:09 | the output of that operation is there's 71. So be careful whenever you're |
|
|
42:16 | multiplication of two vectors or two you should know what operation you are |
|
|
42:22 | . And then use the right operator that. No. All right, |
|
|
42:30 | appending vectors with each other. So , just like when you were defining |
|
|
42:39 | as I said, having columns or commas or just spaces between elements creates |
|
|
42:47 | row vector and having semi columns between creates a column vector. The same |
|
|
42:54 | goes for when you're when you append vectors with each other. So here |
|
|
43:01 | I append A will be transposed and have the column as a comma. |
|
|
43:08 | the as the operator in between That means you add all the all |
|
|
43:14 | elements of B transpose to the to columns of A. So in this |
|
|
43:22 | it's just basically a one D. pending operations so to say. So |
|
|
43:27 | just gets appended after all the elements the road victory. If you have |
|
|
43:33 | semi colons as the as the operator between them, then the new elements |
|
|
43:39 | get appended goes and go to the row. So in this case it |
|
|
43:44 | A um to Arturo matrix basically because new elements that from B transports they |
|
|
43:52 | to the next next door. Ah thing that BB was a column vector |
|
|
44:01 | all the way to 10. If append B again using the comma then |
|
|
44:07 | goes to the next column. So rest of the 45 all the way |
|
|
44:11 | 10 goes to the next column. you append using a semi column then |
|
|
44:18 | get appended below it. That means go to the next draw. So |
|
|
44:23 | this way you can append column vectors row vectors with each other in different |
|
|
44:31 | . Any questions on that comment? worked nicely because A. And B |
|
|
44:40 | the same number of elements. Yes. If you if you have |
|
|
44:44 | number of elements in um in in in the vectors then for one of |
|
|
44:53 | dimensions it will complain. Um So say if um the number of uh |
|
|
45:02 | when performing this operation when adding be to be the number of elements in |
|
|
45:09 | operations was not the same then it have created a ragged array. That |
|
|
45:16 | Let's say we had from 4 to in the left in the first column |
|
|
45:20 | only had 456 and seven in the column. That means that the number |
|
|
45:26 | elements are not equal in one of dimensions. And then matt love would |
|
|
45:30 | complained. So you have to be when you're appending vectors with each other |
|
|
45:39 | the same would happen if you tried multiply two vectors whose dimensions do not |
|
|
45:55 | . All right. Um Right. to define matrix it's a it's a |
|
|
46:03 | simple yes chat question. How does lab handle operations? Multiplication or addition |
|
|
46:10 | the vector? Mix with in danger strength. That's a good question. |
|
|
46:19 | I don't exactly know. I haven't but my guess is that it gives |
|
|
46:25 | an error because of data type I don't think it performs multiplication of |
|
|
46:33 | data types exceptional. Eric yeah except America if they are double or single |
|
|
46:40 | it's fine. It doesn't complain but they are numbers and strings then it |
|
|
46:45 | complain. All right. Um Yeah to define a matrix again I'll just |
|
|
47:02 | it. Um Yeah so to define matrix you can just simply define a |
|
|
47:11 | of row vectors separated by semi which is basically a matrix. So |
|
|
47:18 | in this case 12345 is one row is another row and rows are separated |
|
|
47:24 | semicolons. So you get this matrix here, you can perform transpose of |
|
|
47:31 | matrix again using the apostrophe out So that gives you the transports again |
|
|
47:40 | starting start from one in math So you get if you want to |
|
|
47:45 | a certain element, you just start from one. And let's say if |
|
|
47:50 | do three comma four, that means 3rd row which is this row and |
|
|
47:55 | column which is this column. So element value six as the that's how |
|
|
48:01 | can index it if you want to let's say all the rules of the |
|
|
48:07 | the matrix, but only a few . So for Rose you can just |
|
|
48:14 | write the colon operator, which basically for that. I want to hold |
|
|
48:18 | Rose and then you can tell it I want only to the columns two |
|
|
48:25 | three. So that's two and three the call an operator again And that |
|
|
48:31 | you a column two and 3 and the rows of the matrix simply if |
|
|
48:36 | want all the columns, but only rows one and two. You can |
|
|
48:43 | this syntax to do that and that you the first two rows and all |
|
|
48:48 | columns of those two rows. So how you can just get slices or |
|
|
48:54 | ah the matrix that you want. Again here the asterisk or print is |
|
|
49:02 | matrix multiplication operation. So it performs times column for each row of of |
|
|
49:07 | left hand operator. And that gives the output for matrix multiplication. If |
|
|
49:13 | want to perform element wise multiplication of matrices. The operator uses dot followed |
|
|
49:21 | the asterisk and that's that's what gives the element wise uh multiplication. Um |
|
|
49:32 | . Right. You can also compute inverse of a matrix determinant of a |
|
|
49:39 | . There are simple, simple commands do that. I envy transport inverse |
|
|
49:44 | stands for determinant. Um Right. then there are some special functions that |
|
|
49:52 | can use to define matrices with either zeros, all ones or random random |
|
|
50:02 | in the matrix. So zero's three it defines a three by three matrix |
|
|
50:08 | all zeros in it. So that's one. If you want the matrix |
|
|
50:14 | two rows and three columns all with , you can use this syntax 02 |
|
|
50:18 | three. And that gives your matrix of size two x 3 with all |
|
|
50:24 | in it. Same if you want rather than zeros, then you can |
|
|
50:29 | do once and provide two comma And that gives you a matrix of |
|
|
50:34 | by three with all once. If want a matrix with random values, |
|
|
50:39 | can use the function rand. Ah then give the dimensions. So let's |
|
|
50:44 | we give three by three That gives a matrix with random values of dimensions |
|
|
50:51 | x 3. And the important point using random function you get all the |
|
|
50:57 | that are uniformly distributed in the in interval zero comma one. So if |
|
|
51:05 | want a matrix that has values outside domain, you need to multiply each |
|
|
51:12 | of the value with that whatever scaling , you need to get it into |
|
|
51:16 | different different range. Alright. Any on that? All right. Um |
|
|
51:35 | . Next is how you define functions in math lab. The first point |
|
|
51:42 | that functions inside a dot M script to be defined at the end of |
|
|
51:50 | script. You cannot define it, it before any of the assignment statement |
|
|
51:56 | any other commands. You need to them at the end of the |
|
|
51:59 | Otherwise model gives you an error. The syntax to define a function is |
|
|
52:05 | you have to write the keyword function you need to provide the name of |
|
|
52:10 | variable. That will have the return of of the of whatever is computed |
|
|
52:16 | that, in that function uh followed equal sign. And then the function |
|
|
52:23 | and then the parameters that that function us input. So A and B |
|
|
52:29 | are the input R E. Is the is the return variable which |
|
|
52:34 | contain the return value. So in , in this function I'm basically comparing |
|
|
52:39 | numbers. It is bigger than The R E S variable contains a |
|
|
52:45 | it contains the value of P. I define X and Y as five |
|
|
52:51 | 10 I called the function compare with X and Y variables. And note |
|
|
53:00 | the name of the variables that you here while calling the function does not |
|
|
53:04 | to be same as the function parameters and that's similar to any other programming |
|
|
53:13 | . Um so you call that you give five and 10 as the |
|
|
53:18 | since then is the bigger number? function should return then in this R |
|
|
53:23 | . S, variable. And then return value from that function is stored |
|
|
53:28 | that in a variable called camp. here as you can see the return |
|
|
53:32 | we got was 10 in camp. If you want to return multiple values |
|
|
53:41 | the function, you can simply just the list of the return variables as |
|
|
53:49 | rather than just providing one variable, as the written written variable. So |
|
|
53:55 | this function returns two values that some mull And again it takes two variables |
|
|
54:01 | inputs. Uh stores the sum of two variables in some and the product |
|
|
54:07 | those two variables in mall it returns two. So if we call that |
|
|
54:12 | X and y here Some in Mulch contain 15 and 50. So that's |
|
|
54:20 | some 15 miles has contained 50, questions on that. So just the |
|
|
54:32 | concept. Just different syntax. All . And yes, you can also |
|
|
54:45 | um You can also solve equations um perform differentiation and integration using symbolic |
|
|
54:55 | I don't think I should go into . I'll just post this demo on |
|
|
54:59 | blackboard and you can take a look think for the tutorial they only need |
|
|
55:06 | stuff. We can cover these other later on maybe. Yeah. Um |
|
|
55:15 | guess everyone is everyone ready but their lab environment is everything set up for |
|
|
55:21 | guys. Just just an F. . I focus on the smallest of |
|
|
55:25 | he even does try to experiment that like there's a symbolic math toolbox that |
|
|
55:31 | have to install. Right? If you try to run that and |
|
|
55:35 | don't have the toolbox installed. Matara automatically tell you that you need that |
|
|
55:40 | box. It will give you a to install it. I forgot about |
|
|
55:43 | part. Yeah. So it's a not a big deal. It's if |
|
|
55:48 | if you're missing a toolbox metal up tells you that you're missing something. |
|
|
55:51 | will give you an error in the window along with a a link that |
|
|
55:56 | take you to whatever web page or small window that will allow you to |
|
|
56:01 | that toolbox. So there's not much out to do if you're missing something |
|
|
56:06 | your environment. Mhm. That's Medlab generally a very helpful tool in that |
|
|
56:12 | ? Unless the chat question, is also true for the online version? |
|
|
56:18 | don't know. I believe online version I should have all the toolboxes automatically |
|
|
56:24 | if if it doesn't it should automatically it from whatever server it's running |
|
|
56:31 | I don't think that's required on the version, but if if not it |
|
|
56:37 | it will probably give you again some way to do it. It won't |
|
|
56:41 | a complicated process to do it. . I only have a few exercises |
|
|
56:54 | you guys want to go through Oh, before going to that, |
|
|
56:59 | me tell you the easier way to your codes for these exercises. So |
|
|
57:05 | till now I was showing everything in dot M scripts, right? Which |
|
|
57:09 | just simple scripts to save and run codes for the exercises. You can |
|
|
57:14 | use the live scripts. And those generally more helpful in debugging your code |
|
|
57:21 | you can go to new and open live script from there. And what |
|
|
57:26 | does is it basically allows you to the output of your program as you |
|
|
57:31 | . So let's say if I define equals five, it will show you |
|
|
57:35 | output of whatever I did and If did X Square, it will show |
|
|
57:41 | output 25 years. So it's easier debug your code as you go in |
|
|
57:47 | scripts feel free to use that if more comfortable with dot M scripts feel |
|
|
57:51 | to do that. Is there a um, when I'm trying to do |
|
|
57:59 | you did with the ml xing of live editor, but I'm not seeing |
|
|
58:04 | outputs on the right side. Uh do you not see this window |
|
|
58:13 | the right side? That's what I . I see the window on the |
|
|
58:16 | side, but there's no there are um you need to you need to |
|
|
58:20 | a run in the live editor tab in the live editor tab. |
|
|
58:27 | I got it. I see it . Okay. What's another question having |
|
|
58:34 | lab opens uh low system resources. , in that case you may want |
|
|
58:41 | use the online version. If you to install Maglev on your laptop using |
|
|
58:47 | university license, you can simply go the Mat lab online version and login |
|
|
58:52 | the same same credentials and that should you access to the online version. |
|
|
59:03 | you still want to run it on laptop, you may need more |
|
|
59:08 | Yes. Metal optics quite a bit RAM. All right, let me |
|
|
59:18 | the exercises on top, let's start exercise one and to only have 20 |
|
|
59:25 | , I'll Give maybe four or 5 to get them done. It's they're |
|
|
59:31 | as difficult. Um if it if feels like that we're running out of |
|
|
59:38 | , I'll simply just go through the quickly. But let's see if there |
|
|
59:43 | people who can do it. So question was just starting to get enough |
|
|
59:49 | . Well I'm running with 16 so should be fine. Yes. So |
|
|
59:54 | making me wonder how much is How much is depending on what your |
|
|
59:58 | is? If it's yeah if you has 8 gig and it's um the |
|
|
60:12 | and the exercises are on the The demo is on on blackboard. |
|
|
60:17 | haven't posted the exercises yet and if curious the exercises are actually from dr |
|
|
60:26 | slides which are probably for the next . And there is they are at |
|
|
60:31 | end of that particular lecture. So are the exercises from the lecture slides |
|
|
60:40 | . All right. Yeah let's do exercise one and two elevator a couple |
|
|
60:44 | minutes before. Yeah you guys get try it. I'm not sure if |
|
|
60:55 | are from the book. Sorry I not remember. Keep in check but |
|
|
61:02 | will have them posted. Yeah I'll them anyway that's fine. Alright that's |
|
|
61:22 | Okay I'll wait till two or 5 guess. Okay. Yeah and also |
|
|
61:28 | exercises are on my slides I guess next lecture we encourage you to do |
|
|
61:35 | and as well as whatever gets posted passion if you have trouble send us |
|
|
61:42 | so we can work with you if don't get time to do it now |
|
|
61:46 | the election because an email or you trouble on hulu. So you can |
|
|
62:00 | your feedback. Excuse me. I one question. So the vector is |
|
|
62:44 | vector or a It's a it's a vector because the elements are separated by |
|
|
62:53 | . Mhm. The first one. first one on the first one as |
|
|
62:59 | . Yeah. And for the and the second question, um index position |
|
|
63:06 | at one or a zero. Yeah. Math Club and Math Lab |
|
|
63:11 | starts from one. Yeah. Just the summer Into what or reminder what |
|
|
63:36 | has already said. So list of separated by spaces or commas results in |
|
|
63:44 | row. Doctor. If they are by semicolons, it becomes a column |
|
|
63:53 | . So it's just two options for and one for creating a role factor |
|
|
64:00 | one for creating economy. That's Alright. Uh should I talk about |
|
|
64:15 | Solutions for these 2? Has anyone ? We're a bit tight on |
|
|
64:22 | So you may not get a chance do all of them, but feel |
|
|
64:27 | to try them on your own later . If you if you don't get |
|
|
64:30 | chance any volunteers for the first Okay, sure. Yeah. Go |
|
|
64:42 | . I just want to You want share my screen. Is that what |
|
|
64:44 | mean? Yeah. Yeah, Let me allow David Wright. |
|
|
64:51 | I think I did it. Yeah. You should be able to |
|
|
64:56 | it now. All right. Is ? Sure. Can you see? |
|
|
65:08 | , I think it's good. I it's sure. Okay. There we |
|
|
65:12 | . I was seeing the preview. see. So your screen. I |
|
|
65:19 | see yours that says I'm sharing. hmm. Did in one line you |
|
|
65:28 | just type in chat. Yeah, do that. This one's pretty |
|
|
65:33 | Yeah. Stop sharing. I don't what to do with it. Mm |
|
|
65:40 | . Right. Yeah, that's the answer I think. Yeah. |
|
|
65:47 | If you want 74, um, can simply do that using the colon |
|
|
65:51 | . Right. And with the increment two, Alright, for the second |
|
|
65:58 | you can just probably try to Yeah, it's a little bit hard |
|
|
66:02 | explain everything. Yeah. Just try put in the chat. Um or |
|
|
66:08 | easy way as I can go through solution and maybe you guys can check |
|
|
66:12 | and if you happen to have a solution, let me know. |
|
|
66:18 | So problem too. If you want define a vector again, just use |
|
|
66:23 | elements based ah Like this. If want to add 16 to each |
|
|
66:31 | that's simple. Offly an addition The next thing was to add 3 |
|
|
66:37 | only the odd indexed elements. So that or was it even or |
|
|
66:45 | Okay, interesting. I did it even I don't know why I did |
|
|
66:48 | , but anyway, For that, simply created a vector that started from |
|
|
66:54 | all the way to length of a yeah, so that contained all the |
|
|
67:04 | all the even indexes and then I provided that vector as an input um |
|
|
67:10 | the scripting syntax and added three to . So that's basically what it does |
|
|
67:16 | adds three to all the even numbers indexed elements there. You can do |
|
|
67:22 | same thing for odds um to perform square root, you can simply do |
|
|
67:31 | dot and they and the caret operator negative power of one by two, |
|
|
67:39 | computes the square root. Or otherwise can simply use the function sq. |
|
|
67:43 | in medlab and again then to compute wise, square of each element. |
|
|
67:49 | you can do dot carrot and to the square of each element. |
|
|
67:58 | I'll post the solutions as well on on the on the blackboard. So |
|
|
68:01 | don't have to worry if you miss . Alright, let's see if you |
|
|
68:05 | can get through exercise three and Mhm wow. And note that here |
|
|
69:08 | and Y are column vectors. There a apostrophe after that. After their |
|
|
69:14 | of their column vectors. So that's way you can create a column |
|
|
69:21 | If you don't want to write semi after everything, you can just declare |
|
|
69:25 | row vector and put apostrophe after Mhm. Right. Mhm. |
|
|
70:35 | Mhm. What? All right. that was enough time to go through |
|
|
73:47 | of them. Mm hmm. Um right. So the third problem. |
|
|
73:55 | again we defined X and Y as vectors. So that's 3 to 684135 |
|
|
74:01 | X. And Y. The first said at the some of the elements |
|
|
74:06 | X to Y. So you have first perform some of all the elements |
|
|
74:12 | X and then add that's some to of the element of why And to |
|
|
74:19 | that, that the simple statement that needed to do was why? Plus |
|
|
74:25 | sum function that had X as the . So some of x is the |
|
|
74:32 | huh. Some of all the elements X. And then add that to |
|
|
74:36 | . And since plus is already a wise operations. So you don't need |
|
|
74:41 | write dot plus. It's simply So that's first and raise each element |
|
|
74:49 | X to the power specified by corresponding in Y. So that's again a |
|
|
74:55 | X dot and then carried Y. that's element wise power operations. So |
|
|
75:04 | zero powered Y zero or I should X one? Power Y one, |
|
|
75:08 | two, power Y two and so . So that's this statement performs that |
|
|
75:15 | similarly. If you want to perform element wise division, that's why |
|
|
75:21 | And the division operator X element wise is dot uh star of Y. |
|
|
75:30 | And then Added the elements in Z and assign the variable, assign it |
|
|
75:36 | variable w. So again, performing is just simply calling the function sum |
|
|
75:42 | in case anyone used loops to do . That's also right. But using |
|
|
75:48 | some function is a rather straightforward Any questions on that? All |
|
|
76:00 | For exercise four. Ah It was just using the colon operator correctly. |
|
|
76:08 | first it's just a series of even starting from two. So here I |
|
|
76:14 | Now I use the colon operator to the initial value increment of two and |
|
|
76:19 | till 10. So that's a serious of even numbers. If he wanted |
|
|
76:27 | reversed kind of vectors starting from Going all the way to -4. |
|
|
76:33 | can provide the initial value of stem decree mint of two. So that's |
|
|
76:39 | and the final value is -4. that gives you a vector starting from |
|
|
76:44 | , going Back to -4. Uh anyone get the 3rd and 4th |
|
|
76:52 | Right. Yes. Okay, Yeah, that was a little bit |
|
|
77:01 | one if you haven't used these ones . So here are the simple things |
|
|
77:05 | notice is the enumerators in all the is one. So that's the simple |
|
|
77:12 | . And then the denominator again starts one. So if I can write |
|
|
77:16 | as one by one as well. ? The denominators start from one and |
|
|
77:20 | by one every time we go. simple. And the simple way to |
|
|
77:24 | it is having one as the numerator then element wise divide, divide and |
|
|
77:32 | denominator is simply A vector going from to 10 And that gives you that |
|
|
77:40 | of one x 1, one x and so on. And in the |
|
|
77:45 | 1 you have basically 0x1, you say it. So numerator goes from |
|
|
77:51 | to all positive whole numbers and numerator from one to positive whole numbers. |
|
|
78:00 | again the numerator here, rather than one. In the previous cases you |
|
|
78:04 | have a vector of 0-10 and then wise divide and the nominator goes from |
|
|
78:10 | . So that gives you that kind a vector. There any questions on |
|
|
78:18 | comments, were there Number three Right. The scalar gets promoted to |
|
|
78:25 | vector automatically. Right? Yes, you're divided by a vector basically. |
|
|
78:33 | , extending something networks. Alright. think we have just 558 minutes. |
|
|
78:44 | ? Basically should stop now. that's fine. I have dated have |
|
|
78:50 | Guatemala after this class. That's alright stop 10 minutes before they have. |
|
|
78:59 | you. Yeah. And you know questions or send the email if you |
|
|
79:06 | them otherwise and well not otherwise, on Wednesday will be combined lecture classroom |
|
|
79:13 | . All taxes. Yeah. And sure everyone joins the prologue group. |
|
|
79:17 | don't think many people have joined Okay. Yeah. All right, |
|
|
79:25 | you for today. Thank you. bye. We should stop recording here |
|