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

All m-files must be com pressed into a single ZIP file named ubitname-PP2. zip.

ID: 3763855 • Letter: A

Question

All m-files must be com pressed into a single ZIP file named ubitname-PP2. zip. where ubitname is your ubitname. Your ZIP file must be uploaded to UBIearns before the due date & time. You must write your own code and follow all instructions to get full credit. You are not allowed to use built-in MATI.AB functions or operators and inv (or similar), nor are you allowed to directly use scripts & functions found on the Internet. For all functions, if a call to the function does not contain the proper number of input or output arguments. then you must notify the user by throwing a suitable error message using MATLAB function error or assert. Reference sections 2.6. 2.7 and 9.1 in Introduction to Linear Algebra. 4th Ed. by Gilbert Strang and 3.3.4, 5.3 in Essentials of MATLAB Programming, 2nd Ed. by Stephen Chapman. Write a MATLAB function of the form [L, U, P] = get_lu (A) that accepts a square matrix A and returns the LU decomposition of A with the permutation matrix P. Your function must perform row exchanges, if necessary, and the pivots must be well-scaled (to reduce roundoff error) using the technique of partial pivoting. If A is singular or not square (i.e. rectangular), then you must notify the user by throwing a suitable error message using MATLAB function error or assert. Write a MATLAB function named x = get_sol (A, b) that accepts a square matrix A and vector b. and calls your get_lu function to obtain the LU decomposition of A. which is then used to solve the system Ax = b and return the solution vector in x. Modify the functions you created in Part 1 and Part 2 to optionally utilize the LDU composition. You must only modify your existing ions-do not create new or separate functions! Modify get_lu to be of the form ,U,P,D] = get_lu (A). where output argument D is optional. If D is omitted in the call to get_lu. then the LU decomposition is performed as in Part 1. and nothing is returned in D. However, if D is included in the function call, then the LDU decomposition is performed, and the D matrix is returned, along with L. P and the corresponding U. Modify get_sol to employ cither the LU or LDU decomposition to land the solution to Ax = b, depending on which is resumed by your modified get_lu function. In other words, if output argument D (from your call to get_lu) contains a value (is not empty), then get_sol must use the LDU decomposition: otherwise. get_sol behaves as it did in Part 2. using the LU decomposition.

Explanation / Answer

1) def lu(A): import numpy as np # Return an error if matrix is not square if not A.shape[0]==A.shape[1]: raise ValueError("Input matrix must be square") n = A.shape[0] L = np.zeros((n,n),dtype='float64') U = np.zeros((n,n),dtype='float64') U[:] = A np.fill_diagonal(L,1) # fill the diagonal of L with 1 for i in range(n-1): for j in range(i+1,n): L[j,i] = U[j,i]/U[i,i] U[j,i:] = U[j,i:]-L[j,i]*U[i,i:] U[j,i] = 0 return (L,U)

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