Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-advanced-reader.ss" "lang")((modname |29.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu ;A matrix is a (vectorof (vectorof numbers)). Specifically, an rxc matrix has a vector-length of r, and each element has a vector-length of c.
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu ;build-matrix : N N (N N -> number) -> matrix
7 12687dd9 2023-08-04 jrmu ;Given rows and cols, builds a matrix according to f. f takes in two N's and returns a number (f rows cols).
8 12687dd9 2023-08-04 jrmu
9 12687dd9 2023-08-04 jrmu (define (build-matrix rows cols f)
10 12687dd9 2023-08-04 jrmu (build-vector rows (lambda (r)
11 12687dd9 2023-08-04 jrmu (build-vector cols (lambda (c) (f (+ r 1) (+ c 1)))))))
12 12687dd9 2023-08-04 jrmu
13 12687dd9 2023-08-04 jrmu (define (transpose a-matrix)
14 12687dd9 2023-08-04 jrmu (build-matrix (vector-length (vector-ref a-matrix 0))
15 12687dd9 2023-08-04 jrmu (vector-length a-matrix)
16 12687dd9 2023-08-04 jrmu (lambda (r c) (vector-ref (vector-ref a-matrix (sub1 c)) (sub1 r)))))
17 12687dd9 2023-08-04 jrmu
18 12687dd9 2023-08-04 jrmu (define matrix-A (vector (vector 1 0 -1)
19 12687dd9 2023-08-04 jrmu (vector 2 0 9)
20 12687dd9 2023-08-04 jrmu (vector 1 1 1)))
21 12687dd9 2023-08-04 jrmu (transpose matrix-A)