Optimization, or finding the best choice/decision
This session shows how to formulate a decision problem. We identify the objective function and whether to minimize or maximize it, and we specify the choice variables and any constraints. To find an optimum, we take a derivative to obtain the first-order condition and then check the curvature. We apply these tools to order quantities and production cycles in Karim's warehouse, which stocks sunglasses and ski goggles.
1. Cost functions
Karim manages a warehouse near Lyon that stocks the sunglasses from Session 1. Annual demand totals 52 × 230.5 = 11,986 pairs, so let us round it to d = 12,000 pairs per year. Throughout this session we treat this annual total as known, and we assume that demand occurs at a constant rate throughout the year. Each order costs a fixed K = €250, whatever the batch size. Think of the paperwork and the delivery fee, which covers the truck and the driver's time. Holding one pair in the warehouse for a year costs h = €2.40, which covers shelf space and insurance. Karim needs to choose the batch size Q, the number of pairs to order each time. He balances the cost of placing orders against the cost of holding stock.
A cost function maps a decision, or choice variable, to a monetary cost. Some costs are fixed: they do not depend on the batch size, like the €250 fee for each order. Other costs are variable: they change with the decision. For example, a larger batch means more pairs in the warehouse and therefore a higher holding cost. For now, we assume no lead time: an order arrives as soon as Karim places it. We begin with the annual ordering and holding costs.
Karim orders a batch of Q units, sells the stock down to zero and then receives the next batch of Q units. Plotted over time, the inventory has a sawtooth shape. It falls in a straight line from Q to 0 and jumps back to Q when the next order arrives, so the average inventory is $Q/2$. A larger batch quantity $Q$ leads to more stock in storage, and thus to higher holding costs. Holding one unit for a year costs $h$, so the annual holding cost is
$$\text{holding cost} = h \cdot \frac{Q}{2} = \frac{hQ}{2}.$$
We often omit the multiplication sign between symbols, so $hQ$ means $h\cdot Q$ and $Kd$ means $K\cdot d$. Between numbers we write the sign explicitly, as in $2.40\times600$.
Karim sells d units a year in batches of Q, so he places $d/Q$ orders per year. Each order costs K, so the annual ordering cost is
$$\text{ordering cost} = K \cdot \frac{d}{Q} = \frac{Kd}{Q}.$$
A larger batch quantity $Q$ leads to lower ordering costs, because it reduces the number of orders. For example, at $Q=1{,}200$ Karim places $12{,}000/1{,}200=10$ orders per year and holds 600 units on average. His ordering costs are $250\times10=2{,}500$ euros per year, while his holding costs are $2.40\times600=1{,}440$ euros per year.
Suppose also that Karim buys each unit from a supplier at a constant unit purchase price $c$. Buying $d$ units each year then costs $c\cdot d$, and the full annual cost is
$$TC_{\text{full}}(Q) = \underbrace{\frac{Kd}{Q}}_{\text{ordering}} + \underbrace{\frac{hQ}{2}}_{\text{holding}} + \underbrace{c\,d}_{\text{purchasing}}.$$
The annual purchasing cost $c\,d$ does not depend on $Q$, because Karim buys the same $d$ units each year whatever the batch size. Adding this constant raises the cost of every batch size by the same amount, so it does not change the optimal batch size. We therefore often omit purchasing costs and use $$TC(Q) = \frac{Kd}{Q} + \frac{hQ}{2}$$ when choosing $Q$. To report the full annual cost, add $c\,d$ back to $TC(Q)$.
Inventory over time when Karim orders Q units at a time
Two years of Karim's sunglasses inventory, with demand fixed at d = 12,000 units/year. Drag the order quantity Q, the number of units in each batch. Larger batches mean higher peak inventory and fewer orders. Smaller batches mean lower peaks and more orders.
The dashed line is the average inventory, Q/2, which lies halfway up each tooth.
Writing an optimization problem
Optimization means choosing the best feasible decision according to a stated criterion. To write an optimization problem, we name its parts. The objective function is the function we want to minimize or maximize. The choice variable is the quantity we control. Parameters are quantities we take as given while making the choice. Constraints restrict which choices are allowed. In Karim's problem, the objective function is the annual cost $TC(Q)$, which he wants to minimize. The choice variable is $Q$, and $K$, $d$ and $h$ are parameters. The only constraint is that the order quantity must be positive:
$$\min_{Q>0}\left\{\frac{Kd}{Q}+\frac{hQ}{2}\right\}.$$Read this as “among positive order quantities, choose one with the lowest annual cost.” We denote the optimal quantity by $Q^*$, so that $TC(Q^*)$ is the lowest annual cost among all feasible choices. Note that $Q^*$ is a quantity, while $TC(Q^*)$ is a cost.
We often have a limited set of feasible choices. For example, an order quantity must be positive. We may want to minimize an objective function, such as a firm's costs $C(x)$, or maximize one, such as a firm's profits $\pi(x)$. Both problems have the same structure:
$$\begin{aligned} \text{Minimize cost:}\quad &\min_{x\in\mathcal X}\{C(x)\}, \\[8pt] \text{Maximize profit:}\quad &\max_{x\in\mathcal X}\{\pi(x)\}. \end{aligned}$$The feasible set $\mathcal X$ contains the permitted choices. Without additional constraints, it is the function's stated domain. A storage capacity or a budget restricts this set further. For example, if Karim can store at most $Q_{\max}$ units, his problem becomes
$$\begin{aligned} &\min_{Q>0}\{TC(Q)\} \\ &\text{subject to}\quad Q\le Q_{\max}. \end{aligned}$$The quantity must be positive and must fit within the storage capacity $Q_{\max}$. Karim may prefer a larger order, but it is not feasible. An unconstrained optimum can therefore become infeasible when such a limit is added. Section 5 extends this idea to two choice variables that share a budget.
2. The derivative: how a function changes
Karim currently orders Q = 800 pairs at a time. His assistant wants to know whether a slightly larger batch would raise or lower the total annual cost, and by how much. A derivative answers this question. It measures how cost changes when the quantity changes by a small amount around its current value.
A derivative measures a function's local rate of change. For a cost function, $TC'(Q)$ tells us how annual cost responds to a small change in order quantity around the current $Q$. We start with an average rate of change, which divides the change in cost by the change in quantity:
$$\frac{TC(Q+\Delta Q)-TC(Q)}{\Delta Q}.$$For example, moving from 800 to 1,200 units gives
$$\begin{aligned} \frac{TC(1{,}200)-TC(800)}{1{,}200-800} &=\frac{3{,}940-4{,}710}{400} \\[6pt] &=-1.925 \end{aligned}$$euros per year for each extra unit in $Q$. Geometrically, this is the slope of the straight line through two points on the cost curve. As we make $\Delta Q$ arbitrarily small, this line approaches the tangent to the curve at $Q$. If the limit exists, it defines the derivative:
$$TC'(Q)=\lim_{\Delta Q\to0}\frac{TC(Q+\Delta Q)-TC(Q)}{\Delta Q}.$$For a small change in order quantity, we can use the derivative to approximate the change in cost:
$$TC(Q+\Delta Q)-TC(Q)\approx TC'(Q)\times\Delta Q.$$This approximation is useful for small changes only. It may be inaccurate for larger changes. A negative derivative means that cost falls as $Q$ increases locally. A positive derivative means that cost rises as $Q$ increases locally.
Four examples of derivatives
Each line below gives a function and its derivative.
$$\begin{aligned} f(x)=7 &\quad\Rightarrow\quad f'(x)=0, \\[6pt] f(x)=3x+7 &\quad\Rightarrow\quad f'(x)=3, \\[6pt] f(x)=x^2 &\quad\Rightarrow\quad f'(x)=2x, \\[6pt] f(x)=\frac6x+x &\quad\Rightarrow\quad f'(x)=-\frac{6}{x^2}+1. \end{aligned}$$A constant function has zero slope. A straight line has a constant slope, equal to the coefficient of $x$. The slope of $x^2$ increases as $x$ increases. The fourth function, defined for $x>0$, is a scaled version of an inventory cost: its first term plays the role of the ordering cost and its second term the holding cost. Its slope is negative for small $x$ and positive for large $x$, so this cost first falls and then rises as the batch grows.
The next example shows how to use the limit definition of a derivative for a power function. In practice, we usually apply rules for functions whose derivatives are already known. We first expand the square, so that the $x^2$ terms cancel. We then divide by $\varepsilon$ and let $\varepsilon$ go to zero:
$$\begin{aligned} f'(x)&=\lim_{\varepsilon\to0}\frac{(x+\varepsilon)^2-x^2}{\varepsilon} \\[6pt] &=\lim_{\varepsilon\to0}\frac{x^2+2x\varepsilon+\varepsilon^2-x^2}{\varepsilon} \\[6pt] &=\lim_{\varepsilon\to0}\frac{2x\varepsilon+\varepsilon^2}{\varepsilon} \\[6pt] &=\lim_{\varepsilon\to0}(2x+\varepsilon) \\ &=2x. \end{aligned}$$At $x=2$ the slope is $2\times2=4$. At $x=5$ it is $2\times5=10$. The derivative appendix collects the rules we will use, including the product rule and the chain rule.
Applying derivative rules to the cost function
Here are the general derivative rules we need to differentiate $TC(Q)=Kd/Q + hQ/2$.
The power rule. For any constant $k$,
$$\frac{d}{dx}x^k = kx^{k-1}.$$
With $k=1$ it gives $\frac{d}{dQ}Q=1\cdot Q^0=1$. With $k=-1$ it gives the derivative of $1/Q$:
$$\begin{aligned} \frac{d}{dQ}\!\left(\frac{1}{Q}\right) &=\frac{d}{dQ}Q^{-1} \\[6pt] &=-1\cdot Q^{-2} \\[6pt] &=-\frac{1}{Q^2}. \end{aligned}$$The sum rule and constant multipliers. For constants $a$ and $b$,
$$\frac{d}{dx}\big[au(x)+bv(x)\big]=au'(x)+bv'(x).$$
We differentiate each term separately and keep the constant multipliers. You should also know the product rule, which is in the appendix.
We now apply these rules to $TC(Q)$, treating K, d and h as constants. The first line rewrites $1/Q$ as $Q^{-1}$. The second line applies the power rule to each term and the sum rule to add them.
$$\begin{aligned} TC(Q)&=Kd\,Q^{-1}+\frac h2\,Q, \\[6pt] TC'(Q)&=Kd\cdot(-Q^{-2})+\frac h2\cdot1 \\[6pt] &=-\frac{Kd}{Q^2}+\frac h2. \end{aligned}$$The ordering-cost term contributes a negative slope, because larger batches mean fewer orders. The holding-cost term contributes a positive slope, because larger batches mean more stock in storage. At the optimum, these two contributions cancel.
With Karim's values, $Kd=250\times12{,}000=3{,}000{,}000$ and $h/2=1.2$. At $Q=800$,
$$\begin{aligned} TC'(800)&=-\frac{3{,}000{,}000}{800^2}+1.2 \\[6pt] &=-4.6875+1.2 \\[6pt] &=-3.4875 \end{aligned}$$euros per year for each extra unit. Adding 10 units to each batch therefore gives an approximate saving of $3.4875\times10\approx34.88$ euros per year. The exact saving, $TC(800)-TC(810)$, is about €34.30. The approximation is close because the change is small.
At the minimum, the tangent is horizontal
Geometrically, $TC'(Q)$ is the slope of the tangent line that touches the cost curve at Q. Where the curve falls steeply, the slope is a large negative number. Where it climbs steeply, the slope is a large positive number. At the minimum, the tangent is horizontal. In other words, the derivative is zero. This is the first-order condition (FOC): at an interior minimum of a differentiable function,
$$TC'(Q^*)=0.$$A zero slope alone does not tell us whether the point is a minimum. A constrained optimum also need not have a zero derivative, when the constraint prevents further improvement. Section 3 examines when the first-order condition is enough to conclude that we have found the minimum.
The tangent line and its slope TC'(Q)
The parameters are fixed at K = €250, h = €2.40/unit/yr and d = 12,000/yr.
As Q increases, the tangent first slopes downward. It is horizontal at the minimum, near Q = 1,581, and then slopes upward.
3. Convexity and global minima
Setting $TC'(Q)=0$ identifies a stationary point, where the tangent is horizontal. We still need to check whether this point minimizes cost. The convexity of the cost function can provide this guarantee.
A function is convex on an interval if every chord, the straight segment joining two points of the graph, lies on or above the graph. A convex function is U-shaped, like a cup. A function is concave if every chord lies on or below the graph. A concave function curves downward, like a dome. A useful mnemonic is that concave looks like a cave. These shapes are only reminders: a straight line satisfies both conditions, so it is both convex and concave. The second derivative $f''$ is the derivative of $f'$, and it measures how the slope changes. For a twice-differentiable function on an interval, $$\begin{aligned} f''(x)\ge0\text{ throughout the interval}&\quad\Rightarrow\quad f\text{ is convex}, \\ f''(x)\le0\text{ throughout the interval}&\quad\Rightarrow\quad f\text{ is concave}. \end{aligned}$$
A function can be convex on one interval and concave on another. An inflection point is a point where the curvature changes sign. To use convexity to establish a global minimum, the condition must hold throughout the domain. If $TC''(Q)\ge0$ for every $Q>0$, any stationary point minimizes cost over all positive order quantities. If $TC''(Q)>0$ throughout the domain, the function is strictly convex, and its minimum, if it exists, is unique. Convexity only near a stationary point establishes a local minimum.
A non-convex function can have several local minima. A stationary point may be a local minimum, a local maximum, or neither. The figure below shows why a zero derivative alone is not enough to identify the best choice.
Checking that TC(Q) is convex
We differentiate $TC'(Q) = -Kd\,Q^{-2} + h/2$ once more. By the power rule with $k=-2$, the derivative of $Q^{-2}$ is $-2Q^{-3}$. The constant $h/2$ has derivative zero.
$$\begin{aligned} TC''(Q)&=-Kd\cdot(-2Q^{-3})+0 \\[6pt] &=\frac{2Kd}{Q^3}. \end{aligned}$$Order quantities are positive, so Q > 0. Since K > 0 and d > 0 as well, $TC''(Q) > 0$ for every Q > 0. TC is therefore strictly convex on this domain, and its minimum is unique.
There is also a shortcut. The ordering cost $Kd/Q$ is convex for $Q>0$, because it is a positive multiple of $1/Q$, which is convex for $Q>0$. The holding cost $hQ/2$ is linear, and therefore convex. The sum of convex functions is convex, so $TC(Q)$ is convex without computing a second derivative.
Section 2 introduced the first-order condition. We can now state precisely what it does and does not deliver. $TC'(Q)=0$ is a necessary condition for an interior minimum of a differentiable function. It is not a sufficient condition, because the derivative is also zero at local maxima and at other stationary points. The second-order condition (SOC) checks the curvature. At a stationary point with $f'' > 0$, the function is locally convex (U-shaped) and the point is a local minimum. At a stationary point with $f'' < 0$, the function is locally concave and the point is a local maximum. If $f''=0$ at the stationary point, this test is inconclusive. For example, $f'(0)=f''(0)=0$ for each of $x^4$, $-x^4$ and $x^3$, but $x^4$ has a minimum at zero, $-x^4$ has a maximum there, and $x^3$ has neither.
A constrained optimum must be checked separately, because its derivative need not be zero. For example, suppose storage limits Karim to $0<Q\le1{,}000$. Cost falls throughout this feasible range, so the constrained optimum is $Q=1{,}000$, the largest quantity that storage allows. There, $TC'(1{,}000)=-3{,}000{,}000/1{,}000^2+1.2=-1.8\ne0$. Convexity of the objective on its whole domain is the global version of the second-order check. The figure below shows what can happen when this global property fails.
When the first-order condition is not enough
A cost curve that is neither convex nor concave on $Q > 0$. It is locally convex in each of the two dips and locally concave over the hump between them. The derivative is zero at three stationary points, so the first-order condition alone does not identify a minimum.
Only the second-order check distinguishes the three points. The dips have $f'' > 0$: one is only a local minimum and the other is the global minimum. The hump has $f'' < 0$ and is a local maximum. An inflection point lies between each dip and the hump, where the curvature changes sign. The EOQ cost curve does not have this problem, because it is strictly convex on all of $Q > 0$.
$TC(Q)=Kd/Q+hQ/2$ has a positive second derivative for every $Q>0$, so it is strictly convex on that domain. Its stationary point is therefore its unique global minimum.
4. The Economic Order Quantity (EOQ)
We now solve Karim's problem. Because $TC$ is strictly convex, the order quantity $Q^*$ that satisfies $TC'(Q^*)=0$ minimizes annual cost.
Solving TC'(Q) = 0 for Q
We take the first-order condition and solve it for $Q$. The second line adds $Kd/Q^2$ to both sides. The third line multiplies both sides by $2Q^2/h$.
$$\begin{aligned} -\frac{Kd}{Q^2}+\frac h2&=0, \\[6pt] \frac{Kd}{Q^2}&=\frac h2, \\[6pt] Q^2&=\frac{2Kd}{h}. \end{aligned}$$We take the positive square root, because Q is a quantity and Q > 0:
$$Q^{*} = \sqrt{\frac{2Kd}{h}}.$$
This is the Economic Order Quantity (EOQ). With Karim's values K = €250, d = 12,000 units/year and h = €2.40/unit/year,
$$\begin{aligned} Q^*&=\sqrt{\frac{2\times250\times12{,}000}{2.4}} \\[6pt] &=\sqrt{\frac{6{,}000{,}000}{2.4}} \\[6pt] &=\sqrt{2{,}500{,}000} \\[6pt] &\approx1{,}581\text{ units}. \end{aligned}$$At $Q^*$, ordering cost equals holding cost. This follows from the first-order condition, which is a marginal trade-off. One more unit in each batch lowers the annual ordering cost by about $Kd/Q^2$ and raises the annual holding cost by $h/2$. At $Q^*$, these two marginal effects are equal. Multiplying both sides by $Q^*$ gives
$$\begin{aligned} \frac{Kd}{(Q^*)^2}&=\frac h2, \\[6pt] \frac{Kd}{Q^*}&=\frac{hQ^*}{2}. \end{aligned}$$So ordering cost equals holding cost exactly at the optimum. To find the minimum cost, we substitute $Q^*=\sqrt{2Kd/h}$ into each term. For the ordering cost,
$$\begin{aligned} \frac{Kd}{Q^*}&=Kd\sqrt{\frac{h}{2Kd}} \\[6pt] &=\sqrt{\frac{K^2d^2h}{2Kd}} \\[6pt] &=\sqrt{\frac{Kdh}{2}}. \end{aligned}$$The holding cost $hQ^*/2$ is equal to the ordering cost, so it is also $\sqrt{Kdh/2}$. Adding the two terms gives
$$\begin{aligned} TC(Q^*)&=\frac{Kd}{Q^*}+\frac{hQ^*}{2} \\[6pt] &=\sqrt{\frac{Kdh}{2}}+\sqrt{\frac{Kdh}{2}} \\[6pt] &=2\sqrt{\frac{Kdh}{2}} \\[6pt] &=\sqrt{\frac{4Kdh}{2}} \\[6pt] &=\sqrt{2Kdh}. \end{aligned}$$In Karim's base case, $TC(Q^*)=\sqrt{2\times250\times12{,}000\times2.4} =\sqrt{14{,}400{,}000}\approx3{,}794.73$ euros per year, or €1,897.37 for each component. This is the sum of ordering and holding costs. The purchasing cost $c\,d$ remains excluded.
At Q*, annual ordering and holding costs are equal
Adjust K and h. The axes stay fixed so that you can compare how the cost curves and the optimum Q* move.
d is held fixed at 12,000 units/year (Karim's rounded sunglasses demand). For large K and small h, the ordering-cost curve leaves the top of the frame. The axes are chosen to keep Q* and the total-cost curve visible for every slider setting.
$Q^{*}=\sqrt{2Kd/h}$ increases with the square root of K and of d, and decreases with the square root of h. Because of the square root, $Q^*$ responds less than proportionally. For example, doubling demand multiplies $Q^*$ by $\sqrt2\approx1.41$, an increase of about 41%, and quadrupling demand doubles $Q^*$.
We often want to measure the cost penalty from not choosing $Q^*$, for example because a supplier ships in fixed pack sizes. Write $q=Q/Q^*$ for the ratio of the chosen quantity to the optimal one. At the optimum, each cost component equals $TC(Q^*)/2$. Since $Kd/Q$ is proportional to $1/Q$ and $hQ/2$ is proportional to $Q$,
$$\begin{aligned} TC(qQ^*)&=\frac1q\times\frac{Kd}{Q^*}+q\times\frac{hQ^*}{2} \\[6pt] &=\frac1q\times\frac{TC(Q^*)}{2}+q\times\frac{TC(Q^*)}{2} \\[6pt] &=\frac{TC(Q^*)}{2}\left(q+\frac1q\right). \end{aligned}$$Dividing both sides by $TC(Q^*)$ gives the relative cost $TC(Q)/TC(Q^*)=\tfrac12\left(q+1/q\right)$.
The cost penalty depends only on Q/Q*
This relative cost curve does not depend on K, h or d. It depends only on the ratio of the chosen Q to Q*.
The formula is $TC(Q)/TC(Q^{*}) = \tfrac12\left(Q/Q^{*} + Q^{*}/Q\right)$. Cost changes slowly near the optimum. Ordering 20% more than $Q^*$ increases the sum of ordering and holding costs by about 1.7%, and ordering twice the optimal quantity increases it by 25%.
5. Constrained optimization: a shared inventory budget
Karim's warehouse also stocks ski goggles, with K₂ = €180 per order, h₂ = €3.10/unit/year, demand d₂ ≈ 5,200 units/year and unit cost c₂ = €15. Sunglasses cost c₁ = €8 per unit. Head office sets a budget B for the value of the inventory of both products. If the two independent EOQs together exceed this budget, Karim cannot order each product at its own EOQ. He must then choose both order quantities together, subject to one shared budget.
The objective function is the total annual cost of both products, which Karim wants to minimize. There are now two choice variables, $Q_1$ and $Q_2$, and one budget constraint:
$$\begin{aligned} &\min_{Q_1>0,\,Q_2>0}\{TC_1(Q_1)+TC_2(Q_2)\} \\ &\text{subject to}\quad c_1Q_1+c_2Q_2\le B. \end{aligned}$$Here $B$ is the available budget in euros, and $c_iQ_i$ is the value of product $i$'s peak inventory. The constraint requires enough budget to cover both peaks together. This is a conservative assumption if deliveries occur at different times. Without the budget, the independent EOQs are $Q_1^*\approx1{,}581.14$ and $Q_2^*\approx777.09$. Their combined peak value is $8\times1{,}581.14+15\times777.09\approx24{,}305.48$ euros, so a smaller budget binds.
In the figure below, the horizontal axis is $Q_1$ and the vertical axis is $Q_2$. Each closed oval is a level curve: every point on it has the same total cost. The red line is the budget limit, and feasible quantities lie on or below it. The purple dot marks the unconstrained optimum, with each product at its own EOQ. The orange dot marks the best quantities for the selected budget. With a tight budget, the orange dot lies where the lowest feasible cost contour is tangent to the budget line. Once both EOQs are affordable, the two optima coincide, and the larger purple dot remains visible around the orange dot.
The Lagrangian is a technique for solving optimization problems with constraints. It adds the constraint to the objective function, multiplied by a new variable $\lambda\ge0$ called the Lagrange multiplier:
$$\begin{aligned} \mathcal L(Q_1,Q_2,\lambda) &=TC_1(Q_1)+TC_2(Q_2) \\ &\quad+\lambda(c_1Q_1+c_2Q_2-B). \end{aligned}$$The multiplier attaches a cost to using the limited budget. For a given $\lambda$, we minimize the Lagrangian over positive quantities. We take the derivative with respect to each $Q_i$, keeping the other quantity fixed, and set it to zero. The derivation below shows that this gives
$$Q_i(\lambda) = \sqrt{\frac{2K_i d_i}{h_i + 2\lambda c_i}}.$$
We first try $\lambda=0$, which gives the independent EOQs. If they fit within the budget, they solve the problem. Otherwise, the budget binds, and we choose $\lambda>0$ so that the quantities use the full budget: $$c_1Q_1(\lambda)+c_2Q_2(\lambda)=B.$$ We find this $\lambda$ numerically by bisection, which repeatedly halves an interval that contains the solution.
The multiplier $\lambda$ is the shadow price of the budget. It measures how much the optimal annual cost falls per extra euro of budget. For a small budget increase $\Delta B$, the saving is approximately $\lambda\times\Delta B$. As with the derivative, this approximation is accurate for small changes only. For example, with a budget of €16,000 the multiplier is $\lambda\approx0.1636$. Raising the budget by €100 gives an approximate saving of $0.1636\times100\approx16.36$ euros per year, while the exact saving is about €16.18 per year. When the budget does not bind, $\lambda = 0$. An extra euro of budget then has no value, because Karim already orders both products at their EOQs.
From the Lagrangian to the constrained order quantities
The notation $\partial/\partial Q_i$ means “differentiate with respect to $Q_i$, holding the other variables fixed.” The cost of the other product does not depend on $Q_i$, so its partial derivative is zero. The term $\lambda c_iQ_i$ has derivative $\lambda c_i$. The first-order condition for product $i$ is
$$\frac{\partial\mathcal L}{\partial Q_i} =-\frac{K_id_i}{Q_i^2}+\frac{h_i}{2}+\lambda c_i=0.$$We move the first term to the other side, combine the remaining terms over a common denominator and solve for $Q_i$:
$$\begin{aligned} \frac{K_id_i}{Q_i^2}&=\frac{h_i}{2}+\lambda c_i \\[6pt] &=\frac{h_i+2\lambda c_i}{2}, \\[6pt] Q_i^2&=\frac{2K_id_i}{h_i+2\lambda c_i}, \\[6pt] Q_i(\lambda)&=\sqrt{\frac{2K_id_i}{h_i+2\lambda c_i}}. \end{aligned}$$With $\lambda=0$ this is the ordinary EOQ. A positive $\lambda$ increases the denominator, so the constrained quantities are smaller. Along with positive quantities, the solution satisfies
$$\begin{aligned} c_1Q_1+c_2Q_2&\le B, \\ \lambda&\ge0, \\ \lambda(c_1Q_1+c_2Q_2-B)&=0. \end{aligned}$$The last condition is complementary slackness. Either the budget is fully used, or its multiplier is zero, and both can hold at once. Because the cost is strictly convex and the feasible set is convex, these conditions are sufficient for a minimum here.
How the budget changes the optimal order quantities
While the budget limits the order quantities, the dashed green contour is tangent to the red budget line at the orange dot. Once both EOQs are affordable, the cost contour at the minimum reduces to a single point, and the orange dot sits inside the purple dot.
Product 1 = sunglasses (K₁=€250, h₁=€2.4, d₁=12,000, c₁=€8). Product 2 = ski goggles (K₂=€180, h₂=€3.1, d₂=5,200, c₂=€15).
Minimum annual cost as a function of the budget
Total cost as a function of the budget B. The marker follows the slider above.
The curve falls steeply while the budget binds. It becomes flat once B is large enough to afford the unconstrained optimum, where λ reaches zero. Further budget increases do not reduce the optimal cost.
6. Production planning: the optimal cycle
Suppose now that Karim's company manufactures its products on one production line, which makes them in rotation: sunglasses, then goggles, then sunglasses again. A cycle lasts T years and contains one batch of each product. Each time the line switches to a product, the company pays a setup cost, for example to clean and recalibrate the machines. Between production runs, each product is held in stock. The choice variable is the cycle length T, and the objective is to minimize the annual setup and holding cost.
With a cycle of length T, there are $1/T$ cycles per year, and each cycle contains one setup per product. The annual setup cost is therefore $\frac1T\times\Sigma K=\Sigma K/T$, where $\Sigma K = \sum_i K_i$ is the total setup cost per cycle. Each batch covers one cycle's demand, so the batch size of product $i$ is $Q_i=d_iT$. Its average inventory, and hence its holding cost, grows in proportion to $T$. The annual holding cost of product $i$ is $h_i'd_iT/2$, where $h_i'$ is an adjusted holding cost explained below. (The prime in $h_i'$ is part of the name and does not denote a derivative.) Writing $\Sigma h'd = \sum_i h_i' d_i$ for the demand-weighted total holding cost, the annual cost is
$$TC(T) = \frac{\Sigma K}{T} + T\times\frac{\Sigma h'd}{2}.$$
Why h′ instead of h, and solving for T*
The production rate $P_i$ is the number of units of product $i$ that the line makes per year while it is running on product $i$. We need $P_i>d_i$. Making a batch of $Q_i=d_iT$ units takes $d_iT/P_i$ years. During this time, customers keep buying, so stock rises at the net rate $P_i-d_i$ rather than at $P_i$. The peak inventory is reached when the batch is finished:
$$\begin{aligned} I_{\max}&=(P_i-d_i)\times\frac{d_iT}{P_i} \\[6pt] &=d_iT\left(1-\frac{d_i}{P_i}\right). \end{aligned}$$After the batch is finished, stock falls at rate $d_i$ until the next batch starts. The average inventory over the cycle is therefore $I_{\max}/2$, and the annual holding cost is
$$\begin{aligned} h_i\times\frac{I_{\max}}{2} &=h_i\left(1-\frac{d_i}{P_i}\right)\frac{d_iT}{2} \\[6pt] &=\frac{h_i'd_iT}{2}, \qquad\text{where }h_i'=h_i\left(1-\frac{d_i}{P_i}\right). \end{aligned}$$We call $h_i'$ the adjusted holding cost. It is smaller than $h_i$ because stock never reaches the full batch size. For example, if h₁ = €2.40, $d_1=12{,}000$ and $P_1=52{,}000$, then $h_1'=2.40\times(1-12{,}000/52{,}000)\approx1.85$ euros. If production is very fast, $d_i/P_i\approx0$ and $h_i'\approx h_i$, which brings us back to the EOQ model.
$TC(T)$ has the same form as $TC(Q)$ in Section 4: a constant divided by T plus a constant times T. The same steps therefore give the optimum. By the power rule,
$$\begin{aligned} TC'(T)&=-\frac{\Sigma K}{T^2}+\frac{\Sigma h'd}{2}. \end{aligned}$$Setting $TC'(T^*)=0$ and solving for $T^*$ gives
$$\begin{aligned} \frac{\Sigma K}{(T^*)^2}&=\frac{\Sigma h'd}{2}, \\[6pt] (T^*)^2&=\frac{2\Sigma K}{\Sigma h'd}, \\[6pt] T^*&=\sqrt{\frac{2\Sigma K}{\Sigma h'd}}. \end{aligned}$$For positive setup and adjusted holding costs, $$TC''(T)=\frac{2\Sigma K}{T^3}>0,$$ so this is the unique minimum over $T>0$. For example, with ΣK = €800 and Σh'd = €6,000/year², $T^*=\sqrt{2\times800/6{,}000}\approx0.516$ years, or about 26.9 weeks. The model assumes sufficient production capacity ($\sum_i d_i/P_i\le1$), negligible setup times and a feasible repeating schedule.
Choosing the cycle time T that minimizes annual cost
Adjust the total setup cost and the total weighted holding cost. The axes stay fixed so that you can see the cost curve and its minimum move. Higher setup costs favor longer cycles, while higher holding costs favor shorter cycles.
The yellow dot marks the optimal cycle time. For every slider setting, this minimum stays inside the frame. Very short or very long cycles can have costs above the €10,000 limit shown on the vertical axis.
The ordering model and the production-cycle model share the form “constant divided by x, plus constant times x.” The same differentiation steps give the optimum in both models, and in other operations models with this form.
We formulated decision problems by naming the objective function, whether to minimize or maximize it, the choice variables and any constraints. A zero derivative identifies a candidate optimum. We check the curvature and any constraints before concluding that it is the best feasible choice. For the EOQ cost, strict convexity makes the stationary point the unique global minimum. A shared budget can change the optimal quantities, and its multiplier measures how much an extra euro of budget would save in annual cost.
Every formula in this session assumed that demand d is a known, fixed number. Session 1 showed how to model uncertain demand as a random variable. Session 3 brings this uncertainty back into the decision and shows how it changes the optimal order quantity.
Appendix · Derivative rules
Differentiate with respect to $x$. The letters $a,b,k$ denote constants, and $u$ and $v$ denote differentiable functions of $x$. Use each rule only where the original function and the derivative are defined. In particular, denominators must be nonzero.
| Rule | Function | Derivative |
|---|---|---|
| Constant | $k$ | $0$ |
| Linear | $ax+b$ | $a$ |
| Power | $x^k$ | $kx^{k-1}$ |
| Reciprocal ($x\ne0$) | $1/x$ | $-1/x^2$ |
| Square root ($x>0$) | $\sqrt x$ | $1/(2\sqrt x)$ |
| Exponential | $e^x$ | $e^x$ |
| Natural logarithm ($x>0$) | $\ln x$ | $1/x$ |
| Sum and constant multiples | $au(x)+bv(x)$ | $au'(x)+bv'(x)$ |
| Product | $u(x)v(x)$ | $u'(x)v(x)+u(x)v'(x)$ |
| Quotient ($v(x)\ne0$) | $u(x)/v(x)$ | $\dfrac{u'(x)v(x)-u(x)v'(x)}{v(x)^2}$ |
| Chain (composition) | $u(v(x))$ | $u'(v(x))\,v'(x)$ |
| Cumulative integral (continuous $f$) | $F(x)=\int_{-\infty}^x f(t)\,dt$ | $f(x)$ |
Product rule: differentiate one factor at a time
The first term differentiates the first factor, $x^2$, and keeps the second. The second term keeps the first factor and differentiates the second, $3x+1$.
$$\begin{aligned} f(x)&=x^2(3x+1), \\[6pt] f'(x)&=(2x)(3x+1)+x^2\times3 \\[6pt] &=6x^2+2x+3x^2 \\[6pt] &=9x^2+2x. \end{aligned}$$Keep the other factor unchanged in each term, then add. Multiplying the two derivatives would give the wrong answer.
Chain rule: outside derivative times inside derivative
$$\begin{aligned} f(x)&=(3x+1)^2, \\[6pt] f'(x)&=2(3x+1)\times3 \\[6pt] &=6(3x+1). \end{aligned}$$The outside function squares its input, and the inside function is $3x+1$. The extra factor 3 is the derivative of the inside function: it measures how fast the input of the outside function changes. We will use the same rule when standardizing a normal variable:
$$\frac{d}{dQ}\Phi\!\left(\frac{Q-\mu}{\sigma}\right) =\phi\!\left(\frac{Q-\mu}{\sigma}\right)\times\frac1\sigma,\qquad\sigma>0.$$