Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python3 I need to write a code that takes a matrix as it\'s argument and comp

ID: 3910359 • Letter: I

Question

In python3 I need to write a code that takes a matrix as it's argument and computes and prints the QR factorization using the Modified Gram-Schmidt algorithm. The only built in functions in python3 I want to use are the absolute value, append, and print functions. Please show step by step will rate! Thank you in advance. In python3 I need to write a code that takes a matrix as it's argument and computes and prints the QR factorization using the Modified Gram-Schmidt algorithm. The only built in functions in python3 I want to use are the absolute value, append, and print functions. Please show step by step will rate! Thank you in advance.

Explanation / Answer

Answer: For the least square and Eigen-value problems QR Factorizations are useful. The factorizations such that A=QR and QTQ=I, and R is a upper triangular and nonsingular i.e. your column and row vectors need to be linearly independent, are known as QR Factorization. The classical Gram Schmidt method is computed by rows on the transposed systems and modified Gram Schmidt method is computed by columns on the transposed systems. The modified Schmidt is better because of less round off errors.

Python Code:

import numpy as np

def A(u, v):

    return u * np.dot(v,u) / np.dot(u,u)

def B(V):

    V = 1.0 * V     #FOR ABSOLUTE VALUE

    U = np.copy(V)

    for i in range(1, V.shape[1]):

        for j in range(i):

            U[:,i] -= A(U[:,j], V[:,i])

    # normalize column

    den=(U**2).sum(axis=0) **0.5

    E = U/den

    return E

def C():

    V = np.array([[1.0, 1, 1], [1, 0, 2], [1, 0, 0]]).T

    V2=np.copy(V)

    V2[:,2]=[0,1,0]

    E, E2 = B(V), B(V2)

    print (E, ' ', E2)

    # QR factorization

    print (np.linalg.qr(V))

    print (np.dot(E.T, V))

   

if __name__ == '__main__':

    C()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote