Gaussian Elimation Problem. Using matlab, write a function, called ge, that solv
ID: 3820499 • Letter: G
Question
Gaussian Elimation Problem.
Using matlab, write a function, called ge, that solves the linear system Ax=b (where A Mn() and b n. Note that we are talking about n by m matricies.) via Gaussian elimination without pivoting. The code should compute the LU (lower upper) decomposition of A, with the matricies L and U stored over A. The code should solve the system by solving the lower triangular system Ly=b (using row oriented forward substitution), and then solving the upper triangular system Ux=y (using row oriented back substitution).
.
Explanation / Answer
LU (lower upper) decomposition
function[L,U]=ludec(A);
[n,n]=size(a);
for k=1:n-1
A(k+1:n,k)=A(k+1:n,k)/A(k,k);
A(k+1:n,k+1:n)=A(k+1:n,k+1:n)-A(k+1:n,k)*A(k,k+1:n);
End
L=eye(n, n)+tril(A,-1);
U=triu(A);
endfunction
-----------------------------------------------------------------------------------
Lower triangular system Ly=b (using row oriented forward substitution)
function y=lowtri (L,b)
n=length(b);
y=zeros (n,1);
y(1)=b(1)/L(1,1);
for i=2:n
y(i)=(b(i)-L(i,1:i-1)*y(1:i-1))/L(i,i)
end;
endfunction
--------------------------------------------------------------------------
Upper triangular system Ux=y (using row oriented back substitution)
function x=uptri (U,y)
n=length(y);
x=zeros (n,1);
x(n)=y(n)/U(n,n);
for i=n-1 :-1: 1
x(i)=(y(i)-U(i,i+1:n)*x(i+1:n))/U(i,i)
end;
endfunction
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.