Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; (list-of-areas F xmin xmax nsteps) produces the list of areas of rectangeles
- ;; under the graph of the Function F
- ;; list-of-areas : Function Num Num Nat -> (listof Num)
- ;; requires : xmin less than or equal to xmax
- ;; Example :
- (check-expect (list-of-areas (lambda (x) (+ (* x x) 1)) 2 4 4)
- (list 2.5 3.625 5 6.625))
- (define (list-of-areas F xmin xmax nsteps)
- (map (lambda (x) (* x (/ (- xmax xmin) nsteps)))
- (map F (range xmin xmax (/ (- xmax xmin) nsteps)))))
- ;; (riemann-sum F xmin xmax nsteps) finds the area under the graph of Function F
- ;; using Riemann Sums with nsteps steps between xmin and xmax
- ;; riemann-sums : Function Num Num Nat -> Num
- ;; requires : xmin less than or equal to xmax
- ;; Example :
- (check-expect (riemann-sum (lambda (x) 3) 1 5 100) 12)
- (define (riemann-sum F xmin xmax nsteps)
- (foldr + 0 (list-of-areas F xmin xmax nsteps)))
- ;; Tests :
- (check-expect (riemann-sum (lambda (x) (+ (* x x) 1)) 2 4 4) 17.75)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement