Original English by Jim Hefferon — 34 validated sections. The original mathematics and supplied answers below are preserved. This is a partial-book reading edition, not the complete book or an Everyday-English rewrite.

Source revision df2262e089a02651c127f1dd12649c4622ee1383; CC BY-SA 2.5 option, with original component credits retained. This is not an Everyday-English rewrite. Source-only material after the author’s explicit end-of-file command is not included.

Source-preserving rebuild, navigation, source packaging and current deterministic checks: OpenAI Codex — GPT-6 Astra, Ultra effort. Jim Hefferon remains the author of the mathematics. Earlier intermediate-conversion runtime identity is not established by its retained receipts and is not reassigned to this rebuild. No human review or exhaustive proof certification is claimed.

Computer Algebra Systems

The linear systems in this chapter are small enough that their solution by hand is easy. For large systems, including those involving thousands of equations, we need a computer. There are special purpose programs such as LINPACK for this. Also popular are general purpose computer algebra systems including Maple, Mathematica, or MATLAB, and Sage.

For example, in the Topic on Networks, we need to solve this.

i 0 − i 1 − i 2 = 0 i 1 − i 3 − i 5 = 0 i 2 − i 4 + i 5 = 0 i 3 + i 4 − i 6 = 0 5 i 1 + 10 i 3 = 10 2 i 2 + 4 i 4 = 10 5 i 1 − 2 i 2 + 50 i 5 = 0

Doing this by hand would take time and be error-prone. A computer is better.

Here is that system solved with Sage. (There are many ways to do this; the one here has the advantage of simplicity.)

sage: var('i0,i1,i2,i3,i4,i5,i6')
(i0, i1, i2, i3, i4, i5, i6)
sage: network_system=[i0-i1-i2==0, i1-i3-i5==0, 
....:       i2-i4+i5==0, i3+i4-i6==0, 5*i1+10*i3==10,
....:       2*i2+4*i4==10, 5*i1-2*i2+50*i5==0]
sage: solve(network_system, i0,i1,i2,i3,i4,i5,i6)     
[[i0 == (7/3), i1 == (2/3), i2 == (5/3), i3 == (2/3), 
      i4 == (5/3), i5 == 0, i6 == (7/3)]] 

Magic.

Here is the same system solved under Maple. We enter the array of coefficients and the vector of constants, and then we get the solution.

> A:=array( [[1,-1,-1,0,0,0,0],
             [0,1,0,-1,0,-1,0],
             [0,0,1,0,-1,1,0],
             [0,0,0,1,1,0,-1],
             [0,5,0,10,0,0,0],
             [0,0,2,0,4,0,0],
             [0,5,-2,0,0,50,0]] );
> u:=array( [0,0,0,0,10,10,0] );
> linsolve(A,u);
      7  2  5  2  5     7
    [ -, -, -, -, -, 0, - ]
      3  3  3  3  3     3

If a system has infinitely many solutions then the program will return a parametrization.

Exercises

  1. Exercise 1 Worked answer

    Use the computer to solve the two problems that opened this chapter.

    1. This is the Statics problem.

      40 h + 15 c = 100 25 c = 50 + 50 h

    2. This is the Chemistry problem.

      7 h = 7 j 8 h + 1 i = 5 j + 2 k 1 i = 3 j 3 i = 6 j + 1 k

    Back to Exercise 1

    Answer.

    1. Sage does this.

      sage: var('h,c')
      (h, c)
      sage: statics = [40*h + 15*c == 100,
      ....:            25*c == 50 + 50*h]
      sage: solve(statics, h,c)
      [[h == 1, c == 4]] 

      Other Computer Algebra Systems have similar commands. These Maple commands

      > A:=array( [[40,15],
                   [-50,25]] );
      > u:=array([100,50]);
      > linsolve(A,u);

      get the answer [1,4].

    2. Here there is a free variable. Sage gives this.

      sage: var('h,i,j,k')
      (h, i, j, k)
      sage: chemistry = [7*h == 7*j,
      ....:              8*h + 1*i == 5*j + 2*k,
      ....:              1*i == 3*j,
      ....:              3*i == 6*j + 1*k]
      sage: solve(chemistry, h,i,j,k)
      [[h == 1/3*r1, i == r1, j == 1/3*r1, k == r1]]          

      Similarly, this Maple session

      > A:=array( [[7,0,-7,0],
                   [8,1,-5,2],
                   [0,1,-3,0],
                   [0,3,-6,-1]] );
      > u:=array([0,0,0,0]);
      > linsolve(A,u);

      prompts the same reply (but with parameter t 1 ).

  2. Exercise 2 Worked answer

    Use the computer to solve these systems from the first subsection, or conclude ‘many solutions’ or ‘no solutions’.

    1. 2 x + 2 y = 5 x − 4 y = 0

    2. − x + y = 1 x + y = 2

    3. x − 3 y + z = 1 x + y + 2 z = 14

    4. − x − y = 1 − 3 x − 3 y = 2

    5. 4 y + z = 20 2 x − 2 y + z = 0 x + z = 5 x + y − z = 10

    6. 2 x + z + w = 5 y − w = − 1 3 x − z − w = 0 4 x + y + 2 z + w = 9

    Back to Exercise 2

    Answer.

    1. The answer is x = 2 and y = 1 / 2 . A Sage session does this.

      sage: var('x,y')
      (x, y)
      sage: system = [2*x + 2*y == 5,
      ....:              x - 4*y == 0]
      sage: solve(system, x,y)
      [[x == 2, y == (1/2)]]          

      A Maple session

      > A:=array( [[2,2],
                   [1,-4]] );
      > u:=array([5,0]);
      > linsolve(A,u);            

      gets the same answer, of course.

    2. The answer is x = 1 / 2 and y = 3 / 2 .

      sage: var('x,y')
      (x, y)
      sage: system = [-1*x + y == 1,
      ....:              x + y == 2]
      sage: solve(system, x,y)
      [[x == (1/2), y == (3/2)]]          
    3. This system has infinitely many solutions. In the first subsection, with z as a parameter, we got x = ( 43 − 7 z ) / 4 and y = ( 13 − z ) / 4 . Sage gets the same.

      sage: var('x,y,z')
      (x, y, z)
      sage: system = [x - 3*y + z == 1,
      ....:           x + y + 2*z == 14]
      sage: solve(system, x,y)
      [[x == -7/4*z + 43/4, y == -1/4*z + 13/4]]             

      Maple responds with ( − 12 + 7 t 1 , t 1 , 13 − 4 t 1 ) , preferring y as a parameter.

    4. There is no solution to this system. Sage gives an empty list.

      sage: var('x,y')
      (x, y)
      sage: system = [-1*x - y == 1,
      ....:           -3*x - 3*y == 2]
      sage: solve(system, x,y)
      []          

      Similarly, When the array A and vector u are given to Maple and it is asked to linsolve(A,u), it returns no result at all; that is, it responds with no solutions.

    5. Sage finds

      sage: var('x,y,z')
      (x, y, z)
      sage: system = [       4*y + z == 20,
      ....:            2*x - 2*y + z == 0,
      ....:             x +        z == 5,
      ....:             x +    y - z == 10]
      sage: solve(system, x,y,z)
      [[x == 5, y == 5, z == 0]]          

      that the solutions is ( x , y , z ) = ( 5 , 5 , 0 ) .

    6. There are infinitely many solutions. Sage does this.

      sage: var('x,y,z,w')
      (x, y, z, w)
      sage: system = [ 2*x +        z + w == 5,
      ....:                   y -       w == -1,
      ....:            3*x -        z - w == 0,
      ....:            4*x +  y + 2*z + w == 9]
      sage: solve(system, x,y,z,w)
      [[x == 1, y == r2 - 1, z == -r2 + 3, w == r2]]          

      Maple gives ( 1 , − 1 + t 1 , 3 − t 1 , t 1 ) .

  3. Exercise 3 Worked answer

    Use the computer to solve these systems from the second subsection.

    1. 3 x + 6 y = 18 x + 2 y = 6

    2. x + y = 1 x − y = − 1

    3. x 1 + x 3 = 4 x 1 − x 2 + 2 x 3 = 5 4 x 1 − x 2 + 5 x 3 = 17

    4. 2 a + b − c = 2 2 a + c = 3 a − b = 0

    5. x + 2 y − z = 3 2 x + y + w = 4 x − y + z + w = 1

    6. x + z + w = 4 2 x + y − w = 2 3 x + y + z = 7

    Back to Exercise 3

    Answer.

    1. This system has infinitely many solutions. In the second subsection we gave the solution set as

      { ( 6 0 ) + ( − 2 1 ) y ∣ y ∈ ℝ }

      and Sage finds

      sage: var('x,y')
      (x, y)
      sage: system = [ 3*x + 6*y == 18,
      ....:              x + 2*y == 6]
      sage: solve(system, x,y)
      [[x == -2*r3 + 6, y == r3]]                

      while Maple responds with ( 6 − 2 t 1 , t 1 ) .

    2. The solution set has only one member.

      { ( 0 1 ) }

      Sage gives this.

      sage: var('x,y')
      (x, y)
      sage: system = [ x + y == 1,
      ....:            x - y == -1]
      sage: solve(system, x,y)
      [[x == 0, y == 1]]            
    3. This system’s solution set is infinite

      { ( 4 − 1 0 ) + ( − 1 1 1 ) x 3 ∣ x 3 ∈ ℝ }

      Sage gives this

      sage: var('x1,x2,x3')
      (x1, x2, x3)
      sage: system = [   x1 +        x3 == 4,
      ....:              x1 - x2 + 2*x3 == 5,
      ....:            4*x1 - x2 + 5*x3 == 17]
      sage: solve(system, x1,x2,x3)
      [[x1 == -r4 + 4, x2 == r4 - 1, x3 == r4]]            

      and Maple gives ( t 1 , − t 1 + 3 , − t 1 + 4 ) .

    4. There is a unique solution

      { ( 1 1 1 ) }

      and Sage finds it.

      sage: var('a,b,c')
      (a, b, c)
      sage: system = [ 2*a +  b - c == 2,
      ....:            2*a +      c == 3,
      ....:              a - b      == 0]
      sage: solve(system, a,b,c)
      [[a == 1, b == 1, c == 1]]             
    5. This system has infinitely many solutions; in the second subsection we described the solution set with two parameters.

      { ( 5 / 3 2 / 3 0 0 ) + ( − 1 / 3 2 / 3 1 0 ) z + ( − 2 / 3 1 / 3 0 1 ) w ∣ z , w ∈ ℝ }

      Sage does the same.

      sage: var('x,y,z,w')
      (x, y, z, w)
      sage: system = [   x + 2*y - z     == 3,
      ....:            2*x +   y     + w == 4,
      ....:              x -   y + z + w == 1]
      sage: solve(system, x,y,z,w)
      [[x == r6, y == -r5 - 2*r6 + 4, z == -2*r5 - 3*r6 + 5, w == r5]]             

      as does Maple ( 3 − 2 t 1 + t 2 , t 1 , t 2 , − 2 + 3 t 1 − 2 t 2 ) .

    6. The solution set is empty.

      sage: var('x,y,z,w')
      (x, y, z, w)
      sage: system = [   x +      z + w == 4,
      ....:            2*x +  y     - w == 2,
      ....:            3*x +  y + z     == 7]
      sage: solve(system, x,y,z,w)
      []          
  4. Exercise 4 Worked answer

    What does the computer give for the solution of the general 2 × 2 system?

    a x + c y = p b x + d y = q

    Back to Exercise 4

    Answer. Sage does this.

    sage: var('x,y,a,b,c,d,p,q')
    (x, y, a, b, c, d, p, q)
    sage: system = [ a*x +  c*y == p,
    ....:            b*x +  d*y == q]
    sage: solve(system, x,y)
    [[x == -(d*p - c*q)/(b*c - a*d), y == (b*p - a*q)/(b*c - a*d)]]        

    In response to this prompting

    > A:=array( [[a,c],
                 [b,d]] );
    > u:=array([p,q]);
    > linsolve(A,u);

    Maple gave this reply.

    [ − − d p + q c − b c + a d , − b p + a q − b c + a d ]