List below is HW5.py Please answer this question with the code you used and outp
ID: 3602721 • Letter: L
Question
List below is HW5.py
Please answer this question with the code you used and output please.
Thank you.
Part II. Programming Instructions. For the programming portion of this assignment, you will be running and modifying the code in the provided file hw5.py. Hand in a printed copy of the modified file, as well as a printout of the IPython terminal session(s) containing the commands and output you used to get your answers. Problem 3 a. Write a function hilbert (n) which returns the nx n Hilbert matrix, 1/2 1/3 1/n 1/(n 1/(2n - 1) 1/ (itj+1).) (Hint: You may find it helpful to notice that H [i,j] Print the output of hilbert (5) = DUE OCTOBER 27, 2017 b. Let A be the 20 × 20 Hilbert matrix, x = (1, , 20), and b = Ax Find óx by comparing r with the numerical solution solve (A, b) (which uses NumPy's built-in solver), and then find by comparing A(z 6r) with b. Using either one of the functions norm or 12norm for ll.lla, compute and print the values of]|2/ 2 and lis2/ 2Explanation / Answer
from __future__ import division from pylab import * def newtonFractal(f, Jf, n=32, p=512): """Display a Newton fractal for the function f with Jacobian Jf. n is the number of Newton steps (default: 32), and p is the width and height of the image in pixels (default: 512).""" # Create a p-by-p grid of points in the square [-1,1] x [-1,1]. x = array(meshgrid(linspace(-1,1,p), linspace(-1,1,p))) # Do n Newton steps starting from each point in the grid. for k in range(n): # The following line is just a clever way of doing a Newton # step on the entire array of grid points simultaneously. # Since NumPy array operations are highly optimized, this is # much faster than doing a "for loop" over the grid points. x = x - solve(transpose(Jf(x),(3,2,0,1)), f(x).T).T # Show a p-by-p pixel image, where each starting point is colored # according to the angle of the point in the plane where it ended # up. This angle is given by arctan2(*x) = arctan(x1/x0). imshow(arctan2(*x), extent=[-1,1,-1,1]) def f(x): return array([x[0]**3 - 3*x[0]*x[1]**2 - 1, 3*x[0]**2*x[1] - x[1]**3])
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.