If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

# Expressing a quadratic form with a matrix

## Video transcript

hey guys there's one more thing I need to talk about before I can describe the vectorized form for the quadratic approximation of multivariable functions which is a mouthful to say so let's say you have some kind of expression that looks like a times x squared and I'm thinking of X as a variable times B times XY Y is another variable plus C times y squared and I'm thinking of a b and c is being constants and x and y as being variables now this kind of expression has a fancy name it's called a quadratic form quadratic form and that always threw me off i always kind of like what what does form mean you know i know what a quadratic expression is in quadratic typically means something is squared or you have two variables but why do they call it a form and basically it just means that the only things in here are quadratic you know it's not the case that you have like an X term sitting on its own or like a constant out here like 2 and you're adding all of those together instead it's just you have purely quadratic terms but of course mathematicians don't want to call it just a purely quadratic expression instead they have to give a fancy name to things so that it seems more intimidating than it needs to be but anyway so we have a quadratic form and the question is how can we express this in a vectorized sense and for analogy let's think about linear terms where let's say you have a times X plus B times y and I'll throw another variable in there another constant times another variable Z if you see something like this where every variable is just being multiplied by a constant and then you add terms like that to each other we can express this nicely with vectors where you pile all of the constants into their own vector a vector containing a B and C and you imagine the dot product between that and a vector that contains all of the variable components XY and Z and the convenience here is then you can have just a symbol like a V let's say which represents this whole constant vector and then you can write down take the dot product between that and then have another another symbol maybe a bold-faced X which represents a vector that contains all of the variables and this way your notation just kind of looks like a constant times a variable just like in the single variable world when you have a constant number times a variable number it's kind of like taking a constant vector times a variable vector and the importance of writing things down like this is that V could be a vector that contains not just three numbers but like hundred numbers and then X would have a hundred corresponding variables and the notation doesn't become any more complicated it's generalizable to higher dimensions so the question is can we do something similar like that with our quadratic form because you can imagine let's say we started introducing the variable Z then you would have to have some other term you know some other constant times the X z quadratic term and then some other constant times the Z squared quadratic term and another one for the Y Z quadratic term and we get out of hand and as soon as you start introducing things like 100 variables it would get seriously out of hand because there's a lot of different quadratic terms so we want a nice way to express this and I'm just going to kind of show you how we do it and then we'll work it through to see why it makes sense so usually instead of thinking of B times X Y we we actually think of this as 2 times some constant times X Y and this of course doesn't make a difference you would just change what B represents but you'll see why it's more convenient to write it this way in just a moment so the vectorized way to describe a quadratic form like this is to take a matrix a two-by-two matrix since this is two dimensions where a and C are in the diagonal and then B is on the other diagonal and we always think of these as being symmetric matrices so if you imagine kind of reflecting the whole matrix about this line you'll get the same numbers so it's important that we have have that kind of symmetry and now what you do is you multiply the vector the variable vector that's got XY on the right side of this matrix and then you multiply it again but you kind of you turn it on its side so instead of being a vertical vector you transpose it to being a horizontal vector on the other side and this is a little bit analogous to you know having two variables multiplied in you have two vectors multiplied in but on either side and this is a good point by the way if you are uncomfortable with matrix multiplication to maybe pause the video go find the videos about matrix multiplication and kind of refresh or learn about that because moving forward I'm just going to assume that it's something you're familiar with so going about computing this first let's tackle this right multiplication here we have a matrix multiplied by a vector well the first component that we get we're going to multiply the top row by each corresponding term in the vector so it'll be a times X a times X plus B times y plus B times that second term y and then similarly for the bottom term we'll take the bottom row and multiply the corresponding term so B times X B times X plus C times y C times y so that's what it looks like when we do that right multiplication and of course we've got to keep our transposed vector over there on the right on the left side so now we have this is just a two by one vector now and this is a one by two you could think of it as a horizontal vector or a you know one by two matrix but now when we multiply these guys you just kind of line up the corresponding terms you'll have X multiplied by that entire top expression so X multiplied by ax plus B Y a X plus B Y and then we add that to the second term Y multiplied by the second term of this guy which is BX plus C Y so Y multiplied by B X plus C Y and all of these are numbers so we can simplify it once we start distributing the first term is x times a times X so that's a x squared and then the next term is x times B times y so that's B times X Y over here we have Y times B times X so that's the same thing as B times X Y so that's kind of why we have why it's convenient to write a 2 there because that naturally comes out of our expansion and then the last term is y times C times y so that's C Y squared so we get back the original quadratic form that we were shooting for you know ax squared plus 2b XY plus C Y squared that's how this entire term expands as you kind of work it through you end up with the same quadratic expression now the convenience of this this quadratic form being written with a matrix like this is if we can write this more abstractly and instead of writing the whole matrix in you could just let a letter like M represent that whole matrix and then take the vector that represents the variable may be like a bold-faced X and you would multiply it on the right and then you transpose it and multiply it on the left so typically you denote that by putting a little T as a superscript so X transpose multiplied by the matrix from the left and this expression this is what a quadratic form looks like in vectorized form and the convenience is the same as it was in the linear case just like v could represent something that had a hundred different numbers in it and X would have a hundred different constants you could do something similar here where you can write that same expression even if the matrix M is super huge let's just see what this would look like in a three dimensional circumstance so uh actually I'll need more room so I'll go down even further so we have X transpose multiplied by the matrix multiplied by X bold-faced X and let's say instead this represented you know you have X then Y then Z our transpose vector and then our matrix our matrix let's say it was a b c d e f and because it needs to be symmetric whatever term is in this spot here needs to be the same as over here kind of when you reflect it about that diagonal similarly see that's going to be the same term here and e would be over here so there's only really six free terms that you have but it fills up this entire matrix and then on the right side we would multiply that by x y z now i won't work it out in this video now but you can imagine actually multiplying this matrix by this vector and then multiplying the corresponding vector that you get by this transpose vector and you'll get some kind of quadratic form with three variables and the point is you'll get a very complicated one but it's very simple to express things like this so with that tool in hand in the next video I will talk about how we can use this notation to express the quadratic approximations for multi variable functions see you then