;(require (lib "trace.ss")) ;(define (cputime f . args) ; (define-values (result cpu real gc) (time-apply f args)) ; (* 1.0 cpu)) ; ;(define (factor o n f . args) ; (define-values (result cpu real gc) (time-apply f args)) ; (* 1.0 (/ cpu (o n)))) ;; ;Aufgabe 1 ; ;(define (alignments m n) ; (if (or (= m 0) (= n 0)) 1 ; (+ (alignments (- m 1) n) (alignments (- m 1) (- n 1)) (alignments m (- n 1))) ; ) ; ) ; ;;(alignments 5 9) ; ;(define (fak n) ; (if (<= n 1) ; 1 ; (* n (fak (- n 1))))) ;(define (alignments-i m n) ; (define (alignments-for-length l) ; (define (sum-fak a b) ; (cond ((> a b) 0) ; (else (+ (/ (fak a) (* (fak (- a m)) (fak (- a n)) (fak (- b a)))) (sum-fak (+ a 1) (+ m n)))) ; ) ; ) ; (sum-fak l (+ m n)) ; ) ; (alignments-for-length (max m n)) ; ) ;;(alignments-i 50 90) ; ;; ;Aufgabe 2 ; ;(define (f n) ; (if (< n 3) 1 ; (+ (* 3 (f (- n 1))) (* -2 (f (- n 2))) (* 3 (f (- n 3)))) ; ) ; ) ;; Laufzeitabschätzung ;(define basis 1.84) ;(define (f-o n) (expt basis n)) ; ;; Bestimmung des Proportionalitätsfaktors ;;(factor f-o 33 f 33) ;;(factor f-o 22 f 22) ;;(factor f-o 23 f 23) ;;(factor f-o 24 f 24) ;;(factor f-o 25 f 25) ;;(factor f-o 26 f 26) ;;(factor f-o 27 f 27) ;;(factor f-o 28 f 28) ;;(factor f-o 29 f 29) ;;(factor f-o 30 f 30) ;; Proportionalitätsfaktor ca. 0.00019 ;;(/ (* 0.00019 (f-o 100)) 1000 60 60 24 365) ;;(f 10) ; ;(define (f n) ; (define (f-iter a b c d) ; (if (< d n) (f-iter (+ (* 3 a) (* -2 b) (* 3 c)) a b (+ d 1)) a) ; ) ; ;(trace f-iter) ; (f-iter 1 1 0 1) ; ) ;;(trace f) ;;(f 10) ;;(f 100) --> 1159988228848170573365003508337887644164465 ;; Laufzeitabschätzung ;(define basis 1) ;(define (f-o n) (* n n)) ; ;; Bestimmung des Proportionalitätsfaktors ;(factor f-o 33 f 33) ;(factor f-o 22 f 22) ;(factor f-o 23 f 23) ;(factor f-o 24 f 24) ;(factor f-o 25 f 25) ;(factor f-o 26 f 26) ;(factor f-o 27 f 27) ;(factor f-o 28 f 28) ;(factor f-o 29 f 29) ;(factor f-o 100 f 100) ;; Proportionalitätsfaktor ca. 0.00019 ;(display 'moep) (/ (* 0.0015 (f-o 100)) 1000 60 ) ;;Aufgabe 4 - rekursiv ;(define (square x) (* x x)) ;(define (trapez f a b n) ; (define h (if (< a b) (/ (- b a) n) (/ (- a b) n))) ; (define (trapez-fläche a)(* (/ (+ (f a) (f (+ a h))) 2) h)) ; (define (berechnung f a b n) ; (if (< a b) (+ (trapez-fläche a) (berechnung f (+ a h) b n)) ; 0)) ; (if (< a b) (berechnung f a b n) (* -1 (berechnung f b a n))) ; ) ;;(trace square) ;;(trace trapez) ;(trapez square 0 10 10) ;;iterativ ;(define (trapez f a b n) ; (define h (if (< a b) (/ (- b a) n) (/ (- a b) n))) ; (define (trapez-fläche a)(* (/ (+ (f a) (f (+ a h))) 2) h)) ; (define (berechnung f x z) ; (if (= x n) z ; (berechnung f (+ x h) (+ z (trapez-fläche x))));(* (/ (+ (f a) (f (+ a h))) 2) h) ; ) ; (berechnung f a 0)) ;(trapez square 0 10 10)