CS227:Assignment 1 

MATLAB Basics, and some Plotting Exercises

Assigned: Tuesday, September 6
Due: Tuesday, September 13

Relevant reading: Lecture Notes 1. From Hunt, Chapter 2 (don't bother for now with the sections about symbolic computation and matrices) and the first six pages of Chapter 5. From Moler, Sections 1.1 and 1.7.  From Driscoll: Chapter 1, Sections 2.1-2.4, and Section 5.1.

You will need to turn in (among other things) a  file contaning the MATLAB commands that you type in order to solve the problems below, so once you complete a problem, you should select, copy and save a transcript of your session, or, better yet, create M-files.  (See "What to Hand In" below for more detail.)


1. Harmonic series and summation order

The harmonic series



is divergent---the sum does not approach a finite limit..

(a) Evaluate the sum of the first one million terms of this series.  To do this, you will need to use the various techniques available in MATLAB for manipulating vectors:


(b) Now evaluate the sum again, but this time evaluate it as



(You can begin by creating a vector whose components are (1000000,999999,...,1).)

(c)The answers are close, but not exactly equal.  Again, you will need to use format long to see this. Which one do you think is more accurate?  We will return to this question next week, when we discuss the floating-point representation of numbers in the computer.


2. Plot the lemniscate of Gerono, pictured above.  Parametric equations for the curve are given by



If you try to plot this in the most straightforward way, you are likely to encounter a difficulty connected with the limits on the parameter t, and not be able to produce a smooth plot like the one above.  How can you fix this?

3. Plot a "conical helix"


 (I don't know if that's the right term, but it should be clear from the picture what I mean!) The idea is similar to what we did in the Lecture Notes to produce the cylindrical helix.  You need the following fact about so-called cylindrical coordinates: A point at height z, a distance r from the z-axis, and whose projection onto the (x,y)-plane makes an angle of u with the positive x-axis, has ordinary (Cartesian) coordinates (r cos(u), r sin(u), z).  In the helix, we had r=1, but here r varies linearly from the apex of the cone to the base.


4. Plot a conical surface.




 You need a parametrization in terms of two parameters, which you should choose as the distance r from the z-axis and the polar angle u, as above.












What to Hand In:

With this assignment and with all subsequent assignments, you will submit two different things:
  • A paper document, handed in at the start of class on the due date.
  • A zipped folder, submitted through the Blackboard Vista site for this course, before the start of class on the due date.
The paper document should be a word-processed document containing (a) Carefully reasoned responses to questions 1. (b) A brief discussion of the difficulties involved in question 2. (c) printouts of the M-files you used to solve the plotting problems (these can either be appended at the end of the document or incorporated as running text); (d) the images you created for problems 3-5 (these should have been saved as .jpg files and pasted into the document).  If you have trouble typing the math, you can include handwritten calculations in the paper document.  The ideal solution is to learn how to use a mathematical  typesetting program like LaTeX, but I won't insist on this.

The folder should contain (a) an electronic copy of the word-processed document you submit in class; (b) the M-files containing the sequences of statements that generate the plots in problems 3-5 --I will execute each of these files to see the result. (c) .jpg files containing the plots (to create these, select Save As.. from the File menu of the window containing the plot, and then select 'JPEG image' for the file format.   Place all electronic documents in a folder, compress the folder, submit the resulting .zip file to the Blackboard Vista site for this course.  Your name and the assignment number should be part of the name of the folder and in the subject line of the e-mail message.