1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
5 ;Computes the factorial of n.
10 [else (* n (! (sub1 n)))]))
12 ;series : (N[>=0] -> number) N[>=0] -> number
13 ;Given a-term and n, determine the sum of the first n-th terms in the sequence a-term.
15 (define (series a-term n)
17 [(zero? n) (a-term n)]
19 (series a-term (sub1 n)))]))
21 ;;e-taylor : N -> number
22 ;;Given i, find the i-th term of the Taylor series e^x = 1 + x + (x^2)/2! ...
24 ;e-power : number N -> number
25 ;e-power computes the x-th power of e by summing up n terms of the Taylor sequence.
28 (local ((define (e-taylor i)
29 (/ (expt x i) (! i))))
34 (define (inexact-e-power x n)
35 (exact->inexact (e-power x n)))
37 (inexact-e-power 1 1000)
39 (- (inexact-e-power 1 100) (exp 1))
42 ;ln-taylor : N -> number
43 ;Computes the n-th term of the taylor sequence for ln (x).
45 ;ln-x : number N -> number
46 ;Computes ln(x) by summing the first n-th terms of the Taylor sequence.
49 (local ((define (ln-taylor i)
50 (* 2 (/ (expt (/ (- x 1)
54 (series ln-taylor n)))
56 ;sin-x : number N -> number
57 ;Determines sin(x) by summing the first n-th terms of the Taylor sequence.
59 ;sin-taylor : N -> number
60 ;Returns the i-th term of the Taylor sequence for sin(x).
63 (local ((define (sin-taylor i)
64 (* (/ (expt x (+ (* 2 i) 1))
69 (series sin-taylor n)))
71 ;pi-greg : N -> number
72 ;Calculates pi by summing the first n-th terms of the Taylor sequence.
75 ;Given i, find the n-th term of the greg series.
78 (local ((define (greg i)