You've opened up a shoe factory and you're trying to figure out how many thousands of pairs of shoes to produce in order to optimize your profit. And so let's let x equal the thousands of pairs produced. Now let's think about how much money you're going to make per pair. Actually, let me say how much revenue, which is how much you actually get to sell those shoes for. So let's write a function right here. Revenue as a function of x. Well, you have a wholesaler who's willing to pay you $10 per pair for as many pairs as you're willing to give him. So your revenue as a function of x is going to be 10 times x. And since x is in thousands of pairs produced, if x is 1, that means 1,000 pairs produced times 10, which means$10,000. But this will just give you 10. So this right over here is in thousands of dollars. So if x is 1, that means 1,000 pairs produced. 10 times 1 says r is equal to 10, but that really means $10,000. Now, it would be a nice business if all you had was revenue and no costs. But you do have costs. You have materials, you have to build your factory, have to pay your employees, you have to pay the electricity bill. And so you hire a bunch of consultants to come up with what your cost is as a function of x. And they come up with a function. They say it is the number of the thousands of pairs you produce cubed minus 6 times the thousands of pairs you produce squared plus 15 times the thousands of pairs that you produce. And once again, this is also going to be in thousands of dollars. Now, given these functions of x for revenue and cost, what is profit as a function of x going to be? Well, your profit as a function of x is just going to be equal to your revenue as a function of x minus your cost as a function of x. If you produce a certain amount and let's say you bring in, I don't know,$10,000 of revenue and it costs you $5,000 to produce those shoes, you'll have$5,000 in profit. Those numbers aren't the ones that would actually you would get from this right here. I'm just giving you an example. So this is what you want to optimize. You want to optimize p as a function of x. So what is it? I've just said it here in abstract terms, but we know what r of x is and what's c of x. This is 10x minus all of this business. So minus x to the third plus 6x squared minus 15x. I just subtracted x squared, you subtract 6x squared it becomes positive, you subtract a 15x it becomes negative 15x, and then we can simplify this as-- let's see, we have negative x to the third plus 6x squared minus 15x plus 10x, so that is minus 5x. Now if we want to optimize this profit function analytically, the easiest way is to think about what are the critical points of this profit function and are any of those critical points minimum points or maximum points? And if one of them is a maximum point, then we can say, well, let's produce that many. That is going to be-- we will have optimized or we will figure out the quantity we need to produce in order to optimize our profit. So to figure out critical points, we essentially have to find the derivative of our function and figure out when does that derivative equal 0 or when is that derivative undefined? That's the definition of critical points. So p prime of x is going to be equal to negative 3x squared plus 12x minus 5. And so this thing is going to be defined for all x. So the only critical points we're going to have is when the first derivative right over here is equal to 0. So negative 3x squared plus 12x minus 5 needs to be equal to 0 in order for x to be a critical point. So now we just have to solve for x. And so we just are essentially solving a quadratic equation. Just so that I don't have as many negatives, let's multiply both sides by negative 1. I just like to have a clean first coefficient. So if we multiply both sides by negative 1, we get 3x squared minus 12x plus 5 is equal to 0. And now we can use the quadratic formula to solve for x. So x is going to be equal to negative b, which is 12, plus or minus the square root. I always need to make my radical signs wide enough. The square root of b squared, which is 144, minus 4 times a, which is 3, times c, which is 5. All of that over 2a. So 2 times 3 is 6. So x is equal to 12 plus or minus the square root of, let's see, 4 times 3 is 12 times 5 is 60. 144 minus 60 is 84. All of that over 6. So x could be equal to 12 plus the square root of 84 over 6 or x could be equal to 12 minus the square root of 84 over 6. So let's figure out what these two are. And I'll use a calculator. I'll use the calculator for this one. So I get, let's see, 12 plus the square root of 84 divided by 6 gives me 3.5-- I'll just say 3.53. So approximately 3.-- Actually, let me go one more digit, because I'm talking about thousands. So let me say 3.528. So this would literally be 3,528 shoes, because this is in thousands, or pairs of shoes. And then let's do the situation where we subtract. And actually we can look at our previous entry and just change this to a subtraction. Change that to not a negative sign, a subtraction. There you go. And we get 0.4725. Let me remember that. 0.4725. Approximately equal to 0.4725. I have a horrible memory, so let me review that I wrote the same thing. 4725. Yep. All right. Now these are all we know about these, or these are both critical points. These are points at which our derivative is equal to 0. But we don't know whether they're minimum points, they're points at which the function takes on a minimum value, a maximum value, or neither. To do that, I'll use the second derivative test to figure out if our function is concave upwards or concave downwards or neither at one of these points. So let's look at the second derivative. So p prime prime of x is going to be equal to negative 6x plus 12. And so if we look at-- let me make sure I have enough space. So if we look at p prime prime of 3.528. So let's see if I can think this through. So this is between 3 and 4. So if we take the lower value, 3 times negative 6 is negative 18 plus 12 is going to be less than 0. And if this was 4 it'd be even more negative, so this thing is going to be less than 0. Don't even have to use my calculator to evaluate it. Now what about this thing right over here? 0.47. Well, 0.47, that's roughly 0.5. So negative 6 times 0.5 is negative 3. This is going to be nowhere close to being negative. This is definitely going to be positive. So p prime prime of 0.4725 is greater than 0. So the fact that the second derivative is less than 0, that means that my derivative is decreasing. My first derivative is decreasing when x is equal to this value, which means that our graph, our function, is concave downwards here. And concave downwards means it looks something like this. And so you can see what it looks something like that, the slope is constantly decreasing. So if you have an interval where the slope is decreasing and you know the point where the slope is exactly 0, which is where x is equal to 3.528, it must be a maximum. So we actually do take on a maximum value when x is 3.528. On the other side we see that over here we're concave upwards. The graph will look something like this over here. And if the slope is 0 where the graph looks like that, we see that that is a local minimum. And so we definitely don't want to do this. We would produce 472 and 1/2 units if we were looking to minimize our profit, maximize our loss. So we definitely don't want to do this. But let's actually think about what our profit is going to be if we produce 3.528 thousands of shoes, or 3,528 shoes. Well, to do that we just have to input it back into our original profit function right over here. So let's do that. So I get my calculator out. So my original profit function is right over there. So I want to be able to see that and that. So I get negative 3.528 to the third power plus 6 times 3.528 squared minus 5 times 3.528 gives me-- and we get a drum roll now-- gives me a profit of 13.128. So let me write this down. The profit when I produce 3,528 shoes is approximately equal to or it is equal to, if I produce exactly that many shoes, it's equal to 13.128. Or actually it's approximately, because I'm still rounding 13.128. So if I produce 3,528 shoes in a given period, I'm going to have a profit of $13,128. Remember, this right over here is in thousands, this right over here is 13.128 thousands of dollars in profit, which is$13,128. Anyway, we are now going to be rich shoe manufacturers.