Unformatted text preview:

6.01, Fall Semester, 2007—Assignment 4, Issued: Tuesday, Sept. 25 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.01—Introduction to EECS IFall Semester, 2007Assignment 4, Issued: Tuesday, Sept. 25To 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 b ox provided in the “Software Lab” (Part 4.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 4 that are due on Thursday (Part 4.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 lab writeup, providing written answers (including code and test cases) for everynumb e red question in this handout.6.01, Fall Semester, 2007—Assignment 4, Issued: Tuesday, Sept. 25 2On Athena or the lab laptops make sure you execute:athrun 6.01 updateso that you can get the Desktop/6.01/lab4 directory which has the files mentioned in thishandout.• You need the file polynomial.pyc for the software lab.• You need the file diffeq.py for the software lab.• You need the file soar-graph.py for the software lab.During software lab, if you are using your own laptop, download the files from the courseWeb site (on the Calendar page). Make sure you are using Python version 2.5, as we aregiving you a “compiled” version of the p olynomial class .Tuesday Software Lab 1: Solving second-order difference equationsFor this lab, you will be writing a Python program that solves arbitrary second-order homogeneouslinear difference equations analytically, by computing natural frequencies. Your program shouldtake as inputs the initial values x(0) and x(1) as well as coefficients a1and a2for the differenceequation in the formy(n) = a1y(n − 1) + a2y(n − 2).Your program should print out the solution to the difference e quation and also return a procedurethat, when called with n, returns y(n). For example, if the difference equation isy(n) = 2y(n − 1) − 2y(n − 2),and the initial conditions are y(0) = 0, y(1) = 1, your program should print something equivalenttoy(n) = (2.775 5575e -017+0.5 j )*(1 -1 j )** n + ( -2.7755575 e -017 -0.5 j )*(1+1 j )** nmagnitude of natural f req uen cie s : 1.414213 56237 30951 , 1.4 1 4213 5 6237 3095 1and your program should also return a function which can be used to evaluate y(n) for any n.NOTE: you can assume that the natural frequencies are distinct (but your program should indicatean error when the two natural frequencies are identical). The special case of what to do withrepeated natural frequencies is studied in more advanced courses.Polynomi al manipulationTo save time , you s hould use our impleme ntation of the polynomial manipulation program from therecent post-lab exercises and edit diffeq.py to create your second-order difference equation solver.Please be sure diffeq.py and polynomial.pyc are in the same directory as your difference equationsolver. Executing diffeq.py in IDLE will import our version of the polynomial manipulation routinesimplemented in the class Polynomial. You can see the class interface by typinghelp(Polynomial)at the IDLE command line. Note that the Polynomial class has functions to add, multiply, printand find the roots of polynomials. The following code fragment6.01, Fall Semester, 2007—Assignment 4, Issued: Tuesday, Sept. 25 3p = Pol yno mial ([1 , -6, 9])>>> p . roots ()[(3+0 j ) , (3 -0 j )]generates an instance of the polynomialx2− 6x + 9 = 0 ,and then computes the polynomial’s roots. Our implementation only c omputes roots correctly forpolynomials up to third order (cubics).Checkpoint: 11:45• You should understand the polynomial class.A note on complex numbersFor this problem, your procedure will sometimes need to compute znwhere z is a complex numb er.Python understands complex numbers to some extent, but you have to write them in the forma + bjwhere a is the real part and b is the imaginary part. Note that Python uses the convention thatj =√−1. As an EECS student, you will have to learn to accept the fact that the variable i mustbe reserved for electrical current.You can’t raise a negative real number to a fractional power, but you can do so with a complexnumb e r. So, for example, the Python command>>> ( -4)**0.5will produce an error, but the Python command>>> ( -4+0 j )**0.5produces (1.2246063538223773e-016+2j). (Why the very small real part?)Note: use y**0.5 to compute the square root of a number. The python sqrt function does notunderstand complex numbers. You can get the real and imaginary parts of a complex number xwith x.real and x.imag; also, abs(x) will return its magnitude.It will be important to ensure that the function returned by your difference equation solver onlyreturns real (not complex) values. Be sure you understand why, mathematically, the output shouldalways be real if the coefficients and initial values are real.6.01, Fall Semester, 2007—Assignment 4, Issued: Tuesday, Sept. 25 4Demonstrate that your prog ram worksQuestion 1. Describe how your program works.Question 2. Test your program by solving the difference equationy(n) = 2y(n − 1) − 2y(n − 2),with the initial conditions y(0) = 0, y(1) = 1.Question 3. Demonstrate that your program returns the correct function. How did you verifyyour program was correct?Checkpoint: 12:30 PM• You should have a working difference equation solving program.You can also test your program by plotting the values the program generates. Here are the steps:1. Start SoaR (just type SoaR in the terminal; it’s best to quit Idle before you do this)2. Click on the editor window to get an Idle window from inside SoaR3. Open the file soar-graph.py which has the following commands:from diffeq import *g1 = Gr aph ingW indo w (400 , 400 , 0, 20 , -100 , 100 , " diffeq ")f = solveDiffEq ([0 , 1] , [2 , -2])g1 . grap hDi scre te (f , ’ blue ’)The first in the above sequence of commands generates a a graphing window that is 400 by400 pixels, with x coordinates ranging from 0 to 20 and y coordinates from −100 to +100,and gives the graph the


View Full Document

MIT 6 01 - ASSIGNMENT - 6.01

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 - 6.01
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 - 6.01 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 - 6.01 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?