CS 107 - Introduction to Scientific Computation
Homework #2


Due: Wednesday 2/2 at the beginning of class

NOTE: For each assignment, you should submit not only the requested program files, but also a simple text file called READMEREADME files are often used by programmers to comment on the contents of a directory or give vital information.  Please make sure this plain text file is named "README", not "README.txt", "readme", "ReadMe.txt", "Read me.doc", etc.  For each assignment, your README file will contain:

For this homework, answers to all questions will be placed in a file called hw2.m.  Precede each answer with a commented line (beginning with a "%") that indicates the question.

1. Wheat on a Chessboard: In The Math Book: From Pythagoras to the 57th Dimension, 250 Milestones in the History of Mathematics, Clifford Pickover writes:

The problem of Sissa's chessboard is notable in the history of mathematics because it has been used for centuries to demonstrate the nature of geometric growth or geometric progressions, and it is one of the earliest mentions of chess in puzzles.  The Arabic scholar Ibn Khallikan in 1256 appears to be the first author to discuss the story of Grand Vizier Sissa ben Dahir, who, according to legend, was asked by the Indian King Shirham what reward he wanted for inventing the game of chess.

Sissa addressed the king: "Majesty, I would be happy if you were to give me a grain of wheat to place on the first square of the chessboard, and two grains of wheat to place on the second square, and four grains of wheat to place on the third, and eight grains of wheat to place on the fourth, and so on for the sixty-four squares."

"And is that all you wish, Sissa, you fool?" the astonished King shouted.

In a single expression, compute the number of grains of wheat that Sissa requested.  (Related unassigned problems: text exercises 3.1, 3.2)

2. Drawing a Square: Exercise 3.6.  Hint: "help plot".

3. Boolean Expression: Exercise 3.8.  To present your work, evaluate your Boolean expression for each possible case.  To this end, you may make a and b vectors of appropriate respective values to cover all cases (e.g. sum greater and b nonnegative, sum greater and b negative, etc.).

4. Counting Leap Years: Exercise 3.12.  Hint: start with a vector of years.  Then evaluate Boolean vectors associated with the various conditions of the problem.  Hint 2: "help mod".  Finally, combine these vectors and perform an appropriate operation to compute the total number of leap years.  See the Wikipedia article for clarification: "Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years."