Generating covariance matrices as defined in MATLAB

Click For Summary
SUMMARY

The discussion focuses on generating covariance matrices in MATLAB, specifically for an N*N matrix C where the entries are defined based on normally distributed random variables. The user seeks assistance in creating a 30*30 covariance matrix using MATLAB code, with the entries calculated as the average of the products of the corresponding elements from a vector of normally distributed random variables. The diagonal entries are consistently calculated as (1/N)*[(x_1)^2 + (x_2)^2 + ... + (x_N)^2], ensuring that the matrix C remains symmetric.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with random number generation using randn
  • Knowledge of covariance matrix properties
  • Basic statistics, specifically normal distribution concepts
NEXT STEPS
  • Learn how to implement matrix operations in MATLAB
  • Research the cov function in MATLAB for covariance matrix generation
  • Explore MATLAB's random number generation functions for larger datasets
  • Study matrix symmetry and its implications in statistical analysis
USEFUL FOR

Students and researchers in mathematics or statistics, MATLAB users looking to generate covariance matrices, and anyone involved in statistical modeling or simulations requiring random variable analysis.

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 definition 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
4K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K