[MUSIC] There’re two types of division, the so-called “matrix division”, and “array division”. We're going to take up array division first. And there are two types of array division. Here's how you divide X and Y. First of all, there's X./Y, and then there's the X.\Y. In the first case, it kind of looks like X is over Y, so that's X over Y. And the other one sort of looks like X is under Y, so we'll call that X under Y. And we'll explain what both of those mean. Here's an example. You see an X and a Y. They're both the same shape and size. That's required for array division. And now, let's suppose we use that first example, X./Y, X over Y, and put that in Z. So what does Z look like? Well, over on the right side, we see X written out and Y written out, separated by the dot slash operation. And over on the left, we see the result. Let's look at the first element on the top row. We see 1 slash 2. Over on the right, we see a 1 and a 2 in those positions. So 1 divided by 2 equals 1 over 2, and that's what we get for Z. Of course, MATLAB will carry that out and give you 0.5. Every single one of the elements in Z is equal to the corresponding element in X divided by the corresponding element in Y, and that's what dot slash Y means. Here's what it looks like, the results, in MATLAB, when all these divisions are carried out. And when they're assigned to Z, this is what Z looks like. No surprise there. And what about the backslash case? Well, everything's the same except that 1, instead of being divided by 2, is divided into 2. This is the 1 under the 2 case. So 1 under 2, what do you think that's going to be? Well, it's 2 instead of one-half. 1 goes into 2 two times. Same thing happens for every element at every position. Here's 1 over 2. I mean, here's 1 under 2, and we're showing you that it's the same as 2 over 1. And here, the number is carried out to four decimal places, and here's what you see when it's assigned to Z. You should try some examples of your own to get used to this array division, but don't forget the dot. If you leave the dot out, then you are in a strange new territory called “matrix division”. Matrix division has different rules completely. In fact, it's quite a complicated concept in linear algebra, and we're not covering it here. But if you want to check it out, you can try the advanced concepts in the textbook and get a detailed explanation. Now, let's look at exponentiation. 2 caret 3. The caret is the exponentiation operator, and 2 to the 3rd power is what that means. 2 to the 3rd power is 8. Not surprising. But what might be surprising is that you can do exponentiation operation with arrays. Array exponentiation works sort of like array multiplication. At least the rules are the same. Let's look at X, 1, 2; 3, 4. And let's let N equal 6, 0.5; -1, 2, x dot caret N is the array exponentiation operation. The dot means array exponentiation, just like the dot means array multiplication when we have dot star. And let's look at the result. What this means is the first element of X on the first row, 1, is raised to the first element on the first row of N. So 1 to the 6th power of course is 1. The second element on the first row of X is raised to the power of the second element on the first row of N. So we have 2 raise to the 1/2 power. Well, that's the square root of 2. Down here, we have 3 raised to the -1 power. Well, that's 1/3, and 4 raised to the 2 power, which is 16. So that's array exponentiation. There's no real surprises there. As you may have guessed, if we go to matrix exponentiation, things are going to be more complicated, just like they were more complicated when we went from array multiplication to matrix multiplication. We'll only cover one case, and that's the case in which the second operand is actually a scalar. Let's do that. X matrix-exponentiation 3. What this means is X is multiplied by itself using matrix multiplication three times. So it's the same as this: X times X times X, and you can see you get the same result. It's not possible to raise to X to a power like this, unless X is a square matrix. That's true because, as you may remember for matrix multiplication, the width of the first matrix has to be equal to the height of the second matrix. Since both these matrices are X, that means the width of X has to be equal to the height of X. And that's the definition of a square matrix. We've seen that there are strict rules on the sizes, and shapes of the operands for both array and matrix operations. For array operations, the matrices must have the same size and shape, while for matrix operations the width of the first matrix must equal the height of the second one. Now, we're going to see that MATLAB waives these rules when one operand is a scalar. We'll show how it works with some examples. I'm going to gin up a couple of matrices first. Here's my favorite, [CLICKING] and it's so easy to type. And another one. [CLICKING] Just picking some random digits here. And we'll start with addition. You’ll remember that the addition of two matrices requires that they have the same size and shape. A and B here are both 2 by 3, so we can add them. And let's do it. [CLICKING] There, no problem. But we can violate the same-size-and-shape rule if one operand is a scalar. So let's do that one. [CLICKING] There. I've got the matrix A which is 2 by 3, and I've added a scalar, which by the way is a matrix that's 1 by 1. And 2 by 3 doesn’t match 1 by 1, but no error message. And what happened? Well, you can see here, if we look at A, the first element is a 1. We've added a 3 to that 1 to get a 4. Second element on the first row is a 2. We've added a 3 to that, we've added a 3 to every one of them. And that's the general idea for any arithmetic operation that mixes a scalar and a matrix. The operation is repeated for each element using the scalar as one of the operands. And the scalar can come first or second as for example [CLICKING] there. Which, as you would expect, does the same thing as A plus 3. Let's do some more examples. A minus 1 subtracts 1 from each element. 2 dot star A multiplies each element by 2. 2 star A, the matrix multiplication version, does the same thing. And we can divide too. Let's see, A./2, array division of A by 2, divides each element by 2.
. And you can go the other way: . 2./A [CLICKING] divides each element of A into 2.
. The matrix versions of division with a scalar and
. a matrix don't work though, so 2, say, divided by A.
. MATLAB that doesn't like that. . And A under 2, also gives an error. Finally, the array version of exponentiation works as you might expect it to. A dot caret 2 applies that exponent, 2, to each element of A, so it squares each element. And it works the other direction too. Let's look at A again so we can remember what's in there. Here, we have 2 because we've raised 2 to the 1 power here. Here, we have 4 because we've raised 2 to the 2 power. You have an 8 because we've raised 2 to the 3 power, and so on until we get all the way down here to 64,
which is 2 raised
to the 6th power
. So array exponentiation works fine with a scalar. But as we've just seen, the matrix version
of exponentiation
is kind of picky
. A caret 2 is no good unless A is square,
… and of course, A is 2 by 3, so
it's not square
. All these special cases with scalars may require a little memorization. It's just like idioms in a spoken language, but very little memorization for two reasons. First, the cases of addition, subtraction and multiplication work exactly the same as they do in ordinary mathematical calculations. So you might be familiar with them already. And second, you can always try out unfamiliar cases on small examples to see whether they work, and what they do. That's what I do. [MUSIC] [APPLAUSE]