% SolveThis.m % this uses three programs that you must write. % You must write % (1) myLUfact(A) which returns L and U. % (2) Lsol(L,b) solves Lx = b for x given L lower triangular % (3) Usol(U,b) solves Ux = b for x given U upper triangular % only have the output specified below print to the command window. % Once it runs successfully. Clear the command window run this program % then print the command window and turn it in to me. % We seek to solve Ax = b where A = [6 -2 2 4; 12 -8 4 10; 3 -13 3 3; -6 4 2 -18]; b = [0 -10 -39 -16]'; % by the LU factorization method. % This factors the matrix. You must write myLUfact.m [myL,myU] = myLUfact(A); % Now solve Ly = b. You must write Lsol.m myY = Lsol(myL,b); % Now solve Ux = y. You must write Usol.m myX = Usol(myU,myY); % Now have MATLAB do it. matX = A\b; % This is the 2-norm of the difference between your method and MATLAB's. difference = norm(myX - matX); % These are the 2-norms of the residuals myresid = norm(A*myX - b); Matresid = norm(A*matX - b); % Output to the screen % These should be the only things printed to the command window !!!! disp('Solving Ax = b.') disp('A = ') disp(A) disp('b = ') disp(b) disp('In the LU factorization of A, L = ') disp(myL) disp('In the LU factorization of A, U = ') disp(myU) disp('My solution to Uy = b is y = ') disp(myY) disp('My solution to Lx = y is x = ') disp(myX) disp('The 2-norm of the difference between my solution and Matlabs is') disp(difference) if myresid < Matresid disp('My residual is smaller.') elseif Matresid < myresid disp('Matlabs residual is smaller.') else disp('The residuals are the same.') end