submit p6720 midterm midterm.txtPlease be sure you submit your final version. Replacing the file is permitted until the end of the test.
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. >>> import numpy as np >>> S = np.loadtxt(myfile.txt) Traceback (most recent call last): File "Write the corrected Python command that fixes the problem.", line 1, in NameError: name 'myfile' is not defined >>>
f(x) = 1 - 3*x + x^{2}Your current best guess for a root is x = 1. What numeric value does the Newton-Raphson algorithm give you for your next best guess? Show how you arrived at your result.
#! /usr/bin/python3 import sys import numpy as np from numpy import linalg as LA ############################################################## # In your answer file write the full code for the function # that computes |v|, |w|, and their dot product. # Your function should return all three values. # The function should go in the space below and work with the # calling program. # Please do not change the calling program. ############################################################## # (Your code is meant to go in this space, but copy it to your answer file once you have completed it.) ############################################################## def main(): # Read two vectors v = np.loadtxt('v.txt') w = np.loadtxt('w.txt') # Calculate the Euclidean norm of both vectors and their dot product normv, normw, dotvw = normDot(v,w) print("normv, normw, dotvw = ", normv, normw, dotvw) ############################################################## main()
One of the goals of this course is to provide a diverse tool set so
when you need to solve a problem, you can choose the best tool to do
the job. In this problem, consider the following tools: (1) pencil
and paper (2) awk, (3) interactive Python3 (4) Python3 program (5)
Maple. Select the the one that is most efficient or most appropriate
for each of the following problems and explain in a clear, complete
sentence. If two methods are more or less equally
efficient/appropriate, give both and explain.
(a) Solve the quadratic equation x^{2} - 9 = 0.
(b) Calculate the secant of 1.4 radians.
(c) Find the characteristic polynomial of a 5x5 matrix A.
(d) List the squares of the first value on each line of a text file.
(e) Calculate the determinants of a few dozen 20x20 matrices. The
elements of the matrices are provided in a file.