Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

Students also viewed these Databases questions