In [1]:
from mth309 import *

1.3 Example 5 (pp28-29)

In [2]:
A = Matrix( [[1,2,7],[-2,5,4],[-5,6,-3]] )
A
Out[2]:
  1 2  7
 -2 5  4
 -5 6 -3
In [3]:
re(A)
Out[3]:
 1 2 7
 0 1 2
 0 0 0

From the RRE form above, we see the system is consistent - there is a linear combination that gives the desired vector.

And we can read off the solution (the values of the coefficients) from the RRE form below:

In [4]:
rre(A)
Out[4]:
 1 0 3
 0 1 2
 0 0 0

1.3.28 Coal-burning power plant problem

This problem has non-integer data, so we need to see how to enter rational numbers into a matrix.

In [7]:
from fractions import Fraction as frac
In [8]:
frac(21,3)
Out[8]:
Fraction(7, 1)
In [9]:
frac(14,28)
Out[9]:
Fraction(1, 2)
In [13]:
C = Matrix( [[frac(276,10),frac(302,10),162],[3100,6400,23610],[250,360,1623]] )
C
Out[13]:
 138/5 151/5   162
  3100  6400 23610
   250   360  1623
In [14]:
re(C)
Out[14]:
 1 151/138 135/23
 0       1    9/5
 0       0      0
In [15]:
rre(C)
Out[15]:
 1 0 39/10
 0 1   9/5
 0 0     0
In [ ]: