An island's industries buy from each other. Making one dollar's worth of industry j's output uses up A_{ij} dollars' worth of industry i's output (power for the farms, crops for the brewery...): column j of the input-output matrix A is industry j's recipe. On top of that, households and visitors want d_i dollars of each industry's output: the final demand.
Total output x must cover both the final demand and what the industries use up:
Find it the way the orders spread. Start from x = d (just the final demand). Then, round after round, every industry plans to produce the final demand plus the inputs the other industries' current plans need:
Stop after the first round in which no industry's output changed by tol or more (every |x_{\text{new},i} - x_i| < tol), and return a tuple (x_new, rounds): the outputs from that last round, and how many rounds you ran (at least 1).
Write total_output(A, d, tol). Every column of A sums to less than 1 (each industry adds value), which guarantees that the rounds settle.
Examples
Input: A = [[0.2, 0.1], [0.4, 0.3]], d = [100, 50], tol = 0.01
Output: ([144.22921658, 153.84217666], 13)
Explanation: a final demand of 150 dollars needs about 298 dollars of output in all.
The exact answer, 144.2308 and 153.8462, is reached ever more closely as tol shrinks.
Input: A = [[0, 0], [0, 0]], d = [100, 50], tol = 0.01
Output: ([100, 50], 1)
Explanation: industries that use no inputs make just the final demand; one round shows no change.
Constraints
- answers are compared with a relative tolerance of
1e-6; do not round
Goals
- Read an input-output matrix: column `j` lists what one unit of industry `j`'s output uses up
- Find total output by repeating $x \leftarrow d + A x$ until it settles, with a stated stopping rule
- See that total output exceeds final demand because industries supply each other