function []=hw3_2_6() % solve tridiagonal systems Ax=v of different sizes as full and sparse matrices a=2; b=1; timetable=[]; % I used larger values than they suggest because if n=50 it take virtually no % time to solve the system for n=400:40:800 % set up A and v u1=a*ones(1,n); u2=b*ones(1,n-1); A=diag(u2,-1)+diag(u1)+diag(u2,1); v=ones(n,1); % time the full method tic fullx=A\v; t1=toc; % convert A to a sparse matrix and time the sparse method spA=sparse(A); tic spx=spA\v; t2=toc; % append rows onto timetable timetable=[timetable;[n, t1, t2]]; end format short g disp(' n full time sparse time') disp(' - --------- -----------') disp(timetable) format short