function condvec = plot_condition_number(lb,ub,matname,fignum)
% Call : condvec = plot_condition_number(lb,ub,matname,fignum)
% Task : Plots the condition number for the family
%		 of matrices available through the Matlab
%		 gallery by typing 
%				>> gallery(matname,n)
%		 where n is the size of the matrix. 
%		 If matname = 'randn' or the third parameter
%		 is not provided, instead of the Matlab
%		 gallery the condition numver is plotted for random
%		 matrices (i.e. the matrices are generated by
%		 randn(n);). The condition number is plotted for 
%		 matrices of various sizes ranging in [lb,ub].
%		 condvec at termination is the vector of
%		 condition numbers.

if nargin < 3
	matname = 'randn';
end

if nargin < 4
	fignum = 1;
end

jvec = [];
condvec = [];

for j = lb:ub
	if (length(matname) == 5) & (min(matname == 'randn') > 0)
		A =randn(j);
	else
		A = gallery(matname,j);
	end
	condvec = [condvec cond(A,1)];
	jvec = [jvec j]; 
end

figure(fignum);
plot(jvec,condvec,'r-');
				
return;
