Math 236  •  4 February 2001

A Leontieff open input-output model

This notebook shows how to solve the linear system that models the problem about the three-partner consulting firm (see class notes).
Evaluate all input cells as you come to them.  Solve the included exercises as you come to them.

Preparation—use Clear

Evaluate the following cell to clear, that is, "unset", any definitions you made previously.

ClearAll["Global`*"]

Solving the linear system directly using Solve

We start here with the linear equations already in standard form, that is, with the variables already isolated on the left sides of the equations:
	    0.6 (Subscript[x, 1])  -  0.2 (Subscript[x, 2])  -  
          0.3 (Subscript[x, 3])  =  
        2000, 
-0.1 (Subscript[x, 1])  +  0.7 (Subscript[x, 2])  -  
          0.4 (Subscript[x, 3])  =  
        3500, 
-0.3 (Subscript[x, 1])  -  0.4 (Subscript[x, 2])  +  
          0.8 (Subscript[x, 3])  =  2500.

If you wish, you may set up names for the three equations and the variables:

eqns  =  { .6  x1  -  .2 x2  -   .3 x3  ==  
            2000,  - .1 x1  +   .7 x2  -  .4 x3  ==  
            3500,  - .3 x1  -  .4 x2  + 0.8 x3  ==  
            2500};
vars  =  {x1,  x2,  x3};

And then you use Solve like this:

Solve[eqns,  vars]

Or, you may do the whole thing in one Solve expression:

Solve[{ .6  x1  -  .2 x2  -   .3 x3  ==  
          2000,  - .1 x1  +   .7 x2  -  .4 x3  ==  
          3500,  - .3 x1  -  .4 x2  + 0.8 x3  ==  2500},  {x1,  
        x2,  x3}]

Solution as a list of replacement rules

Whichever approach you used with Solve—with names eqns and vars or without them—no actual assignments have been made to the symbols x1, x2, x3:

x1

The reason no actual assignments have been made is that the result of the Solve expression is a list of replacement rules.  More precisely, it's the one-element list 
	{{x1->20040.,x2->19520.,x3->20400.}}
whose only entry is the list of replacement rules:
	{x1->20040.,x2->19520.,x3->20400.}

To actually assign the indicated numbers as values for the variables, you need to do it explicitly by means of the ReplaceAll function:

soln  =  
      Solve[{ .6  x1  -  .2 x2  -   .3 x3  ==  
            2000,  - .1 x1  +   .7 x2  -  .4 x3  ==  
            3500,  - .3 x1  -  .4 x2  + 0.8 x3  ==  
            2500},  {x1,  x2,  x3}]

ReplaceAll[x1,  soln]

Usually it's more convenient to use the infix abbreviated form name /. ruleList instead of ReplaceAll[name, ruleList]:

x1  /.  soln

Still, the result is a one-element list.  To get just the value itself, get rid of the outer braces of soln so as to obtain a single vector, not a doubly-nested list:

First[soln]

x1  /.  First[soln]

You can get the solution values for all three variables at once:

{x1,  x2,  x3}  /.  First[soln]

Still  x1, x2, x3 do not have values, because no explicit assignments were made to them:

{x1,  x2,  x3}

If you actually want x1, x2, x3 to have the values indicated by the result of Solve, then you have to make the assignment explicitly:

{x1,  x2,  x3}   =  {x1,  x2,  x3}  /.  First[soln]

x1

⚠ Caution:  Because you just made assignments to x1, x2, x3, these names are no longer simply symbols but rather names for numbers.  See what happens if you again try to evaluate the Solve expression involving them:

Solve[{ .6  x1  -  .2 x2  -   .3 x3  ==  
          2000,  - .1 x1  +   .7 x2  -  .4 x3  ==  
          3500,  - .3 x1  -  .4 x2  + 0.8 x3  ==  2500},  {x1,  
        x2,  x3}]

In order to re-evaluate this Solve expression, you will need to clear the values assigned to x1, x2, x3:

Clear[x1,  x2,  x3]

Solve[{ .6  x1  -  .2 x2  -   .3 x3  ==  
          2000,  - .1 x1  +   .7 x2  -  .4 x3  ==  
          3500,  - .3 x1  -  .4 x2  + 0.8 x3  ==  2500},  {x1,  
        x2,  x3}]

Getting the exact solution

Some of the numbers (0.6, 0.2, etc.) appearing in the equations were entered with decimal points, so they are approximate, floating-point numbers.  Then the result of Solve also gives approximate numbers, as the decimal points in the result indicate.  To obtain exact numbers for the solution, you need to use exact numbers in the equations:

Solve[{(6/10) x1  - (2/10) x2  -  (3/10) x3  ==  
          2000,  -(1/10) x1  +  (7/10) x2  - (4/10) x3  ==  
          3500,  -(3/10) x1  - (4/10) x2  + (8/10) x3  ==  
          2500},  {x1,  x2,  x3}]

If you wish, you may let Mathematica do conversion from decimals to exact, rational numbers.  For example:

Rationalize[ .3]

Solving the output = intermediate demand + final-demand equations directly using Solve

The original output = intermediate demand + final demand form of the linear system—before all the variables were isolated on the left sides—was:
(*)	(Subscript[x, 1])  =  
        0.4 (Subscript[x, 1])  +  0.2 (Subscript[x, 2])  +  0.3 (Subscript[x, 3])  +  
          2000, 
(Subscript[x, 2])  =  
        0.1 (Subscript[x, 1])  +  0.3 (Subscript[x, 2])  +  0.4 (Subscript[x, 3])  +  
          3500, 
(Subscript[x, 3])  =  
        0.3 (Subscript[x, 1])  +  0.4 (Subscript[x, 2])  +  0.2 (Subscript[x, 3])  +  2500.

You could have used Solve directly on that system as is:

Solve[{x1  ==   .4 x1  +   .2 x2  +   .3 x3   +  
            2000,  x2  ==  
          0.1 x1  +  0.3 x2  +  0.4 x3  +  3500,  
        x3  ==  
          0.3 x1  +  0.4 x2  +  0.2 x3  +  2500},  {x1,  x2,  
        x3}]

Using matrices to solve the output = intermediate demand + final-demand equations

Look again at the original output = intermediate demand + final demand form (*) of the linear system.

You could assign the consumption matrix c as follows, as a list of lists, that is, as the list of its rows:

c  = { { .4,   .2,   .3},  { .1,   .3,   .4},  { .3,   .4,   .2}}

(You need to use lower-case c here because upper-case C is a protected system symbol.)

Then to display c as a matrix, use MatrixForm:

MatrixForm[c]

It's a common practice to make such an assignment of a matrix to a name and display it as a matrix all at once, as follows:

c  = { { .4,   .2,   .3},  { .1,   .3,   .4},  { .3,   .4,   .2}};  MatrixForm[c]

Another, more readable, way to assign the matrix value to c is as follows:
• select Create Matrix/Table/Palette from the Input menu; 
• in the pop-up dialog box select the Matrix radio button, type in the numbers of rows and columns, and click the OK button; and 
• enter the desired numbers in the □ placeholders—click the top left placeholder and type the entry there, then use ⇥ to move to the next placeholder, etc. 
The input should look like the following when you are done (you need to type both c = for the assignment and the final semicolon to suppress echo back of the value when you evaluate the cell.

c = (({{.4, .2, .3}, {.1, .3, .4}, {.3, .4, .2}}));

Exercise.  What is the actual value of c after this assignment?  After evaluating a cell to get that value, how can you dispaly c as a matrix—without again using the menu?

Next, the final demand vector and output vector (as lists rather than as column vectors):

d  =  {2000,  3500,  2500};
x  =  {x1,  x2,  x3};

The matrix form of the output = intermediate demand + final demand equations (*) is therefore x == c.x + d.  You may use Solve directly now to solve it:

Solve[x  ==  c . x  +  d, x]

Exercise.  Again use the matrix form of output = intermediate demand + final demand equations but make the changes needed in order to obtain the exact solution (without any decimals).

Using matrices to solve the system in standard matrix form A (Overscript[x,  ->])   =  (Overscript[d,  ->])

Clear[x,  x1,  x2,  x3]

x  =  {x1,  x2,  x3};

For consumption matrix C, output vector (Overscript[x,  ->]) , and final demand vector (Overscript[d,  ->]) , the output = intermediate demand + final-demand equations take the matrix form
	(Overscript[x,  ->])   =  
        C (Overscript[x,  ->])   +  (Overscript[d,  ->]) .
Rewrite this as
	(I  -  
              C) (Overscript[x,  ->])   =  (Overscript[d,  ->]) 
where I is the 3 × 3 identity matrix.  Form the coefficient matrix A  =  I  -  C in in Mathematica:

A  =  IdentityMatrix[3]  -  c

Exercise.  Display A as an actual 2 × 2 matrix, not as a one-dimensional list of lists.

Now solve the resulting matrix equation A . x == d:

Solve[A  .  x  ==  d,  x]

Exercise.  Set up and solve the output = intermediate demand + final-demand equations in matrix form A (Overscript[x,  ->])   =  (Overscript[d,  ->])  again, but this time without explicitly using the name A for the coefficient matrix.

Exercise.  Display as an actual column vector (with three rows) the output vector (Overscript[x,  ->])  obtained as solution to this problem.