MATLAB Generating covariance matrices as defined in MATLAB

Click For Summary
The discussion centers around generating a symmetric N*N matrix C in MATLAB, where the entries are defined based on a vector x of normally distributed random variables with mean 0 and variance 1. The user seeks assistance in creating this matrix for N=30, using the formula for the (k,l)-entry of C, which involves the products of the elements of x. The diagonal entries of the matrix are consistently calculated as (1/N)*[(x_1)^2 + (x_2)^2 + ... + (x_N)^2]. The user is looking for MATLAB code to automate this process, as they can manually compute the entries for smaller matrices but require a solution for larger sizes for a math project. The discussion also references MATLAB's covariance matrix functionality as a potential resource.
varth
Messages
5
Reaction score
0
Hi, I'm fairly new to MATLAB and I was wondering if you guys could help me out. If I have an N*N matrix, C where the (k,l)-entry is defined as:
http://a3.sphotos.ak.fbcdn.net/hphotos-ak-ash3/556394_10151031836051952_2120388553_n.jpg

Where x_i is from an N-vector where x_i is normally distributed with 0 mean and variance 1. So x_i ~ N(0,1).
And so the vector, x= [x_1 x_2 ... x_N] = [ randn randn ... rand]

For the case N=3, we have
http://a5.sphotos.ak.fbcdn.net/hphotos-ak-ash3/532427_10151031836071952_2140805136_n.jpg

and x= [x_1 x_2 x_2] = [randn randn randn].

So the (1,2)-entry of C, is: http://a2.sphotos.ak.fbcdn.net/hphotos-ak-snc7/417729_10151031836006952_1450809886_n.jpg
which equals (if worked out) (1/3)*[(x_1)*(x_2) + (x_2)*(x_3)]

We can work out all the other entries of C and then get a 3*3 matrix.

All of this I can do my hand but what I want Matlab to do this task but for N=30.

So here x=[x_1 x_2 ... x_30] = [randn randn ... randn]
I need a code to generate my 30*30 matrix C from such set x_i's with the defintion above (N replaced by 30 of course). Does anyone know how I go about doing this?

EDIT: If it helps at all, the diagonal entries are always the same, it is always (1/N)*[(x_1)^2 + (x_2)^2 + ... + (x_N)^2]
and the matrix, C is always symmetric. I would appreciate any help on this; I need to generate these random matrices for a maths project of mine.
 
Last edited by a moderator:
Physics news on Phys.org

Similar threads

  • · Replies 4 ·
Replies
4
Views
1K
Replies
11
Views
6K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K