This problem may use a notation that is hard to follow. Basically what this approximation method does is use a previous "guess" to compute a "new guess" for the square root of a number called n. The previous is the kth and the next is the k+1st. We assume that the first guess (called the zeroith) is 1.
So, to compute the "next guess", we take 1/2 times the sum of the "previous guess" and n divided by the "previous guess". That new guess becomes the old guess on the next try. The number of tries is referred to as the number of terms.
Wednesday, August 26, 2009
Chapter 2 -- Page 59 -- last line
Again, these initializations can simply be 1 and 2 since the division performed will automatically return floating point.
The correction should be made to lines 2 and 3 of Listing 2.4 as well.
The correction should be made to lines 2 and 3 of Listing 2.4 as well.
Chapter 2 -- Page 54 -- Problem 2.6
In this problem we are testing the archimedes function to see how many sides are required to get the same result as that provided by the math library (math.pi).
Instead of "How many repetitions..." the question should ask "How many sides..."
Also, the values may never be equal. When are they "close enough" to call them equal?
Instead of "How many repetitions..." the question should ask "How many sides..."
Also, the values may never be equal. When are they "close enough" to call them equal?
Chapter 2 -- Page 47 -- Second line and Session 2.1
This line of text refers to floating point division and states that it is necessary for one of the operands to be a floating point number. This is NOT necessary. Division ("single slash") in Python 3 is always assumed to be floating point. So 22/7 will yield the correct result.
22.0, 355.0, and 9801.0 can simply be 22, 355, and 9801 in Session 2.1
22.0, 355.0, and 9801.0 can simply be 22, 355, and 9801 in Session 2.1
Chapter 1 -- Page 13 -- Problem 1.6
This problem needs better wording, something like
Compute the number of handshakes required for each person in your class to shake hands with every other person exactly one time.
Compute the number of handshakes required for each person in your class to shake hands with every other person exactly one time.
Monday, August 24, 2009
Chapter 12 -- Listing 12.8
There is a typo in Listing 12.8. In the init method the instance variable is visibleObjects. The b is missing in the text. In addition, the calls to up() and tracer should be added to the drawAll() method as they are in listing 12.4
Here is a complete, corrected version of Listing 12.8
Here is a complete, corrected version of Listing 12.8
class Canvas:
def __init__(self,w,h):
self.width = w
self.height = h
self.visibleObjects = []
self.turtle = cTurtle.Turtle()
self.turtle.setup(width=self.width,height=self.height)
self.turtle.hideturtle()
def drawAll(self):
self.turtle.reset()
self.turtle.tracer(0)
for shape in self.visibleObjects:
shape._draw(self.turtle)
self.turtle.tracer(1)
self.turtle.hideturtle()
def addShape(self,shape):
self.visibleObjects.append(shape)
def draw(self,gObject):
gObject.setCanvas(self)
gObject.setVisible(True)
self.turtle.up()
self.turtle.tracer(0)
gObject._draw(self.turtle)
self.turtle.tracer(1)
self.addShape(gObject)
Subscribe to:
Posts (Atom)