Vaje tretjega krozka

main
Jurij Podgoršek 2024-05-17 01:08:49 +02:00
parent b4dad87166
commit 4c1b758a56
1 changed files with 40 additions and 0 deletions

View File

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