This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 – Structure and Interpretation of Computer Programs Spring Semester, 2005 Project 1 – Those amazing Red Sox! 1. Issued: Monday, February 7 2. To Be Completed By: Friday, February 18, 6:00 PM 3. Code to load for this project: 1. A link to the code file basebot.scm is provided from the Projects link on the projects section. This file contains the skeleton of the procedures described here, and some utility procedures you will need. Purpose The purpose of Project 1 is for you to gain experience with writing and testing relatively simple procedures. You should create a file with your project solutions for uploading to the 6.001 on-line tutor. For each problem below, include your code (with identification of the problem number being solved), as well as comments and explanations of your code, and demonstrate your code’s functionality against a set of test cases. On occasion, we may provide some example test cases, but you should always create and include your own additional, meaningful test cases to ensure that your code works not only on typical inputs, but also on “boundary” or difficult cases. Get in the habit of writing and running these test cases after every procedure you write – no matter how trivial the procedure may seem to you. Additional guidelines for project submission are available under the “How to write up a project” link on the projects section. Scenario As you may have noticed this past fall, a remarkable event took place – the Boston Red Sox won the World Series for the first time in 86 years! You may also have noticed long time Boston residents (such as MIT professors) walking about in a state of bliss. Because many of these folks don’t want to have to wait another 86 years for this to happen again, “Red Sox Nation” has hired us to provide some help. In particular, we are to investigate the possibility of perfecting a baseball robot (“basebot”) that can accurately throw and can hit with power. Problem 1: Some simple physics We are going to begin by modeling how far a baseball can travel – the same physics will hold for both hitting a ball and throwing a ball. We are going to simplify things byassuming that baseballs don’t spin as they move (clearly false but it makes life much easier). This means we can treat the movement of a baseball as if it were restricted to a two-dimensional plane. So what happens when a baseball is hit? For the moment, we'll model a baseball as a particle that moves along a single dimension with some initial position u, some initial velocity v, and some initial acceleration a, as pictured in Figure 1 below. The equation for the position of the baseball at time t, given a, v, and u is ut = ½ a t2 + v t + u. Note that this denotes a first order differential equation in time. Later, we can apply this equation to either the horizontal (x) component of baseball motion, or the vertical (y) component of baseball motion. v ut a Figure 1: Motion of a b in a generic direction. Write a procedure that takes as input values for a, v, u, and t and returns as output the position of the baseball at time t. (define position(lambda (a v u t)YOUR-CODE-HERE)) Test your position code for at least the following cases: (position 0 0 0 0) ; -> 0(position 0 0 20 0) ; -> 20(position 0 5 10 10) ; -> 60(position 2 2 2 2) ; ->(position 5 5 5 5) ; -> The template code file basebot.scm will have these tests, and other test cases for other procedures, which you should run (you can add/show your output values). In addition, you should add some test cases of your own to these to cover other boundary and typical conditions. Problem 2: Basic Math One of our goals is to determine how far a baseball will travel in the air, if it is hit with some initial velocity at some initial angle with respect to the ground. To do this, we will need to know when the baseball hits the ground, and for that we'll want to find when the y coordinate of the baseball's position reaches zero. This can be discovered by finding the roots of the y position equation, and selecting the one that is larger (later in time). The proper tool for this is the quadratic formula. Given the coefficients of the quadratic uequation az2 + bz + c = 0, write a procedure to find one of the roots (call this root1), and another procedure to find the other root (call this root2). (define root1(lambda (a b c)YOUR-CODE-HERE)) (define root2(lambda (a b c)YOUR-CODE-HERE)) You may notice that, depending on how you wrote your procedures, for some test cases you get an error. For example, try (root1 5 3 6). What happens? If you get an error, which is likely if you wrote your code the straightforward way, figure out how to change it so that your procedure returns a false value in those cases where there is not a valid solution. Problem 3: Flight Time Given an initial upward velocity (in meters per second, or m/s) and initial elevation or height (in meters, or m), write a procedure that computes how long the baseball will be in flight. Remember that gravity is a downward acceleration of 9.8m/s2. Note that to solve this you will need a root of a quadratic equation. Try using root1, and using root2. Only one of these solutions makes sense. Which one? And why? Use this to create a correct version of the procedure below. (define time-to-impact(lambda (vertical-velocity elevation)YOUR-CODE-HERE)) In some cases, we may want to know how long it takes for the ball to drop to a particular height, other than 0. Using your previous procedure as a template, write a procedure that computes the time for the ball to reach a given target elevation. (define time-to-height(lambda (vertical-velocity elevation target-elevation)YOUR-CODE-HERE)) Problem 4: Flight Distance Suppose the baseball is hit with some velocity v, at a starting angle alpha relative to the horizontal (in degrees), and from an initial elevation (in meters). We wish to compute the distance in the horizontal direction the baseball will travel by the time it lands. Remember that some of the velocity vector goes into the x direction, and some into the y, as pictured in Figure 2 below.y elevation 0 α vx g vy v x 0 distance Figure 2: Motion of a baseball in two dimensions, acting under gravitational acceleration g. Checking the Scheme manual, you will find procedures sin and cos. To use these (which require angles in radians


View Full Document

MIT 6 001 - Study Notes

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?