%A script to investigate condition number on bidiagonal matrix
%M126 HW1 #3
%1/12/12
%Brad Nelson;

%for loop to run over values of m
i=0;
relerr=zeros(1,96);
for m=5:100;
i=i+1;
%setting up the matrix
c=1;
r=[1 2];
c=wextend('1d','zpd',c,m-1,'r'); %extends vector to length of matrix
r=wextend('1d','zpd',r,m-2,'r');
A=toeplitz(c,r); %m x m matrix with 1 on diagonal, 2 to the right

x=rand(m,1); %sets up random vector

b=A*x; %finds b such that Ax=b
y=mldivide(A,b); %y=A^{-1}b
diff=y-x; %difference between actual x and computed x
relerr(i)=norm(diff)/norm(x); %relative error
end

ms=5:100;
figure;
semilogy(ms,relerr);
xlabel('m');ylabel('relative error');f(x)

print -depsc toep.eps