Question

Task 1: Machine Epsilon (10 pts) Machine epsilon εm is a characteristic of the CPU in...

Task 1: Machine Epsilon (10 pts)

Machine epsilon εm is a characteristic of the CPU in one’s computer. This machine constant is used extensively when writing computer code to help make one’s algorithms CPU insensitive.

Machine epsilon εm is the smallest number ε such that 1 + ε > 1 in floating-point arithmetic. For any smaller value of ε, round-off error would return 1 + ε = 1. Machine epsilon is defined by the formula εm = b1-m where b is the base number

used by your computer in its construction of a floating-point number (b = 2 in computers that run Intel chips and their clones), and m is the total number of digits in the mantissa (adjustable and fixed). Note: 1-m is the power of base bbecause the first bit in a mantissa is fixed (cf. Homework 2). The fixed bit does not appear explicitly in the bit array representing a floating-point number.

1) Write a Python function that:

Computes machine epsilon (εm). Use a while loop to accomplish this. Start with εm equaling 1. In each successive loop compute εm = εm / 2. Exit the loop when variable 1 + εm equals 1. Multiply the result coming out of this loop by 2 and you have computed machine epsilon for your computer. This function should have the following structure:

def machEps():
    epsilon = 1.0
    ...
    return epsilon

Script files are executable files.

2) Write a Python script that:

Calls your function for computing machine epsilon, and then prints out (to the command window in Spyder) the answer in a readable format; specifically, the written output this script is to produce should look like:

machine epsilon = <the number>

The above output is what your grader will grade!
This script file must have the interface:
def runTask1():
in which you will call your function machEps and print out the answer in the

format specified above.

Homework Answers

Answer #1

def machEps():

epsilon = 1.0

while(epsilon>0):

value = epsilon

epsilon= epsilon/2

return value

Now what is happening here is, epsilon is the smallest value that computer can differentiate from 0. If a number is anything smaller then epsilon the computer treat it as 0.

So what we are doing is dividing the number /2 till we reach a point where that is 0 for the computer and when it happens the loop is over the value of epsilon right before the last division is what the computer can store ( smallest value) so we return the 'value' having that.

Now to write a script let's say, epsilon.py

interface script:
def runTask1():
     epsilon = machEps()
     print("machine epsilon = ",epsilon)

Hope it helps.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Matlab uses IEEE double precision numbers: 64-bit floating point representation 1 bit : sign 11 bits:...
Matlab uses IEEE double precision numbers: 64-bit floating point representation 1 bit : sign 11 bits: exponent 52 bits: mantissa. Calculate largest number that can be stored accurately Calculate smallest number (x>0) that can be stored accurately Calculate the machine epsilon Show all work step by step and explain calculations Now calculate the largest number and smallest number for a 10 bit floating point (1 bit for the sign, 4 bits exponent and 5 bits mantissa)
Matlab uses IEEE double precision numbers: 64-bit floating point representation 1 bit : sign 11 bits:...
Matlab uses IEEE double precision numbers: 64-bit floating point representation 1 bit : sign 11 bits: exponent 52 bits: mantissa. Calculate largest number (less than inf) that can be stored accurately Calculate smallest number (x>0) that can be stored accurately Calculate the machine epsilon Show all work step by step and repeat for 10 bit floating point (bit sign, 4 bits exponent and 5 bits mantissa)
1. (10 pts) Apply Booth's Algorithm to multiply the following 6-bit unsigned numbers, showing the contents...
1. (10 pts) Apply Booth's Algorithm to multiply the following 6-bit unsigned numbers, showing the contents of the A, Q, M registers and the C bit, through the 6 steps: 100110 and 111001 (i.e., decimal 38 and 57) 2 Assuming single-precision (i.e., 32-bits) IEEE 754 standard, unpack the following 32- bit string into decimal floating-point form: 11001110100001000110010000110100
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or...
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Write a python program that defines a function isPrime (number) with the following header: def isPrime (number): that checks whether a number is prime or not. Use that function in your main program to count the number of prime numbers that are less than 5000....
1. Design a function called sum that will take as arguments two floating-point numbers and will...
1. Design a function called sum that will take as arguments two floating-point numbers and will return the sum of those two numbers. 2. Design a function called get_longer that will take as arguments two phrases (strings) and will return the longer of the two strings. 3. Design a function called get_hypotenuse that will take as arguments the two lengths of the short sides (a and b in the formula below) of a right-angle triangle and returns the length of...
I. For problem 1-10 enter the letter of the word that best matches the definition 1)...
I. For problem 1-10 enter the letter of the word that best matches the definition 1) _____ In the statement computerPick = “rock”, the = (equal sign) means                               a) number 2) ____ randint in Python is an example of a Python package function and requires an            b) type                  ______ statement at the beginning of your program.                                                       3) ____ The passed arguments in calling a function must match the parameters                        c) parenthesis defined in the function...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
Design a function called print_area that takes two floating-point numbers, representing the length and width of...
Design a function called print_area that takes two floating-point numbers, representing the length and width of a rectangle. The print_area function calculates and prints the area of the rectangle, rounded to two decimal places. Design a function called small_enough_word that takes a string for which the number of characters will be tested, and an integer representing the maximum allowable number of characters that the word can contain. Remember: the arguments MUST be in this order (the string of text before...
PYTHON------------ Task 1- Remove Number Complete the function remove_number such that given a list of integers...
PYTHON------------ Task 1- Remove Number Complete the function remove_number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. Task 2- Logged List The log2() function is one of an algorithm designer’s favourite functions. You’ll learn more about this later, but briefly – if your input size is 1048576 elements, but you only look at...
Question 1 Consider the following 32-bit IEEE 754 floating point number. The binary number has been...
Question 1 Consider the following 32-bit IEEE 754 floating point number. The binary number has been separated into the sign, exp and frac fields Sign = 1           exp = 1000 0001           frac= 1111 0000 0000 0000 0000 000 Convert this number to decimal. Recall that the bias is 127 for IEEE single precision. Consider the following working C code. For(i = 0; I < 3: i++)             For(j = 0; j<=I; j++)                         Arr[i][j] = i + j; Sketch arr...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT