Description
Unit tests: At a minimum, your program must pass the Numerator
4.0
-4.0 4.0
-4.0 4.0
-4.0 4.0
-4.0 4.0
-4.0
4.0 Denominator
1.0
3.0
5.0
7.0
9.0
11.0
13.0
15.0
17.0 19.0
21.0 Sum
0.0
4.0
2.666
3.466
2.895
3.339
2.976
3.283
3.017 3.252
3.041
unit tests found in the file lab01-test.rkt. Place Make sure your program starts its loop with floating this file in the same folder as your program, and run point numbers, e.g. 4.0, 1.0, etc. If you start with it; there should be no output. exact integers, Scheme will try to keep exact rational numbers through all of those computations and it will be substantially slower. Also, your answers Program: Write a Scheme procedure called make-pi to will look like this:
compute π using the (slowly converging) series:
(make-pi 0.1) =>
516197940314096/166966608033225
Make sure to follow the general rules about func-
The procedure takes one parameter, which will be tional programming: write lots of functions, no asthe accuracy we need. We can stop whenever the signment statements, no for or while loops, use next factor we would add is smaller than this accu- cond instead of if.
(make-pi 0.1) => 3.09162380666784
(make-pi 0.001) => 3.1410926536210413
(make-pi 0.0000001) => 3.141592603589817
#lang racket
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Lab #1
;;
;; Your Name Here
;; W012345678
;;
;; The purpose of this program is to
;; bla bla bla
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(provide make-pi)
(define make-pi
(lambda (tolerance) 3.1415))
racy. For example: Name your program lab01.rkt and include a comment block like the one shown (with your own name and W number). Also, hopefully, with the correct code, although this one will pass the unit tests!
lab01.rkt
Be careful! This series converges very slowly. If you’re curious, instrument the procedure so that it also prints out the number of iterations it took to get the accuracy (this is optional).
Make sure that your program returns the value of π computed, and doesn’t just print it. For example, this should not give an error: (+ (make-pi 0.1) (make-pi 0.1))
To get the loop done, define a recursive procedure with (at least) three parameters that behave like this (I’ve truncated the decimals):
1




Reviews
There are no reviews yet.