#
Matrix operations
^{
}

Suppose we represent vectors v = (vᵢ) as sequences of numbers, and matrices m = (mᵢⱼ) as sequences of vectors (the rows of the matrix). For example, the matrix

is represented as the sequence ((1 2 3 4) (4 5 6 6) (6 7 8 9)). With this representation, we can use sequence operations to concisely express the basic matrix and vector operations. These operations (which are described in any book on matrix algebra) are the following:

(dot-product v w) returns the sum ∑ᵢvᵢwᵢ;

(matrix-*-vector m v) returns the vector t, where tᵢ = ∑ⱼmᵢⱼvᵢ;

(matrix-*-matrix m n) returns the matrix p, where pᵢⱼ = ∑ₖmᵢₖnₖⱼ

(transpose m) returns the matrix n, where nᵢⱼ = mⱼᵢ

We can define the dot product as

```
(define (dot-product v w)
(accumulate + 0 (map * v w)))
```

Fill in the missing expressions in the following procedures for computing the other matrix operations. (The procedure accumulate-n is defined in exercise 2.36 .)

```
(define (matrix-*-vector m v)
(map <??> m))
(define (transpose mat)
(accumulate-n <??> <??> mat))
(define (matrix-*-matrix m n)
(let ((cols (transpose n)))
(map <??> m)))
```

```
(define m (list (list 1 2)
(list 3 4)))
(define m2 '((1 2 3 4)
(4 5 6 6)
(6 7 8 9)))
(define m2-transpose '((1 4 6)
(2 5 7)
(3 6 8)
(4 6 9)))
(define v (list 1 2))
(define x1 (list 2 3))
(define x2 (list 3 2))
(check-equal? (dot-product v x1) 8)
(check-equal? (dot-product v x2) 7)
(check-equal? (matrix-*-vector m v) (list 5 11))
(check-equal? (transpose m) (list (list 1 3)
(list 2 4)))
(check-equal? (transpose m2) m2-transpose)
(check-equal? (matrix-*-matrix m m) '((7 10)
(15 22)))
```