Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (compose f g)
- (lambda (x) (f(g x))))
- (define (derive f dx)
- (lambda (x)
- (/(-(f(+ x dx)) (f x)) dx)))
- (define (square x) (* x x))
- (define (cube x) (* x x x))
- (define (repeated f N)
- (cond ((= n 0) (lambda(x) x))
- ((= n 1) f)
- (else (compose f
- (repeated f (- N 1))))))
- (define (id1 x) 1)
- (define (square1 x)(* 2 x))
- (define (qube1 x) (* 3 x x))
- (define (compare f g x)
- (display "(f x) = ")
- (display (f x))
- (display " (g x)")
- (display (g x))
- (display " compare: ")
- (display (= (f x) (g x)))
- (display " difference: ")
- (display (- (f x)(g x)))
- (display "\n"))
- (define (compare1 f g x)
- (let (
- (valueF (f x))
- (valueG (g x))
- )
- (diaplay " (f x) = ")(display (valueF))
- (diaplay " (g x) = ")(display (valueG))
- (display " compare: ")(display (= valueF valueG))
- (display " difference: ")(display (- valueF valueG))))
- (define (cube2 x) (* 6 x))
- (define (cube3 x) 6)
- (define (id x) x)
- (define (compare-interval f g a b)
- (if (> a b) (display "End.\n")
- (begin (compare f g a)
- (compare-interval f g (+ a 1) b))))
- (display "Comparing id and id1:\n")
- (compare-interval (derive id 0.00001) id1 1 10)
- (compare (derive square 0.00001) square1 1.99999999999)
- (define (deriveN f N dx)
- ((repeated (lambda(f) derive f dx) N) f)
- )
- (compare-interval (deriveN cube 2 0.00001) cube2 1 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement