Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Complete the function import numpy as np from numpy.testing import assert_allclose np.set_printoptions(precision = 4) def p3(): ''' 3) This problem involves functions to support QR

"Complete the function"

import numpy as np

from numpy.testing import assert_allclose

np.set_printoptions(precision = 4)

def p3():

'''

3) This problem involves functions to support QR factorization.

'''

'''

3a) Implement a function to compute the component of vector v along the direction of vector u.

'''

'''

3b) In class, we discussed QR factorization based on Gram Scmidt orthogonalization. In that approach, an orthogonal basis is constructed by subtracting from each new candidate basis vector the components along the direction of each already-computed entry in the (numerically) orthogonal set. That approach can run into precision issues (because candidate basis vectors that lie close to the space spanned by the existing basis vectors can lead to catastrophic cancellation when components are subtracted). That issue led to the creation of other approaches. The one that is the focus of this problem involves Householder reflections. The basic idea is to compute the vector that arises when an input vector v is reflected about the plane normal to a specified vector u.

Fill in code below to implement a function to compute the Householder reflection. This should be pretty straightforward if you usethe function component_of_along that you implemented in 3a.

'''

'''

3c) Householder made good use of this basic reflection operation. First, he noted that the reflection operation corresponds to multiplication of the input vector v by an orthogonal matrix Q_u. Think about why that is true! Then, he figured out how to pick the mirror normal that would produce a reflected vector e0 that lies along the first coordinate axis; i.e. Q_u(v) = norm(v)*e0. Convince yourself that the choice u = c*(v - norm(v)*e0) works for any choice of the constant c. In particular, choose c=1 so u = v - norm(v)*e0

NOTE: The slightly more complicated choice u = v - sign(v[0])*norm(v)*e0 prevents the possibility of catastrophic cancellation errors.

Insert code below to produce the orthogonal matrix that reflects a given input vector to become a multiple of e0.

'''

'''

3d) Use the function you implemented for part 3c to implement a function that does the first step of QR factorization.

'''

pass

def p4():

'''

4) Use the functions you wrote for problem 3 to implement QR factorization

based on Householder reflections.

'''

pass

if __name__ == '__main__':

p1()

p2()

p3()

p4()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started