This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 135 Winter 2012 Brad Lushman Assignment: 5 Due: Wednesday, February 15, 9:15am Language level: Beginning Student with List Abbreviations Allowed recursion: Pure structural Files to submit: sine.rkt , index.rkt Warmup exercises: HtDP 12.2.1, 13.0.3, 13.0.4, 13.0.7, 13.0.8 Practise exercises: HtDP 13.0.5, 13.0.6, 17.1.1, 17.1.2, 17.2.1, 17.2.2 Here are the assignment questions you need to submit. 1. As you will learn in your calculus class, many well-known functions can be expressed as infinite sums, known as Taylor series . For example, sin x = x- x 3 3! + x 5 5!- x 7 7! + x 9 9! + ··· + (- 1) n- 1 x 2 n- 1 (2 n- 1)! + ··· In fact, this is how calculators and computer programs typically compute these functions. In this problem, you will write a Scheme function to compute the trigonometric sine function. (a) The sine function is best expressed as a sum of terms over the odd natural numbers n (since the first term is the x 1 term, the second term is the x 3 term, the third term is the x 5 term, etc.). In comments, write a recursive data definition for odd natural numbers. (b) Use your data definition to derive a template for functions operating on odd natural numbers. Present your template in comments. (c) Write the Scheme function taylor-term that consumes a number x and an odd natural number n , and produces the term of the Taylor sum that contains x n . For example, for any number x , ( taylor-term x 7 ) produces the number- x 7 / 7! . (d) Write the Scheme function my-sin that consumes a number x and an odd natural number n , and produces the sum of the terms in the Taylor series, from the first one up to and including the term containing x n . For example, for any number x , ( my-sin x 3 ) produces the number x- x 3 / 3! . Test your function by comparing its output with the output of the built-in sin function. Note, however, that the built-in sin function produces inexact quantities, so test your program using check-within . Place your solution in the file sine.rkt . 2. Open any non-fiction book, and you’ll find an index at the back, which helps you find topics of interest, by indicating, for (almost) every word in the book, which pages contain that word. Obviously, no one actually takes the time to manually record every occurrence of every word in the book; rather, we use an automated process to compute the index for us. In this problem, you will write a Scheme program to automatically compute an index....
View Full Document