# Optimization problem of a Cobb-Douglas function with 3 inputs

A perfectly competitive firm uses 3 inputs to manufacture a certain product according to the following Cobb-Douglas production function:

$$Q = A L_1^{\alpha_1} L_2^{\alpha_2} L_3^{\alpha_3}$$

where $$A$$ is a productivity coefficient, $$L_i$$, $$i \in \{1, 2, 3\}$$ are the inputs and $$\alpha_i$$, $$i \in \{1, 2, 3\}$$ are output elasticity coefficients. The firm seeks to maximize profit, which is calculated as the difference between total revenue ($$TR = PQ$$) and total cost ($$TC = \sum_{i=1}^3 w_iL_i$$). $$P$$ is the product price and $$w_i$$, $$i \in \{1, 2, 3\}$$ are the input costs. My goal is to find the profit maximizing inputs: $$L_i^*$$, $$i \in \{1, 2, 3\}$$. This is how I went about it.

The optimization problem is:

$$\text{arg}\,\max\limits_{L_1, L_2, L_3} \{ TR - TC \} \\ \text{arg}\,\max\limits_{L_1, L_2, L_3} \{ PQ - w_1L_1 - w_2L_2 - w_3L_3 \} \\ \text{arg}\,\max\limits_{L_1, L_2, L_3} \{ P A L_1^{\alpha_1} L_2^{\alpha_2} L_3^{\alpha_3} - w_1L_1 - w_2L_2 - w_3L_3 \}$$

With first order conditions:

\begin{align*} P \alpha_1 A L_1^{\alpha_1 - 1} L_2^{\alpha_2} L_3^{\alpha_3} - w_1 &= 0 \\ P \alpha_2 A L_1^{\alpha_1} L_2^{\alpha_2 - 1} L_3^{\alpha_3} - w_2 &= 0 \\ P \alpha_3 A L_1^{\alpha_1} L_2^{\alpha_2} L_3^{\alpha_3 - 1} - w_3 &= 0 \end{align*}

Solving this system of equations is very challenging, so I log-linearize it (and add the Cobb-Douglas production function to it):

\begin{align*} \ln(w_1) &= \ln(P) + \ln(\alpha_1) + \ln(Q) - \ln(L_1) \\ \ln(w_2) &= \ln(P) + \ln(\alpha_2) + \ln(Q) - \ln(L_2) \\ \ln(w_3) &= \ln(P) + \ln(\alpha_3) + \ln(Q) - \ln(L_3) \\ \ln(Q) &= \ln(A) + \alpha_1 \ln(L_1) + \alpha_2 \ln(L_2) + \alpha_3 \ln(L_3) \end{align*}

I want to use matrix algebra to find the solution to the system, so I rearrange the equation in order to have endogenous and exogenous variables/parameters on either sides of the equal symbol:

\begin{align*} \ln(L_1) - \ln(Q) &= \ln(P) + \ln(\alpha_1) - \ln(w_1) \\ \ln(L_2) - \ln(Q) &= \ln(P) + \ln(\alpha_2) - \ln(w_2) \\ \ln(L_3) - \ln(Q) &= \ln(P) + \ln(\alpha_3) - \ln(w_3) \\ \ln(Q) - \alpha_1 \ln(L_1) - \alpha_2 \ln(L_2) - \alpha_3 \ln(L_3) &= ln(A) \end{align*}

Then, I rewrite the system using matrices:

\begin{align*} CX &= DY \\ \begin{bmatrix} 1 & 0 & 0 & -1 \\ 0 & 1 & 0 & -1 \\ 0 & 0 & 1 & -1 \\ -\alpha_1 & -\alpha_2 & -\alpha_3 & -1 \end{bmatrix} \begin{bmatrix} \ln(L_1) \\ \ln(L_2) \\ \ln(L_3) \\ \ln(Q) \end{bmatrix} &= \begin{bmatrix} 1 & 0 & 1 & 0 & 0 & -1 & 0 & 0 \\ 1 & 0 & 0 & 1 & 0 & 0 & -1 & 0 \\ 1 & 0 & 0 & 0 & 1 & 0 & 0 & -1 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} \ln(P) \\ \ln(A) \\ \ln(\alpha_1) \\ \ln(\alpha_2) \\ \ln(\alpha_3) \\ \ln(w_1) \\ \ln(w_2) \\ \ln(w_3) \end{bmatrix} \end{align*}

Now, I can compute the log optimal values in matrix $$X$$ as:

$$X = C^{-1}DY$$

Finally, the profit-maximizing inputs of the firm can be obtained by exponentiating the values in matrix $$X$$.

Hopefully, this shows you that I have done my homework. Now my question. Are there not two ways of obtaining the profit-maximizing output of the firm? Shouldn't the values of (i) and (ii) below be equal?

(i) exponentiate the fourth element of matrix $$X$$ (i.e. $$Q^* = X_{4,1}$$)

(ii) evaluate the production function at the optimal values (i.e. $$Q(L_1^*, L_2^*, L_3^*$$))

I coded the system in R and randomly generated some values (within acceptable ranges) for the exogenous parameters. It turns out that I do not obtain the same values. This is not meant to be a coding question; however, in case there are R users here who could provide help, here is my code as well as the "odd" results I obtain. I make sure to set a seed number for reproducibility and I also print all exogenous parameters in case you would like to copy and paste them into your favorite scripting language. I appreciate the help.

# Make results reproducible
set.seed(123)

# Generate exogenous parameters

P <- sample(x = 100:1000, size = 1)
A <- sample(x = 10:1000, size = 1)
w_i <- sample(x = 30, size = 3)
alpha_i <- c(0.3, 0.2, 0.4)

# Build matrix C

C1 <- cbind(diag(3), matrix(-1, ncol = 1, nrow = 3))
C <- rbind(A1, matrix(c(-alpha_i, -1), nrow = 1))

# Build matrix D

D1 <- matrix(c(1, 1, 1, 0, 0, 0), ncol = 2, byrow = FALSE)
D2 <- cbind(B1, diag(3), -diag(3))
D <- rbind(B2, matrix(c(0, 1, rep(0, 6)), nrow = 1))

# Build matrix Y

Y <- matrix(ncol = 1, c(log(P), log(A), log(alpha_i), log(w_i)))

# All exogenous parameters

P
[1] 514

A
[1] 472

w_i
[1] 19 14  3

alpha_i
[1] 0.3 0.2 0.4

C
[,1] [,2] [,3] [,4]
[1,]  1.0  0.0  0.0   -1
[2,]  0.0  1.0  0.0   -1
[3,]  0.0  0.0  1.0   -1
[4,] -0.3 -0.2 -0.4   -1

D
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    1    0    1    0    0   -1    0    0
[2,]    1    0    0    1    0    0   -1    0
[3,]    1    0    0    0    1    0    0   -1
[4,]    0    1    0    0    0    0    0    0

Y
[,1]
[1,]  6.2422233
[2,]  6.1569790
[3,] -1.2039728
[4,] -1.6094379
[5,] -0.9162907
[6,]  2.9444390
[7,]  2.6390573
[8,]  1.0986123

# Solve system

log_optim_matrix <- solve(C) %*% D %*% Y
log_optim_matrix

[,1]
[1,] -2.5771339
[2,] -2.6772173
[3,] -0.4436251
[4,] -4.6709453

# Actual optimal values

exp(log_optim_matrix)

[,1]
[1,] 0.075991495
[2,] 0.068754210
[3,] 0.641705959
[4,] 0.009363414

# Evaluate production function with optimal inputs

A * prod(as.numeric(exp(log_optim_matrix))[1:3]^alpha_i)

[1] 106.7987
$$$$
`