LU Decomposition 0 solutions submitted (max: Unlimited) This problem has four pa
ID: 3739349 • Letter: L
Question
LU Decomposition 0 solutions submitted (max: Unlimited) This problem has four parts. Develop one MATLAB function which outputs the solutions of all parts. (1) Solve the following system of equations using LU factorization with partial pivoting 2x 1-6x 2- x 3 40 -3x 1- x 2 6x 3 - 20 -8x1 + x2-2x3 = 50 Output the lower triangular matrix L, the upper triangular matrix U, the permutation matrix P, the intermediate solution vector d (see Chapra Sec. 10.2.1: Step 2.), and the final solution vectorx. Hint You may use he MATLAB function LuP = u A , which returns lower nangular matrix L upper nangular mat xuan mutation matrix s a p A 2) Evaluate the inverse invA of the matrix of the coefficients A using LU decomposition. Output also the intermediate matrix D-LIP. 3) Evaluate the determinant of A using the LU factors. Output also the determinant or the permutation matrix detP 4) Evaluate the condition number using the Frobenius norm of both the matrix A and its inverse invA you have evaluated above. - - Your Function 1 function [L,U,P,d,x,D,invA, detP,detA, condAHUFactorization() 21%% Output 3 % L: lower triangular coefficients (3x3 matrix) 4 % U: upper triangular coefficients (3x3 matrix) 51% d: intermediate solution (3x1 column vector) 61% x: final solution for unknowns (3x1 column vector) 8 % invA: inverse of matrix A (3x3 matrix) 91% detp: determinant of matrix 1e% detA: determinant of matrix A % condA: condition number of matrix A using Frobenius norm % krite your code here.Explanation / Answer
1) SAVE THE FOLLOWING CODES IN MATLAB AND GET THE RESULTS ACCORDINGLY-
SAVE THE FUNCTION FILE IN MATLAB-
Part (A)
function[L,U,X]=LU_Parker(A,B)
[m,n]=size(A);
if (m ~= n )
disp ( 'LR2 error: Matrix must be square' );
return;
end;
% Part 2 : Decomposition of matrix into L and U
L=zeros(m,m);
U=zeros(m,m);
for i=1:m
% Finding L
for k=1:i-1
L(i,k)=A(i,k);
for j=1:k-1
L(i,k)= L(i,k)-L(i,j)*U(j,k);
end
L(i,k) = L(i,k)/U(k,k);
end
% Finding U
for k=i:m
U(i,k) = A(i,k);
for j=1:i-1
U(i,k)= U(i,k)-L(i,j)*U(j,k);
end
end
end
for i=1:m
L(i,i)=1;
end
% Program shows U and L
U
L
% Now use a vector y to solve 'Ly=b'
y=zeros(m,1);
y(1)=B(1)/L(1,1);
for i=2:m
y(i)=-L(i,1)*y(1);
for k=2:i-1
y(i)=y(i)-L(i,k)*y(k);
y(i)=(B(i)+y(i))/L(i,i);
end;
end;
% Now we use this y to solve Ux = y
x=zeros(m,1);
x(1)=y(1)/U(1,1);
for i=2:m
x(i)=-U(i,1)*x(1);
for k=i:m
x(i)=x(i)-U(i,k)*x(k);
x(i)=(y(i)+x(i))/U(i,i);
end;
end
2)SAVE THE FOLLOWING SCRIPT FILE IN MATLAB AND HIT ENTER-
Part (B)
>> A=[2 -6 -3;-3 -1 6;-8 1 -2];
>> B=[40;20;50];
>> LU_Parker(A,B);
Part (C)
A_inverse=inv(A);
Part (D)
A_determinant=det(A);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.