Chapter 19. Optimization problems
Now that we understand both critical points of and regions , we turn our attention to the problem of finding global minimums and maximums.
§19.1 [TEXT] The easy and hard cases
Suppose you have a function that you can compute for, and a region . We’re going to distinguish between two cases:
- The easy case is if has dimension as well. The rule of thumb says there should be zero “=” constraints.
- The hard case is if has dimension . Rule of thumb says there should be one “=” constraint. In the hard case, we will use Lagrange multipliers.
We won’t cover the case where has dimension or less in 18.02 (i.e. two or more constraints), although it can be done.
§19.2 [RECIPE] The easy case
Suppose you want to find the optimal values of over a region , and has dimension .
- Figure out the boundary and limit cases for the region . (You don’t need to look at for this step.)
- Evaluate on all the critical points of in the region .
- Evaluate on all the boundary points of in the region .
- Evaluate on all the limit cases of in the region .
- Output the points in the previous steps that give the best values, or assert the optimal value doesn’t exist (if points in step 3 do better than steps 1-2).
If there are any points at which is undefined, you should check those as well. However, these seem to be pretty rare for the examples that show up in 18.02.
In 18.01, you probably only optimized functions over intervals , in which case the boundary was just two inputs and . In 18.02, the situation is completely different: the boundary (if it is nonempty) will often have infinitely many points. So it can take a lot of work to do the boundary case! Don’t underestimate the possible complexity of Step 2.
In particular, Step 2 might even require you to use Lagrange multipliers, i.e. that one step of the easy case is an entire instance of the hard case. For that reason, the naming “easy case” and “hard case” is a bit of a misnomer.
We’ll start with an example with no boundary for which the limit cases are easy to examine, so Step 2 and Step 3 are mostly harmless. Later on we’ll do more examples where Step 2 and Step 3 are more intricate.
Compute the minimum and maximum possible value, if they exist of
over .
Solution. The region is the first quadrant which is indeed two-dimensional (no constraints), so we’re in the easy case and the recipe applies here. We check all the points in turn:
has no boundary and limit cases when any variable approaches or .
To find the critical points, calculate the gradient
and then set it equal to . This gives us the simultaneous equations
This implies or (we have in , so we’re not worried about division by zero) and so the only critical point is .
The region has no boundary, so there are no boundary points to check.
The region has four different kinds of limit cases:
- .
In fact all four of these cases cause . In each of the first two cases, the term in causes . In the case , the term causes . In the case , the term causes .
Putting these together:
- The global minimum is , at which .
- There is no global maximum, since we saw limit cases where .
§19.3 [TEXT] Lagrange multipliers
Let be a function we’re optimizing over some region . We now turn to the case where , is dimension , because of a single constraint of the form or .
We need a new definition of critical point. To motivate it, let’s consider a particular example in Figure 40. Here , and
- , and
- is the blue level curve shown in the picture below;
- is just the level curve (no further or constraints).
Trying to optimize subject to in this picture is the same as finding the points on the level curve which are furthest or closest to the origin. I’ve marked those two points as and in the figure. The trick to understanding how to get them is to also draw the level curves for that pass through and : then we observe that the level curves for that get those minimums and maximums ought to be tangent to at and .
Now how can we check whether there’s a tangency? Answer: look at the gradient! We expect that and , at the points and , should point in the same direction. So that gives us the strategy: look for the points where and point the same way.
I don’t think the following term is an official name, but I like it, and I’ll use it:
An LM-critical point is a point on the curve/surface such that either
- for some scalar ; OR
- .
Note that there are two possible situations. If you want, you can think about this as requiring that and are linearly dependent, so it’s only one item. However, in practice, people end up usually breaking into cases like this.
The parameter is the reason for the name “Lagrange multipliers”; it’s a scalar multiplier on . Personally, I don’t think this name makes much sense.
Also, some sources will define an LM-critical point in the following (in my opinion, more confusing) way. Let’s say is a three-variable function. Define a four-variable “Lagrangian function” . Then an LM-critical point is a point for which either or , i.e. a normal critical point of . It can be checked this is equivalent to the original definition, but I personally find this unnatural. However, if you like this definition, feel free to use it instead.
Now that we have this, we can describe the recipe for the “hard” case. The only change is to replace the old critical point definition (where ) with the LM-critical point definition.
§19.4 [RECIPE] Lagrange multipliers
Suppose you want to find the optimal values of over a region , and has dimension due to a single constraint for some .
- Figure out the boundary and limit cases for the region . (You don’t need to look at for this step.)
- Evaluate on all the LM-critical points of that lie on the region .
- Evaluate on all the boundary points of of the region .
- Evaluate on all the limit cases of of the region .
- Output the points in the previous steps that give the best values, or assert the optimal value doesn’t exist (if points in step 3 do better than steps 1-2).
If there are any points at which or are undefined, you should check those as well. However, these seem to be pretty rare for the examples that show up in 18.02.
Again, this is the same recipe as Section 19.2, except we changed “critical point” to “LM-critical point”.
Remember how finding critical points could lead to systems of equations that required quite a bit of algebraic skill to solve? The same is true for Lagrange multipliers, but even more so, because of the new parameter that you have to care about. So the reason this is called the “hard case” isn’t because the 18.02 ideas needed are different, but because the algebra can become quite involved in finding LM-critical points.
In fact, in high school math competitions, the algebra can sometimes become so ugly that the method of Lagrange multipliers is sometimes jokingly called “Lagrange murderpliers” to reflect the extreme amount of calculation needed for some problems.
Compute the minimum and maximum possible value, if they exist, of
over satisfying the condition .
Solution. We carry out the recipe.
The region is two-dimensional, consisting of strict inequalities and the condition . So there is no boundary, but there are limit cases if any variables approaches or .
To find the LM-critical points, we need to compute both and . We do so:
Now, there are no points with in the region , because in all the variables are constrained to be positive. So we now solve the system
and see what values it takes.
The trick to solving the system of equations is to divide the first two to get rid of the parameter , which we don’t really care about, to get
So we must have . Similarly, we find and .
Hence the LM-critical point must have . Since , it follows the only LM-critical point is . Evaluating here gives .
The region has no boundary, because no or constraints are present.
The region has limit cases when any of the variables either approach or . However, remember that . So if any variable approaches , some other variable must become large. Consequently, in every limit case, we find that .
Collating all these results:
- The unique global minimum is at which .
- There is no global maximum.
§19.5 [TEXT] Advice for solving systems of equations (reprise)
Back in Section 17.5, when we were finding all the critical points, I reminded you to be careful about division-by-zero, handle cases carefully, and gave you some advice for solving systems. Solving the system for LM-critical points is a similar situation: systems of equations are hard, and you have to treat it like a self-contained high school algebra puzzle.
For systems of equations generated by Lagrange multipliers, there’s a new feature: a variable whose value is never used, but which appears in every equation besides the constraint . So a couple tips specific to Lagrange Multiplier systems:
In addition to the tips in Section 17.5, here are some strategies that sometimes help:
- It might make sense to try to get rid of ASAP, if that’s easy to do. After all, we don’t actually care what is.
- Alternatively, you can try to kill every variable except ! This is commonly used if each equations involves only one non- variable. That is, solve for in terms of ; do the same for and . Then plug these in the original constraint equation to solve for , and hence extract .
Note the second advice bullet is the opposite of the first advice bullet! Again, systems of equations can’t be solved by blindly following recipes. You should use whatever method you think makes sense for the given problem. You don’t need anyone’s permission to use so-and-so approach.
Remember: watch out for division by zero! For example, if you get to the equation , for example, this implies EITHER OR .
During the 2024 midterm, an equation like this appeared as part of a step in a standard Lagrange multipliers question. Something like 50%-80% of students who got this equation would forget one of the two cases (which one they forgot about varied). Don’t let this be you! Whenever you try to cancel, check for division by zero!
Here’s an example where a good idea is to kill ASAP:
Solution. We want to minimize the function subject to the constraint .
The constraint region has no boundary, but limit cases along the line if either and and either and .
Computing the gradients gives
Note is never . Thus, the Lagrange multiplier equation becomes:
This gives the following system of equations:
Combining these two equations gives us an easy way to get rid of :
Cancel on both sides gives us :
Now substitute into the constraint to get:
In other words, the only LM-critical point is , at which point we have
There is no boundary to check.
If any of the variables goes to (and hence the other goes to ), the value of will become large too.17
In conclusion, the global minimum is .
And here’s an example where we kill every variable except :
Solution. We want to minimize the function subject to the constraint .
The region is a plane with no boundary but limit cases if any variable becomes .
Let’s find all the LM-critical points. We start by calculating all the gradients:
Note the gradient is never . Thus, the Lagrange multiplier equation becomes:
or
Let’s get rid of every variable besides , by solving in :
Now substitute , , and into the constraint :
Now that we have , plug back in to get :
This gives a single LM-critical point , where .
There are no boundary cases to consider.
The limit cases are if one of the variables goes to . However, in such a situation obviously becomes large, so there are no minimums in the situation.
In conclusion, the global minimum is .
We show a way you can skip all the calculus steps in the previous problem if you can see how to rewrite the question as a geometry one. This approach is so clever that you don’t even need to find ; it will directly tell you the minimum value. Don’t try this on an exam unless you really know what you’re doing.
Let be a point. Let denote the plane . The magic trick is to rewrite
where . In other words, is a shift of the squared distance of from . So actually, the global minimum we found is the point on the plane closest to .
But if all you care about is the distance from to the , then using calculus is overkill: instead use the recipe from way back in Section 5.6:
So the minimum is
Thus, an extremely clever student could have bypassed the entire problem by translating it into a geometry question. Don’t worry, you won’t be expected to come up with something like this in 18.02.
To top all that of, here is a Lagrange multipliers example that requires considering tons of cases. This is probably too lengthy of a calculation for 18.02 because of the amount of arithmetic required; it’s here just to illustrate.
Solution. The region has no boundary nor limit cases. So, we will only focus on calculating the LM-critical points.
The gradients of and are given by
We begin by simplifying each equation:
becomes: . This gives two possibilities:
- , or
- (assuming ).
becomes: . This gives two possibilities:
- , or
- (assuming ).
becomes: . This gives two possibilities:
- , or
- (assuming ).
This gives a total of eight cases! We will go through them all individually.
- Case 1 where , ,
From the constraint , we get:
Thus, .
- Case 2 where , ,
From the constraint , we get:
Thus, .
- Case 3 where , ,
From the constraint , we get:
Thus, .
- Case 4 where , ,
From the constraint , we solve using and . Equating these, we get:
Substitute into the constraint:
This simplifies to:
Thus, .
- Case 5 where , ,
From the constraint , we solve using and . Equating these, we get:
Substitute into the constraint:
Thus, , and:
- Case 6 where , ,
From the constraint , we solve using and . Equating these, we get:
Substitute into the constraint:
Thus, , and:
- Case 7 where , ,
Equating the three expressions for :
From , we get , and from , we get . Substitute into the constraint:
Thus, , and:
Since is a square, this could be written more simply as
- Case 8 where , ,
- This doesn’t yield a valid solution because it doesn’t lie on the constraint .
Hence there are a whopping total of LM-critical points. They are:
- , , ,
- , , ,
- , , ,
- , , .
- , , ,
- , , ,
- , , .
When searching for the maximum, we should always take for to maximize ; similarly, the minimum uses only for . Note also that plugging in all ‘s is the negative of plugging in all ’s. So this reduces us from cases to just . If we actually try all seven, we find that the last one is the optimal one; that is, the maximum and minimums are
§19.6 [TEXT] Example of easy case with a “common-sense” boundary
As we alluded to earlier, the boundary of the so-called “easy case” can have infinitely many points, so you cannot just plug them in one by one to inspect them all. In some situations, it will still be doable just by inspection, because the function is really easy to describe on the boundary. We give one such example below.
Compute the minimum possible value of
in the first quadrant .
Solution. Follow the recipe:
The first quadrant has limit cases if either or . The boundary consists of two rays: the positive axis (from due east) and the positive axis (from due north).
We calculate the critical points. The gradient is given by
Setting the gradient to the zero vector, we need to solve the system
which is an easy linear system. If we let from the first equation, we get
Since we are working in the first quadrant where , this value is not valid. Therefore, there are no critical points in our region .
As we saw, we have two boundaries. There are infinitely many points on the positive and axis, so we cannot just plug them all in one by one. In principle, you could redo the entire easy-case recipe for each boundary parts, and it will work.
However, luckily, the function is quite easy to analyze on each part, and we can do it with just high school algebra, no calculus needed. This way we don’t need to go through the whole recipe again.
- The boundary of and
Substitute into the function: . In other words, we need to see what the smallest value of
could be. You could use the derivative of , but I think the fastest thing to do is actually complete the square: the function
obviously has the smallest value at . (And and are both worse.)
- The boundary of and
Substitute into the function:
It’s obvious that is minimized at . (Note that is worse.)
In the limit case where either and it’s clear that .
In conclusion, the best value is actually the one from Step 2: we have being the smallest possible value.
§19.7 [TEXT] Example of easy case that ends up using Lagrange multipliers for the boundary
Now here’s a case where the boundary requires Lagrange multipliers. So, it’s really a hard-case optimization problem within an easy-case optimization problem. If you’ve seen the movie Inception, yes, one of those.
Compute the minimum and maximum possible value, if they exist, of
over the region .
Solution. At first glance, this seems like it should be in the easy case! The region consisting of the closed ball is indeed three-dimensional. But the reason this sample question is in this section is because we will find that checking the boundary case requires another application of Lagrange multipliers.
Let’s carry out the easy case recipe.
There are no limit cases, but a boundary , the unit sphere (not filled).
First let’s find the critical points of . Write
Solving the insultingly easy system of equations we see the only critical point is apparently . The value there is .
The boundary of is , the unit sphere; we denote this sphere by . So now we have to evaluate on this boundary. The issue is that there are too many points on this unit sphere! We can’t just check them one by one. And unlike the previous example, the function is not simple enough that we can use common sense to deal with it.
Therefore, we will use Lagrange multipliers with the constraint function to find the minimum possible value of on this new region .
The new region has no boundary and no limit cases.
Let’s find the LM-critical points for on . Take the gradient of to get
The only point at which is which isn’t on the sphere , so we don’t have to worry about the case. Now we instead solve
This requires some manual labor to solve, because there are lots of cases. The equation for says that
and similarly for and :
A priori, this seems like it will require us to take a lot of cases. However, we can take advantage of symmetry to reduce the amount of work we have to do. The trick is to get rid of as follows: Observation: All the nonzero variables , , should have the same absolute value. To spell it out:
- If all three variables are nonzero, then (because as well).
- If two variables are nonzero, then their absolute values are by the same token.
- And if only one variable is nonzero, it is .
(Note of course that does not lie on .) Think about why this works.
So there are 26 LM-critical points given by the following list:
- ; there are 8 points in this case. The -values are all .
- ; there are 4 points in this case. The -values are all .
- ; there are 4 points in this case. The -values are all .
- ; there are 4 points in this case. The -values are all .
- ; there are 2 points in this case. The -values are all .
- ; there are 2 points in this case. The -values are all .
- ; there are 2 points in this case. The -values are all .
Phew! Okay. The other cases are much shorter:
has no boundary to consider.
has no limit cases to consider.
has no limit cases to consider.
Okay, marathon done. Collate everything together. The values of we saw were , , and , and there were no limit cases of any sort. So:
- is the global minimum.
- are the global maximums.
§19.8 [SIDENOTE] A little common sense can save you a lot of work
If you step back and think a bit before you try to dive into calculus, you might find that having a bit of “common sense” might save you a lot of work. What I mean is, imagine you gave the question to your high school self before you learned any calculus at all. Would they be able to say anything about what properties the answer could have? The answer is, yes, pretty often.
Let’s take the example we just did: we asked for the minimum and maximum of
over the region . To show the recipe, I turned off my brain and jumped straight into a really long calculation. But it turns out you can cut out a lot of the steps if you just use some common sense, not involving any calculus:
- The minimum is actually obvious: it’s just , because fourth powers are always nonnegative! So is obvious even to a high schooler, and .
For the maximum you can actually see a priori that it must occur on the boundary . Why is this? Suppose you had a point in the strict interior with . Then is some number. But you could obviously increase the value of just by scaling the absolute value of things in ! For example, if I double all the coordinates of to get , then . As long as stays within the sphere, this will be a better value.
So any point in the interior is obviously not a maximum: if you have a point strictly the interior, you could increase by moving farther from the origin.
That means if we had used a bit of common sense, we could have gotten the minimum with no work at all, and we could have skipped straight to the LM step for the maximum. So if you aren’t too overwhelmed by material already in this class, look for shortcuts like this when you can.
We saw the minimum is obviously if you just thought about it. In fact, you can also similarly find the maximum with no calculus at all if you realize the answer should be .
Here’s how. What we’re trying to prove is that
whenever . Because and are nonnegative, it’s obvious that . But in fact it’s easy to see that
Similarly, and . Thus
§19.9 [SIDENOTE] Compactness as a way to check your work
This is an optional section containing a nice theorem from 18.100 that could help you check your work, but isn’t necessary in theory if you never make mistakes. (But in practice…)
I need a new word called “compact”, and like before, it’s beyond the scope of 18.02 to give a proper definition. However, I will hazard the following one: for 18.02 examples, is compact if there are no limit cases. That is,
- All the constraints are , , or ; no or ,
- None of the variables can go to .
Then the theorem I promised you is:
This works in both the easy case (no Lagrange multipliers) and the hard case (with Lagrange multipliers).
Here’s some examples of how this theorem can help you:
Suppose you are asked to optimize a continuous function on the square , . We saw this square has no limit cases. Then the compact optimization theorem promises you that the answer “no global minimum” or “no global maximum” will never occur.
Suppose you are asked to optimize a continuous function on the sphere (which means you are probably going to use Lagrange multipliers). We saw this sphere has no limit cases (and not even a boundary). Then the compact optimization theorem promises you that the answer “no global minimum” or “no global maximum” will never occur.
Suppose you are asked to optimize a continuous function on the closed ball , like in the last example. This closed ball also has no limit cases, so the compact optimization theorem promises you that the answer “no global minimum” or “no global maximum” will never occur.
§19.10 [RECAP] Recap of Part Foxtrot on Optimization
We introduced the notion of critical points as points where .
- We saw that critical points could be local minimums, local maximums, or saddle points.
- We introduced the second derivative test as a way to tell some of these cases apart, although the second derivative test can be inconclusive.
- We talked about how regions have dimensions, limit cases, and boundaries. Although we didn’t give a proper definition, we explain rules of thumb that work in 18.02.
- For optimization problems with no constraints, we check the critical points, limit cases, and boundaries.
- For optimization problems with one constraint, we check the LM-critical points, limit cases, and boundaries.
- Finding either critical points or LM-critical points involves solving systems of equations. There is no fixed recipe for this, but we gave some possible strategies that you can try depending on the exact shape of the system you get.
§19.11 [EXER] Exercises
Exercise 19.1. Let be the triangle in the -plane with vertices , , . For what point in the plane is the sum
as small as possible?
Exercise 19.3 (Suggested by Ting-Wei Chao). Compute the global minimum of the function