Dense symmetric positive definite matrix

How could one define a dense symmetric positive definite matrix (dimension $1000 \times 1000$) with uniformly distributed eigenvalues (with the smallest eigenvalue $1$ and the condition number $100$) in Matlab?

Because the matrix has to be symmetric, it's absolute eigenvalues are also the singular values. So $\sigma_1=100$ and $\sigma_{1000}=1$. The rest of the eigenvalues/singular values are just random numbers between 1 and 100. The last step is to check whether the matrix is positive definite, which is correct because all of it's eigenvalues are positive.

Any help on the algorithm and the implementation/code would be much appreciated!

• Do you know the algorithm and just need help expressing it Matlab? – AnonSubmitter85 Jan 26 '14 at 18:17
• I'm actually stuck on both sides. Though I think it has something to do with an SVD and generating some random elements of a matrix. Smallest eigenvalue 1 and largest equal to 100? – ABC Jan 26 '14 at 19:06
• You are more likely to get help if you edit your question to explain what you know, what you have tried, and what you do not understand. Once you wholly understand the problem, expressing it in Matlab will be easy. If you'd like more help with how to ask a question, see here. – AnonSubmitter85 Jan 26 '14 at 22:27

Since the matrix is symmetric, it must be diagonalisable. This means that we can express the matrix $A$ as $A=Q\Lambda Q^T$, where the columns of $Q$ form an orthonormal basis for the eigenspace and $\Lambda$ is a diagonal matrix with elements equal to the eigenvalues.

Now, the eigenvalues are to be uniformly distributed in $(1,100)$, with $\lambda_1=1$ and $\lambda_{1000}=100$, since the singular values and eigenvalues are the same for an spd matrix. This allows us to form the diagonal matrix as

Lambda = diag([1;100;1+99*rand(998,1)]);  % diagonal matrix of eigenvalues


We can also form an orthogonal matrix $Q$ using

R = rand(1000); % any old random matrix
[Q,~] = qr(R); % use the QR decomposition to form an orthogonal matrix


Putting this together, to form an $n\times n$ symmetric, positive definite matrix $A$ with eigenvalues in the range $[a,b]$, the following code will suffice.

% Given n, a, b

Lambda = diag([a;b;a+(b-a)*rand(n-2,1)]); % diagonal matrix of eigenvalues

R = rand(n); % any old random matrix
[Q,~] = qr(R); % use the QR decomposition to form an orthogonal matrix

A = Q*Lambda*Q';

% Output A