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

Submit your M-files and a diary showing how you tested the code. Submit the M-fi

ID: 3788598 • Letter: S

Question

Submit your M-files and a diary showing how you tested the code. Submit the M-files for forward, backward, and mySolve, but not MYLU. Write a file forward.m to solve n times n lower triangular systems and a file backward.m to solve n times n upper triangular systems. Then write an M-file mySolve.m to solve n times n systems (under the assumption that elimination can be performed without row exchanges). Use MYLU.m from last week's assignment. Test your code on Ax = b with A = [1 -5 -4 -9 5 -3 0 4 -1 0 -8 -3 -9 -3 -2 8 -8 -6 9 5 4 7 -4 0 -3], b = [-9 -4 7 6 -2]

Explanation / Answer

for solving lower triangular system (forward.m)

x=zeros(n,1);
for j=1:n
    if (A(j,j)==0) end; %for checking singular matrix
    x(j)=b(j)/A(j,j);
    b(j+1:n)=b(j+1:n)-L(j+1:n,j)*x(j);
end

for solving upper triangular system (backward.m)

x=zeros(n,1);
for j=n:-1:1
    if (A(j,j)==0) error('Matrix is singular!'); end;
    x(j)=b(j)/U(j,j);
    b(1:j-1)=b(1:j-1)-A(1:j-1,j)*x(j);
end

solving Ax=B (mySolve.m)

this can be solved using Gauss Elimination method

or can be solved using insolve function