You are Here: Home >< Maths

# Generating an SPD matrix watch

1. I'm writing a computer program which involves using real random, symmetric positive definite matrices.

An SPD matrix M is symmetric and satisfies x^T M x >0 for all non-zero vectors z with real entries.

Can someone explain how I can generate these matrices?
2. I don't know if there's a more standard way to do it, but all SPD matrices are orthogonally diagonalizable with positive eigenvalues.

You could randomly choose a set of positive entries in a diagonal matrix D, take a random matrix X (which would almost always be invertible) and use Gram-Schmidt to turn it into an orthogonal matrix P. It would then be the case that P^T D P would be an SPD matrix.

What sort of distribution, though, are you looking to have on your SPD matrices?
3. (Original post by RichE)
What sort of distribution, though, are you looking to have on your SPD matrices?
Uniform.
4. (Original post by 0-))
Uniform.
Think that will be impossible - it's like asking for a uniform distribution on the real line
5. (Original post by RichE)
Think that will be impossible - it's like asking for a uniform distribution on the real line
I don't think I meant uniform. I just need any random SPD matrices formed from a matrix formed using a random number generator.
6. (Original post by 0-))
I don't think I meant uniform. I just need any random SPD matrices formed from a matrix formed using a random number generator.
In that case you could do what I suggested in my first post - but to what end are you producing these SPDs? Surely you care about their distribution if they're to serve some purpose.
7. (Original post by RichE)
In that case you could do what I suggested in my first post - but to what end are you producing these SPDs? Surely you care about their distribution if they're to serve some purpose.
I'm trying to generate random SPD matrices to test my conjugate gradient method program.
8. (Original post by 0-))
I'm trying to generate random SPD matrices to test my conjugate gradient method program.
In that case it would probably be enough to take a fixed orthogonal matrix P and use your random number generator to populate a diagonal matrix with positive entries.

P^T D P would then be an SPD matrix.

### Related university courses

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: March 21, 2011
Today on TSR

### He lied about his age

Thought he was 19... really he's 14

### University open days

Wed, 25 Jul '18
2. University of Buckingham
Wed, 25 Jul '18
3. Bournemouth University
Wed, 1 Aug '18
Poll
Useful resources

### Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

### How to use LaTex

Writing equations the easy way

### Study habits of A* students

Top tips from students who have already aced their exams