Assignment 3: Square Root
Assignment 3: Square Root
Assignment 3
Square Root
A classic algorithm that illustrates many of these concerns is Newton’s method to compute square roots
x = √ (a) for a>0, i.e. to solve x = a. The algorithm starts with some guess x 1 > 0 and computes the
2
it turns out that this algorithm is very old, dating at least to the ancient Babylonians circa 1000 BCE(See e.g.
Boyer,A History of Mathematics, ch. 3; the Babylonians used base 60 and a famous tablet (YBC
7289)shows√2 to about six decimal digits.)
In modern times, this was seen to be equivalent to Newton’s method to find a root of f (x) = x 2 − a Recall
that Newton’s method finds an approximate root of f(x)=0 from a guess x n by approximating f(x) as its
tangent line f (x n ) + f ′ (x n )(x − x n ) eading to an improved guess x n+1 from the root of the tangent:
f (x)
x n+1 = x n +
′
f (x)
Example
Find the Square root of any input positive integer and evaluate the square root using above Formula
In [6]:
Task 1
Use only While loop to solve the following Problems
http://localhost:8888/nbconvert/html/Downloads/Assignment3_13174.ipynb?download=false 1/3
9/11/2018 Assignment3_13174
Q1
When talking about floating point, we discussed machine epsilon, ϵ —this is the smallest number that when
added to 1 is still different from 1.
In [2]:
eps=1
while(1+eps!=1):
eps=eps/2
print(eps)
1.1102230246251565e-16
Q2
Create a loop to calculate and print the times table (Multiplication table) of given input number upto first 12
places Required output is given as follow
2 × 1 = 2
2 × 2 = 4
2 × 3 = 6
2 × 5 = 8
2 × 11 = 22
2 × 12 = 24
http://localhost:8888/nbconvert/html/Downloads/Assignment3_13174.ipynb?download=false 2/3
9/11/2018 Assignment3_13174
In [6]:
Enter a number = 12
12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120
12 x 11 = 132
12 x 12 = 144
http://localhost:8888/nbconvert/html/Downloads/Assignment3_13174.ipynb?download=false 3/3