Optimizing Real-World Stuff (Explaining Calculus #10)

In the previous post in this series, I explained how you can use derivatives to locate maximizing and minimizing values for functions. Now, I will put that knowledge to use in concrete examples to show exactly how this works.

Example 1: Building a Fence

Imagine the following situation. You are a farmer, and you want to build a rectangular fence for your cows. You happen to live near a river, and you know your cows would never fall into the river. So, to save money, you decide to use the river as one of the “sides” of the fence. That way, you’ll only have to build three out of the actual fencing material. You’ve already decided that your fencing needs to contain 45,000 square feet of field so that your cows will have enough grass to graze on. Wanting to save money, you ask yourself… what is the least amount of fencing I have to buy to build this pen for my cows?

Notice we just used the word least. That’s just another word for minimizing something. That means we should be able to use calculus somehow. But how? Well Step 1 would be to clearly set up the thing you’re trying to minimize. As stated, we are trying to minimize the amount of fence material we buy. And what is the amount of fencing material? Well, that would be the total length of the three sides of the pen we have to build. To make this easier to visualize, let’s say the river runs north-south and we are building the pen to the right of the river. Since this is rectangular, two of the sides are going to be the same length (the top and bottom sides) and the third side (right side) could possibly be a different length. We will say the length of the top/bottom sides are x feet and the right-hand side has a length of y feet. Then the amount of fencing we need to use, which we will call P (stands for perimeter), is

P = x + x + y = 2x + y.

Ok, so far so good. We have a formula for P. But we have a problem. We can’t do a derivative yet, because there are too many variables. We need to find a way to “get rid of” the y… how? Well, let’s try to use the information about the area of the field we already know. The total area is going to be 45000. But the area of a rectangle is also always equal to xy. So,

\text{Area} = xy = 45000.

We can do something clever now. If we divide both sides by x, then we come to see that y = \dfrac{AAA}{x}. That means

P = 2x + y = 2x + \dfrac{45000}{x}.

That helped! Because now, we have just the one variable, x, on the right-hand side (we can also give P the new name P(x) to make it more clear that the variable is x). So we can take a derivative now! But before we do, we need to stop to remember why we are taking a derivative in the first place. Remember from the previous post that max and min values always occur either at a place where the derivative does not exist or where the derivative is equal to zero. So, once we take the derivative of P, our next step needs to be to catalogue these two potential options. First, the derivative of P. We can do this using the distributive rule and the polynomial rule for derivatives (which we discussed in part one of “Computing Derivatives”). Using these rules and simplifying a bit,

P^\prime(x) = \dfrac{d}{dx}[2x] + \dfrac{d}{dx}[45000 x^{-1}] = 2 x^{1-1} + (-1)*45000 x^{-1-1} = 2 - \dfrac{45000}{x^2}.

Now, we need to categorize ‘special points’ where we might find a max or min value. The only place where P^\prime(x) doesn’t make sense is at 0, but a rectangle with side length zero (remember, x is a side length!) doesn’t make any sense, so we can actually just ignore it. In other words, since x has to be a positive number anyways, x=0 is never even on our radar of possibilities. Having ruled out the ‘does not exist’ option, we need to solve the equation P^\prime(x) = 0. To simplify a bit, we can multiply both sides by x^2,

P^\prime(x) = 0 \iff 2 - \dfrac{45000}{x^2} = 0 \iff 2x^2 - 45000 = 0.

If we divide both sides of this new equation by 2, then we find that we need to solve x^2 - 22500 = 0. This equation has two solutions, x = 150 and x = -150. But remember from earlier, x is a length, so only x = 150 makes any sense (there is no such thing as a negative length). So, we actually only really have one option. But is this option really a minimum like we want it to be? After all, these special points can sometimes be maximums too. How do we know we actually found a minimum?

In the same post where we talked about how to find these special points, we also talked about how to tell which are which by using the ideas of increasing and decreasing. The idea was to pick values that are close to the special point on the left and right to see what P^\prime looks like there, and use the visual ideas of increasing/decreasing to give us our answer. Using the equation P^\prime(x) = 2 - \dfrac{45000}{x^2}, if we pick x a little to the left of 150 we get a negative number, and if we pick x a little to the right then we get a positive number. This means that, as we move from left to right, we find ourselves decreasing, leveling off, then increasing. This is the exact pattern of the U shape, which is the key example we used to show what a minimum looks like. So we actually do have a minimum!

What does all of this mean? It means that, as the farmer, you should build the top and bottom fences 150 feet long. But what about the lone third side? Well, we had an equation for that earlier, y = \dfrac{45000}{x}. If we just plug in x = 150, then we find that y = 300. So, the third side should be built at 300 feet long. And this is the best way to save your money!

I like this example because, without using calculus, it isn’t exactly obvious how you should be building the fence to save money. So this is a problem that became much, much easier because we learned how to use derivatives. And the even better thing is that we can solve any problem resembling this one by using exactly the same concept, we won’t have to come up with any complicated new ideas for new problems that are similar enough to this one. In fact, in “Homework Problem 1,” I give as practice this same problem without the river to help you out, so where you’ll have to build all 4 sides of the fence rather than just three.

Example 2: Building a Low-Cost Container

Imagine you are running a business and you need to design a very special shipping container. This container is special because the top and bottom of this container need to be made out of a more expensive, slightly magnetic material so the boxes can stay connected better when you stack them. The top and bottom materials are going to cost you $5 per square foot, and the cheaper material for the sides costs $2 per square foot. Your boss asks you to design a box with a total storage volume of 100 square feet for the lowest possible cost, and that the top and bottom of this box need to be squares. How do you design such a box?

Before we even start, notice that is a more complicated problem than the fence problem from earlier. We are going to have to think a little bit more carefully, particularly at the very beginning. Firstly, notice where the word lowest shows up – it refers to the cost. Because our process of minimizing things requires that we take a derivative, we need to write down function that tells us about the cost. We will eventually call this function C.

But how do we write down C? Well, we need to slow down a bit. This function counts the total cost of building a box. When we build this box, there are six sides, so C is the sum of the cost of the bottom, the cost of the top, and the cost of each of the four sides. Well then, if we could write down all those numbers, we’d have an equation for C! Here is where we need to pause and remember what our boss asked us to do. He told us that the top and bottom must be squares. So, if those squares have a side length of x feet, then the area of the top is x^2 square feet, and the area of the bottom is also x^2 square feet. We also know that the expensive material for the top and bottom costs us $5 per square foot. This means that the top will cost us 5x^2 dollars and the bottom will also cost us 5x^2 dollars. Now, we need the costs for the four sides, which go for the cheaper rate of $2 per square foot. We can notice that the four sides have a shared base with the squares, but have a height that we can’t determine from the squares. We can call this height y. So, the area of each of the four sides panels of the box is xy. Since these sides cost two dollars per square foot, each panel costs 2xy dollars to build. Since there are four of these side panels, then the cost for the sides is 2xy + 2xy + 2xy + 2xy = 8xy dollars.

We now have all the information we need for an initial cost formula. By adding up the dollar total for the top, bottom, and sides, we can conclude that

C = 5x^2 + 5x^2 + 8xy = 10x^2 + 8xy.

Now what? We can’t exactly take a derivative yet, there are too many variables. How do we get out of that problem? We again turn to what our boss asked us to do. We were asked to build a box with a total volume of 100 square feet. Well, we need to remember the volume formula for a box,

Volume = Base \times Width \times Height.

The base and the width are both x, and and the height is y. So, the volume formula tells us that our boss is asking that we make sure 100 = x^2 y. By dividing both sides by x^2, we can conclude that

y = \dfrac{100}{x^2}.

Because we know this new expression for y, we can use that expression in our formula for C:

C(x) = 10x^2 + 8x\dfrac{100}{x^2} = 10x^2 + \dfrac{8000}{x}.

We are in familiar territory now! We have a single function C(x) and we need to find its minimum value. This is where we use the same process from earlier – we take a derivative, find zeros, and carry on.

The derivative is a fairly routine one using the power rule, we have

C^\prime(x) = 20x - \dfrac{8000}{x^2}.

We want to solve the equation C^\prime(x) = 20x - \dfrac{8000}{x^2} = 0. By multiplying both sides by x^2, we see that 20x^3 - 8000 = 0. By adding 8000 to both sides, we arrive at 20x^3 = 8000. By dividing both sides by 20, we see that x^3 = 400. When you look at this closely, only one number really makes sense, because there is only one positive real number whose cube is 400. So, we see that x = \sqrt[3]{400} is probably our desired answer. But, how do we know this? The answer is, as before we need to check the slopes to the ‘left’ and ‘right’ of the key point. When you do this (take some time to do it yourself if you want practice) we find that leading up to the point x = \sqrt[3]{400} the graph of C(x) slopes downward, then after the key point it slopes upward. This is the characteristic ‘U’ pattern, which tells us we’ve found the minimum!

So, you can tell your boss the base needs to have a side length x = \sqrt[3]{400}. I’ve on purpose chosen a problem with a rather strange number as the answer to make a brief point – calculus can solve a lot of not very obvious problems with some not obvious answers. Before we close out this post, I’ll solve one more problem – this time one with a maximum.

Example 3: The Apple Orchard

You run an apple orchard, and naturally you want to produce as many apples as you can. You’ve done some research and experiments with your field and the variety of apple tree that you grow. You’ve notice over time that when you plant trees too close together, they crowd each other out and you get fewer apples per tree. But, you also realize that more trees mean more apples. You’ve got on the one hand an increase in apples, and on the other hand a decrease in apples. You are trying to figure out what the perfect balance is between planting as many trees as you can without causing too much overcrowding. Your research has led you to conclude the if the number of trees per acre of land increases by one, then each tree in that acre gives you two fewer apples than it did before. Your field currently has 10 trees per acre and each tree grows 35 apples. Now, how should you change your apple orchard to give you the most apples possible?

As with the previous two examples, we have to start by reminding ourselves of exactly what we are doing. We want the largest number of apples, so mathematically speaking, we want a formula A that counts the number of apples we get every harvest, and we want to maximize that formula.

Well, what is a good formula for A? Well, if we know each tree gives us N apples every harvest and that we have T trees per acre, then A = TN. This tells us how to count the number of apples. However, we can’t take the derivative of A yet, there are still too many variables. We now must use the time we spent in research about our apple trees. We know that when T = 10, N = 35. We also know that if we add one to T, then N goes down by two. We can actually think of this as the slope of a linear equation. To see how, note that in the equation y = -2 x, then if x goes up by one, then y goes down by two. This means that something like N = -2T is true… but that isn’t quite right, because T = 10, N = 35 doesn’t work with that equation. If we were to plug those in, we’d get 35 = -2*10 = -20, which is surely wrong. We have to ‘shift’ the equation up to make it work, which in this case involves adding stuff onto the right side until the -20 gets all the way up to 35 where we need it. When we make this correction, we end up with the correct equation N = -2T + 55.

We can now go back to the real problem of maximizing A. We know both that A = TN and N = -2T + 55. By using this second equation to modify the first one,

A = TN = T(-2T + 55) = -2T^2 + 55T.

Therefore, we’ve found that A = -2T^2 + 55T. This is a one-variable equation for A, so we are now at the same point we reached in the other two examples. We proceed in the same way, by finding A^\prime and solving for T in A^\prime = 0. The derivative of A is A^\prime = -4T + 55, and the solution to A^\prime = 0 is T = \dfrac{55}{4}. So, in theory, this is our answer. We should be planting about $\dfrac{55}{4} = 11.25$ trees per acre. Since we are currently only planting 10 per acre, we should plant a couple more trees.


This would be a really good time to pause and reflect on what calculus has enabled us to do. We’ve just solved a variety of problems that asked us to find best-case scenarios for many different sorts of things. This is one of the most important things that calculus can do. There is another incredibly important application of calculus to physics, which we shall go into later. For now, we can appreciate what these new mathematical tricks have enabled us to do.

A Practice Problem

Problem: This is a similar problem to Example 1. If you had to build all four sides of the fence instead of just three, prove that the pen you save the most money with will be a square. In other words, x = y if we use x,y the same way as in Example 1. (Hint: What is the new version of the equation P = 2x + y?)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: