Decompose a Matrix Using Naive Gauss Elimination: Write your own MATLAB function
ID: 3758514 • Letter: D
Question
Decompose a Matrix Using Naive Gauss Elimination: Write your own MATLAB function code to perform LU decomposition using Naïve Gauss elimination. You’ll need to employ nested loops in this assignment. Do not use the “lu” command in your code. Package your code in a function whose input is the matrix to be decomposed, and the outputs are the corresponding lower- and upper-triangular matrices. Run your function with the following input matrix A and display the resulting lower and upper triangular matrices.
Explanation / Answer
working matlab code
function x = naiv_gauss(A,b);
n = length(b); x = zeros(n,1);
for k=1:n-1
for i=k+1:n
mula = A(i,k)/A(k,k);
for j=k+1:n
A(i,j) = A(i,j)-mula*A(k,j);
end
b(i) = b(i)-mula*b(k);
end
end
x(n) = b(n)/A(n,n);
for i=n-1:-1:1
sum = b(i);
for j=i+1:n
sum = sum-A(i,j)*x(j);
end
x(i) = sum/A(i,i);
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.