function []=hw3_2_10(n) % solve a linear system Ex=b by \ and by LU % note: the answer should be [0,0,0... n+1] % set up E, but don't use C that's an extra matrix to store E=zeros(n); for i=1:n for j=1:n if (i==j) E(i,j)=i*(n-i+1); elseif (j>i) E(i,j)=E(i,j-1)-i; else E(i,j)=E(j,i); end end end E=1/(n+1)*E; b=[1:n]'; % \ method x1=E\b; % LU method [L,U]=lu(E); y=L\b; x2=U\y; % print x1,x2 as rows to save space disp('x1 from the \ method') x1' disp('x2 from the LU method') x2' % cond(E)