Question: given this function in python Write a program that uses the LU decomposition function that I gave you above and solves the problem Ax= b

 given this function in python Write a program that uses the

given this function in python

Write a program that uses the LU decomposition function that I gave you above and solves the problem Ax= b , given the matrix A and the solution vector b. You can check your program with the solutions given by using numpy.linalg.solve

def LU_decomposition (A): "" "Perform LU decomposition of a square matrix (numpy array) using the Doolittle factorization.""" #import numpy import numpy as np make sure type is correct (or you could set this up to try and convert the type instead of raising an error.) if type (A) != np.ndarray: raise TypeError( 'Input must be a numpy array, type f will not work' .format (type (A))) #check dimension to ensure A is square #print ( np. shape ( A) [ 0 ] ) if np. shape (A) [0] != np. shape (A) [1]: raise ValueErrorInput matrix is not square, shape will not work' .format (np.shape (A))) L - np.zeros_like (A) Unp.zeros_like(A) N- np.size(A, 0) for k in range (N): L(k, k] = 1 for j in range (k+1, N): for i in range(ktl, N): U[k, j-Alk, j] - np.dot (L[k, :k], Ul:k, j]) return L, U def LU_decomposition (A): "" "Perform LU decomposition of a square matrix (numpy array) using the Doolittle factorization.""" #import numpy import numpy as np make sure type is correct (or you could set this up to try and convert the type instead of raising an error.) if type (A) != np.ndarray: raise TypeError( 'Input must be a numpy array, type f will not work' .format (type (A))) #check dimension to ensure A is square #print ( np. shape ( A) [ 0 ] ) if np. shape (A) [0] != np. shape (A) [1]: raise ValueErrorInput matrix is not square, shape will not work' .format (np.shape (A))) L - np.zeros_like (A) Unp.zeros_like(A) N- np.size(A, 0) for k in range (N): L(k, k] = 1 for j in range (k+1, N): for i in range(ktl, N): U[k, j-Alk, j] - np.dot (L[k, :k], Ul:k, j]) return L, U

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!