Arrange your data sets. The covariance matrix can only be calculated if you have two clear, distinct groups. If your data was originally collected as a set of two different groups' information, then call the column vector representing the first group "A" and the column vector for the second "B." If you only have one data set and are planning to calculate a covariance matrix for two groups within the data, then split your data set into two vectors and label them "A" and "B."
Calculate the means of the data in the data vectors. Sum the data in one vector and divide by the size of the vector. The size of a vector is the number of data points in the vector. Do this for the other vector and call the results "mA" and "mB."
Compute the standardized vectors. Use the equations sA = A - mA*O and sB = B - mB*O, where "O" represents a vector of 1s of the same length of the vector it is being subtracted from.
Transpose sB. You can also choose to transpose sA; it does not affect the result. Transposing the vector is the action of converting a column vector to a row vector; just turn the vector on its side.
Perform the multiplication of sA*sB. Because this vector multiplication multiplies a column vector by a row vector, the result will be a matrix. Note you must place the column vector in the front for this calculation; otherwise, the result will be a single number.
Divide the resulting matrix by the number of data points for a single group. The result is a matrix of the same length and width but with smaller cell entries. This result is the estimated covariance matrix.