You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
692 B
33 lines
692 B
(define (cube x) |
|
(* x x x)) |
|
|
|
(define (inc x) |
|
(+ x 1)) |
|
|
|
(define (sum term a next b) |
|
(define (iter a result) |
|
(if (> a b) |
|
result |
|
(iter (next a) (+ result (term a))))) |
|
(iter a 0)) |
|
|
|
; after here this is all copied from example |
|
; 29, it's unimportant |
|
; |
|
; i also don't understand integral calculus |
|
|
|
(define (integral f a b dx) |
|
(define (add-dx x) |
|
(+ x dx)) |
|
(* (sum f (+ a (/ dx 2.0)) add-dx b) |
|
dx)) |
|
|
|
(define (simpson f a b n) |
|
(define h (/ (- b a) n)) |
|
(define (yk k) (f (+ a (* h k)))) |
|
(define (simpson-term k) |
|
(* (cond ((or (= k 0) (= k n)) 1) |
|
((odd? k) 4) |
|
(else 2)) |
|
(yk k))) |
|
(* (/ h 3.0) (sum simpson-term 0 inc n)))
|
|
|