Lecture 22: Gauss, Prince of Mathematics



  1. Reading: TSS, chapter 11
  2. Solving a system of equations:
    2 * z + 2 * x + 3 * y = 10
    2 * z + 5 * x + 12 * y = 31
    4 * z + 1 * x + -2 * y = 1

    A solution is a substitution of one number per variable such that the equations work out.
    Here is a solution for the above set of equations: z = 1, x = 1, y = 2. Task: check that it is a solution.

  3. Gauss suggested a method for solving a system of equations. It consists of two phases: triangulation and then the solution process proper.
    First, we need a representation for equations.
    (list
    (list 223 10)
    (list 2512 31)
    (list 41-2 1))

    Second, we need to see what it means to manipulate (representations of) these equations:
    (list
    (list 223 10)
    (list 2512 31)
    (list 41-2 1))
    (list
    (list 223 10)
    (list 39 21)
    (list -3-8 -19))
    (list
    (list 223 10)
    (list 39 21)
    (list 1 2))

    This last set of equations has triangular form and it is easy to solve.
    Task: Solve the corresponding system of equations systematically.

  4. Time to design a Scheme program for triangulation:
    Data Definition:
    A matrix is a (listof (listof num)).
    
      Constraints:
       1. Each item on a matrix has the same length.
       2. The first item on a matrix is by one item longer than the matrix itself.
    
    A trimat is a (listof (listof num)).
    
      Constraints:
       1. Each item on a trimat is by one item longer than the following one.
       2. The first item on a trimat is by one item longer than the trimat itself.
       3. The last one contains two items (nums). 
    

    Contract, header, and purpose:
      triangulate : matrix -> trimat
      (define (triangulate a-matrix) ...)
    
      Purpose: compute a triangular matrix from a-matrix (with the same solution)
    

    Example: see above
    Template:
    1. trivial problem: matrix with one row
    2. trivial solution: the matrix
    3. generative step:
      subtract the first row from the remaining rows an appropriate number of times from the remaining ones, eliminate the leading 0
      then process the remaining equations
      combine the resulting trimat with the first row

    Definition:
    (define (triangulate mat)
      (cond
        ((empty? (rest mat)) (first mat))
        (else (local ((define row1 (first mat)))
    	    (cons row1 (triangulate (subtract-row1-from-all-rows row1 (rest mat))))))))
    

    does every recursive application use triangulate on a matrix? YES!
    Define auxiliary function:
    #|
      subtract-row1-from-all-rows : (listof num) (listof (listof num)) -> (listof (listof num))
    
      (define (subtract-row1-from-all-rows row1 other-rows) ...)   
    
       Purpose: subtract enough multiples of row1 from all rows in other-rows
         so that first number of each new one is 0. Eliminate the 0, i.e., 
         all rows in result are one shorter than row1
    
       Example: 
        (subtract-row1-from-all-rows (list 2 3 4)
    				 (list (list 2 3 4)
    				       (list 4 4 4)))
        = 
        (list 
         (list  0  0)
         (list -2 -4))
    |#
    




Matthias Felleisen This page was generated on Fri Apr 9 09:17:38 CDT 1999.