 In our discussion of mathematics and data science foundations, the last thing I want to talk about right here is calculus and how it relates to optimization. I'd like to think of this in other words as the place where math meets reality or it meets Manhattan or something. Now if you remember this graph I made in the last video, y is equal to x squared. That shows this curve here and we have the derivative that the slope can be given by 2x. And so when x is equal to three, the slope is equal to six, fine. And this is where this comes into play. Calculus makes it possible to find values that maximize or minimize outcomes. And if you want to make something a little more concrete out of this, let's think of an example here. By the way, that's Cupid and Psyche. Let's talk about pricing for online dating. Let's assume you've created a dating service and you want to figure out how much can you charge for it that will maximize your revenue. So let's get a few hypothetical parameters involved. First off, let's say that subscriptions, annual subscriptions currently cost $500 a year and you can charge that for a dating service. And let's say you sell 180 new subscriptions every week. On the other hand, based on your previous experience manipulating prices around, you have some data that suggests that for each $5 you discount from the price of $500 you will get three more sales. Also, because it's an online service, let's just make our lives a little simpler right now and assume that there is no increase in overhead. It's not really how it works, but we'll do it for now. And I'm actually going to show you how to do all this by hand. Now, let's go back to price. First, we have this $500 is the current annual subscription price, and you're going to subtract $5 for each unit of discount. That's what I'm giving D. So one discount is $5, two discounts is $10 and so on. And then we have a little bit of data about sales that you're currently selling 180 new subscriptions per week, and that you will add three more for each unit of discount that you give. So what we're going to do here is we're going to find sales as a function of price. Now to do that, the first thing we have to do is get the Y intercept. So we have price here $500 is the current annual subscription price minus $5 times D. And what we're going to do is we're going to get the Y intercept by solving when does this equals zero. Okay, well, we take the 500 we subtract that from both sides. And then we end up with minus 5d is equal to minus 500 divide both sides by minus five and we're left with D is equal to 100. That is when D is equal to 100 x is zero. And that tells us how we can get the Y intercept. But to get that we have to substitute this value into sales. So we take D is equal to 100. And the intercept is equal to 180 plus three 180 is the number of new subscriptions per week. And then we take the three and then we multiply that times our 100. So 180 times three times 100 is equal to 300. Add those together and you get 480. And that is the Y intercept in our equation. So when we've discounted sort of price to zero when prices zero, then the expected sales is 480. Of course, that's not going to happen in reality. But it's necessary for finding the slope of the line. And so now let's get the slope. The slope is equal to the change in Y on the y axis divided by the change in X. One way we can get this is by looking at sales. We get our 180 new subscriptions per week plus three for each unit of discount. And we take our information on price $500 per year minus $5 for each unit of discount. And then we take these the 3d and the 5d and those will give us the slope. So it's plus three divided by minus five. And that's just minus point six. And so that is the slope of the line. Slope is equal to minus 0.6. And so what we have from this is sales as a function of price where sales is equal to 480. Because that's the Y intercept when X is equal to zero when price is zero minus 0.6 times price. So this isn't the final thing. Now what we have to do is we turn this into revenue. So there's another stage to this. Now revenue is equal to sales time the price. How many things did you sell and how much did it cost? Well, we can substitute in some information here. If we take sales and we put it in as a function of price because we just calculated that a moment ago. We get this and then we do a little bit of multiplication. And then we get that revenue is equal to 480 times the price minus 0.6 times the square of the price. Okay, that's a lot of stuff going on there. What we're going to do now is we're going to get the derivative. That's the calculus that we talked about. Well, the derivative of 48 in the price where price is sort of the X, the derivative is simply 480. And the minus 0.6 times the square of the price. Well, that's very similar to the thing we did with the curve. And what we end up with is 0.6 times 2 is equal to 1.2 times the price. This is the derivative of the original equation. We can solve that for zero now. And just in case you're wondering, why do we solve it for zero? Because that is going to give us the place when Y is at a maximum. Now, we had a minus squared, so we have to invert the shape. And we're trying to look for this value right here when it's at the very tippy top of the curve, because that will indicate maximum revenue. Okay, so what we're going to do is we're going to solve for zero. Let's go back to our equation here. We want to find out when is that equal to zero? Well, we subtract 480 from each side. There we go. And we divide by minus 1.2 on each side. And this is our price for maximum revenue. So we've been charging $500 a week, but this says we'll have more total income if we charge 400 instead. And if you want to find out how many sales we can get, currently we have 480. And if you want to know what the sales volume is going to be for that, well, you take the 480, which is the hypothetical Y intercept when the price is zero, but then we put in our actual price of 400, multiply that we get 240, do the subtraction, and we get 240 total. So that would be 240 new subscriptions per week. So let's compare this, the current revenue is 180 new subscriptions per week at $500 per year. And that means that our current revenue is $90,000 per year. I know it sounds really good. But we can do better than that because the formula for maximum revenue is 240 times 400. When you multiply those, you get 96,000. And so the improvement is just the ratio of those two, 96,000 divided by 90,000 is equal to 1.07. And what that means is a 7% increase and anybody would be thrilled to get a 7% increase in their business simply by changing the price and increasing the overall revenue. So let's summarize what we found here. If you lower the cost by 20%, go from $500 per year to $400 per year, assuming all of our other information is correct, then you can increase sales by 33%. That's more than the 20 that you had. And that increases total revenue by 7%. And so we can optimize the price to get the maximum total revenue. And it has to do with this little bit of calculus on the derivative of a function. So in sum, calculus can be used to find the minimum and the maximum of functions, including prices. It allows for optimization. And that in turn allows you to make better business decisions.