submit p6720 midterm midterm.txtPlease be sure you submit your final version. Replacing the file is permitted until the end of the test.
1 (b)
A file called positions contains a list of position vectors,
one per line. Each line has two numbers, namely, the x and y
components of a vector. Write the one-line Unix command that creates a
new file called lengths that contains the lengths of the
vectors (the square root of the sum of the squares of the components),
one length per line.
1 (c)
You have loaded numpy as np and its linalg
package as LA. Write the one-line command that normalizes the
vector x to unit length and stores the result in the
vector y.
1 (d)
Use Maple or Matlab to find the lowest positive solution to x =
cot(x) to four significant figures. Copy the Maple or Matlab
command(s) to your answer file including your answer. (You may do the
rounding by hand.)
1 (e)
You want to read the string of characters vibranium from
standard input and store it in a variable metal. Your
input statement reads
metal = eval(input("Enter the name of the metal "))What should you type on the keyboard when prompted by your command?
101 cygnus:~> python3 Python 3.5.0a2 (default, Mar 19 2015, 15:31:59) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> tan(40) Traceback (most recent call last): File "There are multiple errors here. Write the Python commands that give the correct result.", line 1, in NameError: name 'tan' is not defined >>>
for i in range(n+1):with n = 6, what are the first and last values of i?
def f(x,y): return x**2, x*yand it is called with
a, b = f(7,5)What are the resulting values of a and b?
#! /usr/bin/python3 import numpy as np from numpy import linalg as LA ############################################################## # In your answer file write the full code for the function # that computes |A x - b|, the norm of the difference between the # left side and right side of the equation. # Your function should return the value of the norm. # The function should go in the space below and work with the # calling program. # Please do not change the calling program or the import statements. ############################################################## # (Your code is intended to go in this space) ############################################################## def main(): # Read the matrix and vector from files A = np.loadtxt('A.txt') b = np.loadtxt('b.txt') # Solve the linear system x = LA.solve(A,b) # Call the function to compute |Ax - b| d = check(A,x,b) print("The solution to Ax = b is", x) print("The norm |Ax-b| is", d) ############################################################## main()
4 (a) In calculus we learn that a derivative of a continuous, differentiable function f(x) at x is found by taking the limit as h->0 of
[f(x+h) - f(x)]/h.The mathematical idea of the limit is that the ratio gets steadily closer to the derivative as h is made smaller. Suppose we try taking the limit numerically, using this formula in a computer program. Will the numerical quantity get closer and closer to the derivative? Explain in a clear, complete sentence.