DOC PREVIEW
MIT 6 01 - Assignment 3

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 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 23 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 23 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 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.01, Fall Semester, 2007—Assignment 3, Issued: Tuesday, Sept. 18 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.01—Introduction to EECS IFall Semester, 2007Assignment 3, Issued: Tuesday, Sept. 18To do this week...in Tuesday software lab1. Start writing code and test cases for the numbered questions in the software lab. Paste allyour code, including your test cases, into the box provided in the “Software Lab” (Part 3.1)problem on the on-line Tutor. This will not be graded....before the start of lab on Thursday1. Read the lecture notes.2. Do the on-line Tutor problems for week 3 that are due on Thursday (Part 3.2).3. Read through the entire description of Thursday’s lab....in Thursday robot lab1. Answer the numbered questions in the robot lab and demonstrate them to your LA.2. Do the nanoquiz; it will be based on the material in the lecture notes and the on-line Tutorproblems due on Thursday....before the start of lecture next Tuesday1. Do the on-line Tutor problems for week 3 that are due on Tuesday (Part 3.3).2. Do the lab writeup, providing written answers (including code and test cases) for everynumbered question in this handout.On Athena machines make sure you do:athrun 6.01 updateso that you can get the Desktop/6.01/lab3 directory which has the files mentioned in thishandout.• You need the file fsm.py for the software lab.• You need the files sequence.py and UtilityBrainTB.py for the robot lab.During software lab, if you are using your own laptop, download the files from the courseWeb site (on the Calendar page).6.01, Fall Semester, 2007—Assignment 3, Issued: Tuesday, Sept. 18 2Object-Oriented Programming; Combining Sequential BehaviorsTuesday’s lecture, the Tuesday software lab, and the on-line problems cover Python’s support forobject-oriented programming. Thursday’s lab applies the tools of object-oriented programming todevelop a new system for defining and combining robot behaviors sequentially, rather than theutility-based combination we looked at last week.Tuesday Software Lab: PracticeAt the end of this lab, go to the on-line Tutor at http://sicp.csail.mit.edu/6.01/fall07, choose PS3, and paste all your code, including your test cases, into the box providedin the “Software Lab” problem. This will not be graded, it is simply a checkpoint for us tosee how people are doing. Complete the assignment later and hand it in as part of your labwriteup. Make sure that you include the test cases and results that you used toconclude that your code was working.This week, we’ll get practice with object-oriented programming, and build some tools that will beuseful in future labs.Polynomial ArithmeticWe can represent a polynomial as a list of coefficients starting with the highest-order term. Forexample, the polynomial x4− 7x3+ 10x2− 4x + 6 would be represented as the list [1,-7,10,-4,6].Let’s say that the length of a polynomial is the length of its list of coefficients.Write a class called Polynomial that supports evaluation and addition on polynomials. You canstructure it any way you’d like, but it should be correct and be beautiful. It should support, atleast, an interaction like this:>>> p1 = Polynomial([3, 2, 1])>>> print p1poly[3.0, 2.0, 1.0]This represents the polynomial 3x2+ 2x + 1.>>> p2 = Polynomial([100, 200])>>> print p1.add(p2)poly[3.0, 102.0, 201.0]>>> print p1 + p2poly[3.0, 102.0, 201.0]>>> p1.val(1)6.0>>> p1.val(10)321.06.01, Fall Semester, 2007—Assignment 3, Issued: Tuesday, Sept. 18 3The constructor accepts a list of coefficients, highest-order first.Question 1. Define the basic parts of your class, with an init method and a str method(see the lecture notes for more information about this), so that if you do>>> print Polynomial([3, 2, 1])poly[3.0, 2.0, 1.0]something nice and informative is printed out.Question 2. Implement the add method for your class.A cool thing about Python is that you can overload the arithmetic operators. So, for example, ifyou add the following method to your Polynomial classdef __add__(self, v):return self.add(v)or, if you prefer,def __add__(self, v):return Polynomial.add(self, v)then you can do>>> print Polynomial([3, 2, 1]) + Polynomial([100, 200])poly[3.0, 102.0, 201.0]Exactly what gets printed as a result of this statement depends on how you’ve defined your strprocedure; this is just an example.Question 3. Add the add method to your class.A straightforward way to evaluate polynomials is to explicitly add up the terms aixi. We can dothis with list comprehension and sum. Hint: note that in a polynomial with k coefficients, thehighest power of the variable is k − 1, for example, our example polynomial of length 3 has thehighest power of x2.Question 4. Add the val method to your class, which evaluates the polynomial for the specifiedvalue.Try to do things as simply as possible. Don’t do anything twice.Finite State MachinesThis section builds on the FSM discussion in lecture. All the code from lecture can be found inthe fsm.py file. There is additional written material covering the lecture presentation at the endof this handout.6.01, Fall Semester, 2007—Assignment 3, Issued: Tuesday, Sept. 18 4Figure 1: Serial, parallel, and feedback compositions of state machines.Question 5. Assuming the elevator starts in the closed state, what is the sequence of states andoutputs for the following sequence of inputs: commandOpen, commandClose, noCommand,commandOpen?If you have a very complicated system to model or implement, writing a single monolithic statetransition function would be very difficult. Happily, we can apply our PCA (primitive, combination,abstraction) methodology here, to build more complex FSMs out of simpler ones.We wil treat the PrimitiveFSM class as a primitive and consider some possible means of combina-tion. Figure 1 sketches three types of FSM composition: serial, parallel, and feedback. In this lab,we’ll focus on serial and feedback composition.Serial compositionIn serial composition, we take two machines and use the output of the first one as the input to thesecond. The result is a new composite machine, whose input vocabulary is the input vocabularyof the first machine and whose output vocabulary is the output vocabulary of the second machine.It is, of course, crucial that the output vocabulary of the first machine be the same as the inputvocabulary of the second machine.6.01, Fall Semester, 2007—Assignment 3, Issued: Tuesday,


View Full Document

MIT 6 01 - Assignment 3

Documents in this Course
Week 1

Week 1

3 pages

Op-Amps

Op-Amps

8 pages

Op-Amps

Op-Amps

6 pages

Syllabus

Syllabus

14 pages

Planning

Planning

14 pages

Load more
Download Assignment 3
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 Assignment 3 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 Assignment 3 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?