 So we know how to maximize or minimize a function, even if that function may have more than one variable that it depends on. But what we've seen is that finding the max or the minimum of that function isn't necessarily what we want to do. In a science problem, there's often some constraints on the problem. Not any solution is a physically relevant solution. We might have constraints, for example, that the energy of the system might be conserved or that we might need to conserve the number of molecules in the system. Or as we saw with the heads and tails example, we might need to conserve the probability. Probabilities have to add up to 100%. So what we really want to be able to do is maximize or minimize a function subject to some constraints. So to keep things simple at first, let's start out with a purely mathematical example. In fact, we'll stick with the example we considered before. Let's take the function x squared plus 2y squared minus 6x plus 5. We want to find the minimum of that function. But now let's make it a slightly different problem. So we want to find the minimum, but we want to find a minimum subject to a particular constraint. Let's say we want to require that x and y have to add up to 6. We know there's a minimum of that function at the minimum, the minimum of that function happens to be 3 comma 0. At the minimum of that function, it doesn't obey the constraint. We want to find out of all the combinations of x and y that do obey this constraint, which of those gives the minimum value of the function. So there's a couple of ways to consider proceeding with this problem. And we'll consider two of them. The first one we'll consider in this video lecture is the one that might occur to most of you first. So it'll seem perhaps most natural. So our approach number one is let's consider using that constraint to eliminate a variable. If we have more than one constraint, we can use it to eliminate, use the multiple constraints to eliminate multiple variables. In this case, we have one constraint that tells us something about y relative to x and vice versa. So we can use this constraint. So if I rearrange that constraint, the constraint equation, x plus y equals 6, tells me that y always has to be 6 minus x. So this function of x and y, everywhere I see a y, I can insert this constraint equation. So plug that into my original equation, x squared, 2y squared. If x and y have to add up to 6, then y squared must be 6 minus x quantity squared. I can subtract x and add 5. That gives me my original expression, but now only for y values that obey the constraint. So this is the constrained version of the original equation, and I just have a little algebra to do. 6 minus x quantity squared is 36 minus 12x plus x squared. If I combine terms in that equation, I've got 2x squared in this parenthesized term and extra x squared over here, so that gives me 3x squared. So I've got 2 times negative 12, gives me negative 24x here, another minus 6 from here, so that's a total of minus 30x's, and then I've got 72 as a constant term and 5 additional, so that's plus 77. So that's just rewriting my constrained original equation. Of course, what we are aiming to do is minimize the function, find the minimum of that function. So the derivative of that function with respect to x, if I set that equal to zero, I'm looking for the place where the derivative of this function, or 6x minus 30, is equal to zero. So this is only true at the minimum. Certainly 6x minus 30 is not always equal to zero, but at the minimum that's true. If I rearrange that equation, 6x is equal to 30, or x is equal to 5. So that's x star, that's the value of x at the minimum, the value of the function when it's correctly obeying the constraint and it's at its minimum, and then y at the minimum is 6 minus that value of x that we've just determined, so 6 minus 5 is equal to 1. So what we've just figured out is the minimum of this function occurs at not 3,0, which is the unconstrained minimum of this function, the position where this function takes on its absolute lowest value, but 5,1 is the value of the function that obeys this constraint. So that'll make even more sense hopefully if I draw a picture for you. I'll attempt to make this picture somewhat to scale. So here's my function, exactly this function x squared plus 2y squared, so it's going to be a parabola pointing upwards, concave up in both x and y. The minimum of that function, the true minimum of the function is at 3,0. So directly above 3,0 this function has a minimum. So it's a parabolic function that has a minimum directly above 3,0, but that's not what we're interested in finding the bottom of this parabola. What we're interested in is finding the point on this function that obeys the constraint. So this constraint x plus y equals 6, there's a few ways I can obey that constraint. I can have x and y add up to 6 if I'm sitting at 6,0, or if I'm sitting at 0,6 or 3,3. So any point on the line connecting these points, those are x and y values that add up to 6. So those are the x and y values that obey the constraint. What I'm really interested in is if I calculate the value of the function at 6,0 or at 0,6 and so on, that gives me certain particular values of this function, draw that a little better to scale. So directly above this line on the x, y axis is a slice through this paraboloid that is the values of the original function that do obey the constraint. And what we're looking for is the spot on these constrained original function that does, in fact, obey that undergoes a minimum. So the minimum of the constraint function is here. And if I were to trace that point down, that point is what exists at 5,1. So the minimum of the absolute function without any constraints, maybe 3,0. But we're only interested in a subset of the points of that function, the ones that obey some constraint. And their minimum may be somewhere else entirely. So summing up what we've done so far, this is only method one of two. The next video lecture will cover the second approach for solving the same problem. But what we've done here is maybe the intuitive feeling thing to do of using the constraint, substituting it into the original expression, eliminating a variable. So there's no more y's left, and then minimizing that function. The downside with this approach is maybe the constraint we have isn't easy to solve algebraically, or maybe it's very tedious because our function doesn't just have one variable. Maybe it has three, or five, or ten, or a hundred different variables in it. And then doing the math of solving that constraint equation can be very difficult. So there are occasions where the second approach that we'll consider in the next video lecture will be the more reasonable way to go about it.