You are here

Linear Algebra in Engineering: Macroeconomics with Leontief Input-Output Model (Part 5 of 7)

Preface
This series is aimed at providing tools for an electrical engineer to analyze data and solve problems in design. The focus is on applying linear algebra to systems of equations or large sets of matrix data.

Introduction
This article will demonstrate the use of Leontief Input-Output Models. This can be used to analyze macroeconomic models of production.

If you are not familiar with linear algebra or need a brush up I recommend Linear Algebra and its Applications by Lay, Lay and McDonald. It provides an excellent review of theory and applications.

This also assumes you are familiar with Python or can stumble your way through it.

The data and code are available here: linear5.py and linear5.xlsx.

Concepts
Consumption Matrix: An nxn matrix which specifies how many units from each sector are required to produce 1 unit from a particular sector. Each column/row represents a particular sector. n is the total number of sectors represented in the model.

Demand Vector: final output quantity of each sector required of an economy

Production Vector: the amount of units from each sector required to meet the demand of the economy (specified by the demand vector).

Importing Your Data Set
I will use the Anaconda package suite with Python, numpy and the Spyder IDE for mathematical analysis. It is cross platform, free and open source. It is also easy to import data from Excel once you have the code snippet.

I usually have the following boilerplate code in my scripts:

import sys
import xlrd
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d


np.set_printoptions(threshold=np.nan)
print sys.version
print __name__

The sectors in this example are Caprese, Mozzarella, Basil, Tomato, Toast, Milk, Water, Wheat. While this example is a bit playful, they could easily have been manufacturing, agriculture, technology, health, etc. And we would like to calculate the input requirements for creating 100 units of Caprese.

Caprese Mozzarella Basil Tomato Toast Milk Water Wheat
Caprese 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Mozzarella 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Basil 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Tomato 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Toast 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Milk 0.0 5.0 0.0 0.0 0.0 0.0 0.0 0.0
Water 0.0 5.0 1.0 3.0 1.0 10.0 0.0 1.0
Wheat 0.0 0.0 0.0 0.0 2.0 0.0 0.0 0.0


filename='linear_5.xlsx'
print
print 'Opening',filename
ss=xlrd.open_workbook(filename,on_demand=True)
sheet_index=0
print ' Worksheet',ss.sheet_names()[sheet_index]
sh=ss.sheet_by_index(sheet_index)


print ' Reading data values'
xa=[]
for row_index in range(0,sh.nrows):
row_single=[]
for col_index in range(0,sh.ncols):
row_single.append(sh.cell_value(row_index,col_index))
xa.append(row_single)
xa=np.array(xa)
print ' Design x array size:',len(xa)
print
print xa

Here we read in a matrix of unknown size from Excel.

The last bit of code converts the array to a numpy array which will be necessary for the code below.

Finding Final Production Requirements
We need to calculate d = (I-C)*x. Where 'd' is the demand vector and 'C' is the consumption matrix. 'x' is the production vector.


idm=np.identity(sh.nrows)
xa=idm-xa
final_demand=np.array([100,0,0,0,0,0,0,0])


eq=np.linalg.solve(xa,final_demand)
print
print eq

This is the output:

2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]
__main__


Opening linear_5.xlsx
Worksheet Sheet1
Reading data values
Design x array size: 8


[[ 0. 0. 0. 0. 0. 0. 0. 0.]
[ 1. 0. 0. 0. 0. 0. 0. 0.]
[ 1. 0. 0. 0. 0. 0. 0. 0.]
[ 1. 0. 0. 0. 0. 0. 0. 0.]
[ 1. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 5. 0. 0. 0. 0. 0. 0.]
[ 0. 5. 1. 3. 1. 10. 0. 1.]
[ 0. 0. 0. 0. 2. 0. 0. 0.]]

And the production requirements (solution):

[ 100. 100. 100. 100. 100. 500. 6200. 200.]

We can see that 100 caprese units requires 100 mozzarella, 100 basil, 100 tomato and 100 toast. But we also see, and this is the key value of this method, is that we also know we need 500 units of milk, 200 of toast and 6200 units of water.

Caprese Mozzarella Basil Tomato Toast Milk Water Wheat
100 100 100 100 100 500 6200 200

Next Up
In the next article we will analyze dynamic systems with Markov chains.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <table> <tr> <td> <ul> <ol> <li> <dl> <dt> <pre> <dd> <img> <sub> <sup>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.