; ======================================================================
;
; Structure and Interpretation of Computer Programs
; (trial answer to excercises)
;
; 计算机程序的构造和解释(习题试解)
;
; created: code17 08/19/05
; modified:
; (保持内容完整不变前提下,可以任意转载)
; ======================================================================
;; SICP No.2.37
(define (matrix-*-vector m v)
(map (lambda (x) (dot-product x v)) m))
(define (transpose mat)
(accumulate-n cons () mat))
(define (matrix-*-matrix m n)
(let ((cols (transpose n)))
(map (lambda (x) (matrix-*-vector cols x)) m)))
;; Test-it:
;; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
;; > (define m (list (list 1 2 3 4) (list 4 5 6 6) (list 6 7 8 9)))
;; > (define v (list 4 3 2 1))
;; > (matrix-*-vector m v)
;; (20 49 70)
;; > > (transpose m)
;; ((1 4 6) (2 5 7) (3 6 8) (4 6 9))
;; > (matrix-*-matrix m (transpose m))
;; ((30 56 80) (56 113 161) (80 161 230))