Univariate optimization
1. Univariate optimization
Welcome back! Let's add another tool to our optimization toolkit: calculus!2. Example: Optimization in manufacturing
Recall our furniture manufacturer that wants to maximize the profit, P, which is dependent on a single variable, q, the quantity of furniture produced, through the following objective function. Since we only have one variable this is considered a univariate optimization problem. When we plot the objective function, we can see that as the quantity produced increases profit increases to a maximum, and then begins to decrease.3. Example: Optimization in manufacturing
The rate at which profit changes due to changes in quantity is known as the slope. We can visualize it by showing the slope at each point along our objective function, depicted by the dashed red line. It starts off as positive, illustrated by a line that increases vertically as quantity increases. Notice how the slope becomes less and less positive and eventually becomes negative after we pass over the maximum of the objective function. Instead of plotting the slope of the line visually, let's lean on calculus and differentiation to model the slope and simplify the process.4. Calculating derivatives
Differentiation takes some function, like our profit objective function, and derives another function, called the derivative, that describes how the slope behaves. For this course, we'll use the SymPy Python library to calculate derivatives. We begin by importing the symbols, diff, and solve functions from SymPy. symbols takes a string of variable names and converts them into symbols, which we can then use to define the objective function, P. Now that our equation is stored as P, we can find the derivative by passing it to diff, which stands for differentiate. We find that the derivative is 40 minus q. We called the derivative dp_dq, as we differentiated the function P with respect to the variable, q, and this is written in mathematical notation as dP over dq.5. The critical point
We can use the derivative to find the maximum by looking for critical points. Whenever our derivative function equals zero, we are at a critical point. Critical points are excellent candidates for potential minimums or maximums of a function making them ideal for optimizations. We can find our critical points by solving dp_dq equals zero using SymPy's solve function, and print the result. We find there is a critical point when 40 pieces of furniture are produced.6. Maxima, minima, or neither?
Our function only has one critical point, but it is possible to have multiple critical points. So how do we know if the critical point is a maximum or minimum value? We have a few options.7. Convexity and concavity
The first way is to look graphically at the plot. If the function is shaped like a hill, formally called concave, then the critical point is a maxima. If the function is bowl- or U-shaped, formally convex, then the critical point is a minima.8. Second derivative
Alternatively, we can determine whether a point is a maxima or minima with calculus. We can derive the second derivative, or derivative of the derivative. Conceptually, we can think of the second derivative as describing the rate the slope changes as the variable changes. If the second derivative is less than zero at the critical point, it is a maxima, as the speed at which the slope is increasing is slowing down. Likewise, a second derivative above zero indicates a minima. It is possible to have a second derivative of zero at a critical point, this represents an inflection point which is neither a maximum nor a minimum.9. Example: Maximum, minimum, or neither?
Here's the derivative we found for the furniture manufacturing problem. We call the diff function on the first derivative we found earlier to find the second derivative. The subs function substitutes a value into an equation, so once the second derivative is found, we'll substitute the optimum quantity into it and print the result. We find that the second derivative at the critical point is -1, which is less than zero and indicates a maxima.10. Derivatives in optimization
To summarize, first derivatives help find critical points in optimization problems. Second derivatives help identify if these points are minima or maxima.11. Let's practice!
Now it's your turn!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.