CSE 1729 Lecture Notes - Lecture 30: Euclidean Vector
CSE 1729 verified notes
30/30View all
Document Summary
Lecture 30: vectors: accumulating a vector sum (functionally): (define (vector-sum v) (define (sum-accumulate i) (if (>= i (vector-length v)) 0 (+ (vector-ref v i) (sum-accumulate (+ i 1))))) (sum-accumulate 0)) > (vector-sum (vector 1 2 3 4 5)) 15: using do: loops through the array, for each index, it destructively updates the result (define (vector-sum-d v) (let ((result 0)) (do ((index 0 (+ index 1))) ((>= index (vector-length v)) result) (set! > (vector-sum-d (vector 1 2 3 4 5)) Inner product: idea: sum of the product of identical components; both vectors have the same length (define (vector-product v1 v2) (let ((sp 0)) (do (i 0 (+ i 1))) ((>= i (vector-length v1)) sp) (set! Sp (+ sp (* vector-ref v1 i) (vector-ref v2 i))))))) > (vector-product (vector 1 2 3) (vector 4 5 6))