[SOLVED] R python ORIE5270 Homework 4

$25

File Name: R_python_ORIE5270__Homework_4.zip
File Size: 273.18 KB

5/5 - (1 vote)

ORIE5270 Homework 4
Due February 22nd, 2019 at 1:25pm
You are not allowed to collaborate with your classmates. Submit this assignment by pushing a folder HW4 to your ORIE5270 repository on cornells github with your solutions as well as a solution file in pdf format containing your repo url to Blackboard. Make sure all your code are readable. You should also tell us how to run your code in your solution file.
Problem 1
Problem 2
Problem 3
(Test of NameHeap) Modify your NameHeap class last homework so that if the NameHeap is empty, the function smallestName() and deleteSmallestName() will print out a message
There is no one in the Heap.
Now write a python file NameHeapTests.py to test each function in your NameHeap using the python module unittest or nose. Explain how you test each function (you can include your code with enough comments so you dont need to repeat your work) and how other people can run your test in your solution file. You repo should contain NameHeapTests.py.
(Subnormal numbers) Assuming you are only dealing with IEEE754 floating point num- ber with double precision (binary64) in this problem.
(1) What is a subnormal number? Give an example of a subnormal number (dont use the one, 2102250, in the class).
(2) Write a routine detectSubnormalNumber.py that outputs true if a given float is a subnormal number and false otherwise. Write a test file TestDetectSubnormalNumber.py to test detectSubnormalNumber.py with examples of your own. The solution file should contain explanations of why your routine works, and your tests cases.
(Quadratic Formula) Consider solving the quadratic equation
x(x 2b) = c (1)
for some constants b, c R and c 0, which ensures the solutions are real.
(1) Using the quadratic formula, for a given input of b, write a python file qesolution.py
that outputs a pair of solutions x that satisfies the above equation. Then write a test file TestQesolution.py to test your solution are accurate for various but not extreme b, c. To test the accuracy of the two roots, calculate the theoretical value of : x1 + x2 and x1x2 where x1, x2 are solution to (1) and test against those values in terms of relative error. Make sure your accuracy is at least 1012.
(2) Add unit tests to your TestQesolution.py for scenarios when b is large in magni- tude and when c is small (so that they fail your function qesolution.py). What happens to the relative error and why? Write your solution to the two questions and your choice of b and c in the solution file. (Note: dont worry about when b2/c > 252)
(3) There is more than one way to write the quadratic formula. Multiply the numerator and denominator by the conjugate to move the square root term to the denominator.
Write a new python file qesolutionRevise.py for solving the quadratic equa- tion that selectively chooses the more numerically stable formula depending on the right situation. Explain why your code works in your solution file. Your qesolutionRevise.py should also pass your previous tests in TestQesolution.py.
(Matrix-vector Product) Suppose you want to know the complexity of the following matrix-vector product using numpy:
import numpy a s np
Problem 4
1

2
def matrixVectproduct (A, b ) : return Ab
Of course, you know for a matrix A Rnn and b Rn, computing the matrix-vector product Ab should take no more than n2 number of arithmetic operations. However, since numpy matrix-vector product A*b is a black box to you, you are not perfectly sure about your answer O(n2). Can you use a plot to see the complexity of matrix-vector product? Write a python script MatrixVectorProductComplexity.py for the plot. Put your plot in your solution file, explain how you make the plot, and the complexity of the matrix-vector product reflected in the plot.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] R python ORIE5270 Homework 4
$25