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!
Answer
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
No comments:
Post a Comment