Generating covariance matrices as defined in MATLAB

In summary, the conversation discusses the creation of a MATLAB code to generate a 30*30 covariance matrix using a set of normally distributed variables. The (k,l)-entry of the matrix is defined as (1/N)*[(x_k)*(x_l) + (x_l)*(x_(l+1))], where x_i is a random variable with mean 0 and variance 1. The diagonal entries are always (1/N)*[(x_1)^2 + (x_2)^2 + ... + (x_N)^2] and the matrix is always symmetric. The conversation also mentions the use of the MATLAB function "cov" to generate these matrices.
  • #1
varth
5
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

1. What is a covariance matrix and why is it useful?

A covariance matrix is a mathematical tool used to measure the linear relationship between multiple variables. It is useful because it can provide insight into the interdependence and strength of these relationships, which can be beneficial in various fields such as statistics, finance, and data analysis.

2. How is a covariance matrix generated in MATLAB?

In MATLAB, a covariance matrix can be generated using the cov function. This function takes in a matrix of data as its input and returns a square matrix with the covariance values between each pair of variables in the data.

3. What are the assumptions made when generating a covariance matrix?

The main assumptions made when generating a covariance matrix are that the variables are continuous, normally distributed, and have a linear relationship with each other. If these assumptions are not met, the resulting covariance matrix may not accurately reflect the true relationships between the variables.

4. How can I interpret the values in a covariance matrix?

The values in a covariance matrix represent the strength and direction of the linear relationship between two variables. A positive value indicates a positive relationship, meaning that when one variable increases, the other tends to increase as well. A negative value indicates a negative relationship, meaning that when one variable increases, the other tends to decrease. A value close to zero indicates a weak or no relationship between the variables.

5. Can a covariance matrix be used to determine causality?

No, a covariance matrix alone cannot determine causality between variables. It only measures the strength of linear relationships, and there may be other factors at play that are not captured in the matrix. Additional analysis and experimentation are needed to determine causality.

Similar threads

Replies
3
Views
746
  • Quantum Physics
Replies
21
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
981
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
16
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Precalculus Mathematics Homework Help
2
Replies
57
Views
3K
Back
Top