clearvars; %format long; prompt1 = 'What is the value of n? '; prompt2 = 'What is the value of delta? '; n = input(prompt1); delta= input(prompt2); I=eye(n,n); z=rand(n,n); % disp(' '); disp('If A*x=b where'); A=I+delta*z; % disp('and'); b=rand(n,1); tic; x=A\b; norm_Method_A = norm(x,2); t=toc; fprintf('%s %9.4f %s\n','then using Matlab''s ''backslash'' command, Method A, it requires ',... t,'seconds to compute solutions'); fprintf('%s %9.4f\n','for Method A, the 2-norm of vector x =', norm_Method_A); % for i=1:n; % fprintf('%s %i %s %7.5f\n',' x(',i,')=',x(i) ); % end tic; x=inv(A)*b; norm_Method_B = norm(x,2); t=toc; fprintf('%s %9.4f %s\n','then using Matlab''s inv(A) command, Method B, it requires ',... t,' seconds to compute solutions'); fprintf('%s %9.4f\n','for Method B, the 2-norm of vector x =', norm_Method_B); % for i=1:n; % fprintf('%s %i %s %7.5f\n',' x(',i,')=',x(i) ); % end tic; DetA=det(A); for i=1:n; B=A; B(:,i)=b; x(i)=det(B)/DetA; end norm_Method_C = norm(x,2); t=toc; fprintf('%s %9.4f %s\n','then using Cramer''s Rule, Method C, it requires ',... t,' seconds to compute solutions'); fprintf('%s %9.4f\n','for Method C, the 2-norm of vector x =', norm_Method_C); % for i=1:n; % fprintf('%s %i %s %7.5f\n',' x(',i,')=',x(i) ); % end