function A = matgen(n, condno)

%  Generate an n by n random matrix with 2-norm condition number condno.

%    First generate two random orthogonal matrices U and V.

[U,R] = qr(randn(n,n));
[V,R] = qr(randn(n,n));

%    Now generate the diagonal matrix of singular values ranging from
%    1 to 1/condno.

Sigma = zeros(n,n);
for i=1:n, Sigma(i,i) = condno^(-(i-1)/(n-1)); end;

%    Now form A.

A = U*Sigma*V';
