Matrices become especially useful when solving systems of equations where multiple equations and variables are present. This occurs in economics when evaluating supply and demand equilibrium for products in different markets. The following example will examine equilibrium quantity and supply for two products in two different markets.
Market 1:
\(Q_{d1} = 10 - 2P_1 +P_2\)
\(Q_{s1} = -2 + 3P_1\)
\(Q_{d1} = Q_{s1}\), because in equilibrium quantity demanded = quantity supplied.
Market 2
\(Q_{d2} = 15 + P_1 - P_2\)
\(Q_{s2} = -1 +2P_2\)
\(Q_{d2} = Q_{s2}\)
Since there are multiple equations, determining equilibrium price and quantity for these two products and two markets may become difficult to do conventionally (i.e., solving the system with simple algebra).
Using R and linear algebra, we can solve the system and find the equilibrium prices and quantities for both markets (we can really find equilibrium for any number of markets).
Simplifying our equations into matrix form, we get:
\[ \begin{bmatrix}1 & 0 & 2 & -1 \\1 & 0 & -3 & 0 \\0 & 1 & -1 & 1 \\0 & 1 & 0 & -2 \\\end{bmatrix} \begin{bmatrix} Q_1\\ Q_2 \\ P_1 \\ P_2\\\end{bmatrix} = \begin{bmatrix} 10\\ -2 \\ 15 \\ -1\\\end{bmatrix} \]
Using R, we can solve the system of equations (now in matrix form) to find equilibrium prices and quantities.
matrix1 <- matrix(c(1, 0, 2, -1, 1, 0, -3, 0, 0, 1, -1, 1, 0, 1, 0, -2), nrow = 4, ncol = 4, byrow = TRUE)
final_values <- c(10, -2, 15, -1)
# Solve the system of equations
solution <- solve(matrix1, final_values)
## Solution:
## Q_1 = 9.142857
## Q_2 = 12.14286
## P_1 = 3.714286
## P_2 = 6.571429
Using our matrix and some simple commands, we determine equilibrium prices and quantities:
\(Q_1 = 9.14\)
\(Q_2 = 12.14\)
\(P_1 = 3.71\)
\(P_2 = 6.57\)
As seen below, we can arrive at the same answer using a slightly different code, mainly the %% operator. The %*% implies multiplying the matrix, while the solve function calculates the inverse of the matrix.
solution2 <- solve(matrix1) %*% final_values
## Solution:
## Q_1 = 9.142857
## Q_2 = 12.14286
## P_1 = 3.714286
## P_2 = 6.571429
Now that we have solved the system, we know the equilibrium quantity demanded and corresponding price. As a producer, we can aim to produce the quantity demanded, and minimize costs at that level of output. This will help maximize profits. This better understanding of the market for the two goods is extremely useful to firms, who are interested in price as well, since in perfectly competitive markets firms are price-takers.