How to find covariance matrix of 3 or more vectors in matlab?

In summary, the conversation discusses finding covariance and variance of vectors and the correct equation for a covariance matrix with 3 vectors. It also mentions the use of MATLAB to find the covariance matrix and the definition of covariance and variance for random variables.
  • #1
dexterdev
194
1
Hi all,
I know how to find covariance of 2 vectors and variance too. If covariance matrix is to be found of 3 vectors x,y and z, then then the cov matrix is given by

cov_matrix(x,y,z) =[var(x) cov(x,y) cov(x,z); cov(x,y) var(y) cov(y,z); cov(x,z) cov(y,z) var(z) ];

Is this equation right? In MATLAB I believe we first have to define a 3 row matrix 'A' to consider 3 vectors at once finding covariance matrix. Then command cov(A) gives the cov matrix. But I doubt whether this result matches with the above equation.

-Devanand T
 
Physics news on Phys.org
  • #2
Hey dexterdev.

In general, the covariance matrix element (i,j) has the value Cov(Xi,Xj) = E[Xi*Xj] - E[Xi]E[Xj] for all random variables Xi and Xj. If i = j you get the variance Var[Xi].

This definition holds for any finite number of random variables.
 
  • Like
Likes 1 person
  • #3
@chiro : I got it Sir, thanks...
 
Last edited:

1. How do I input multiple vectors into a covariance matrix in matlab?

In order to input multiple vectors into a covariance matrix in matlab, you can use the "cov" function. This function takes in a matrix of data, where each row represents a different vector, and calculates the covariance matrix for those vectors.

2. Can I calculate the covariance matrix for more than 3 vectors in matlab?

Yes, the "cov" function in matlab can calculate the covariance matrix for any number of vectors. You simply need to input a matrix with each row representing a different vector.

3. How do I interpret the values in a covariance matrix?

The values in a covariance matrix represent the relationships between the different vectors. A positive value indicates a positive correlation, a negative value indicates a negative correlation, and a value close to 0 indicates little to no correlation.

4. Can I use the covariance matrix to determine the strength of the relationships between vectors?

Yes, the values in the covariance matrix can be used to determine the strength of the relationships between vectors. A larger absolute value indicates a stronger relationship, while a small value indicates a weaker relationship.

5. Is there a way to visualize the covariance matrix in matlab?

Yes, there are several ways to visualize the covariance matrix in matlab. One way is to use the "heatmap" function to create a color-coded visualization of the matrix. Another way is to use the "imagesc" function to create a visual representation of the matrix with a color scale.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
865
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
5K
  • Calculus and Beyond Homework Help
Replies
3
Views
908
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top