Vaje tretjega krozka
parent
b4dad87166
commit
4c1b758a56
|
@ -0,0 +1,40 @@
|
|||
;; 1.29
|
||||
(define(cube x)
|
||||
(* x x x))
|
||||
|
||||
(define(sum-integers a b)
|
||||
(if ( > a b)
|
||||
0
|
||||
(+ a (sum-integers (+ a 1) b))))
|
||||
|
||||
(define(sum-cubes a b)
|
||||
(if (> a b)
|
||||
0
|
||||
(+ (cube a) (sum-cubes(+ a 1) b))))
|
||||
|
||||
|
||||
(define (sum term a next b)
|
||||
(if (> a b)
|
||||
0
|
||||
(+ (term a)
|
||||
(sum term (next a) next b))))
|
||||
|
||||
(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 (add-hh a) (+ a h h))
|
||||
(* (+ (- (f a))
|
||||
(* 2 (sum f a add-hh b))
|
||||
(* 4 (sum f (+ a h) add-hh b))
|
||||
(- (f b)))
|
||||
(/ h 3.0)))
|
||||
|
||||
|
||||
(display (simpson cube 1 2 100))
|
||||
(display "\n")
|
||||
(display (simpson cube 1 2 1000))
|
||||
(display "\n")
|
Loading…
Reference in New Issue