CSE 1729 Lecture Notes - Lecture 30: Euclidean Vector

60 views1 pages
Verified Note

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))

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions