0
votes

I am looking for some help with a fast loop to form a bunch of values. Given a 30-vector, x and another 30-vector which is the expected value of such data expx. I want to be able to quickly sum 30*30=90 values to form a symmetric 30x30 matrix. Here is how the (k,l)-entry of my 30x30 matrix is:

enter image description here

so x forms the entries on the left part of the bracket, x_i and expx is the right part, i.e. < x_i > for i=1,2,...,30. You don't need to worry about what values makes up these vectors, I've already determined them. Does anyone know how I should form such elements of the matrix and put them into my 30x30 matrix.

I guess I'd start off with:

M=30;
C = zeros(M); 

I'm struggling to get the summation though.

1
That's just an autocorrelation matrix, right? Have you tried the built-in functions?Ben Voigt
Well I've been calling it 'autocovariance' matrix, I think autocorrelation matrices are different unless I am incorrect? I did use the 'autocorr' and 'toeplitz' function in the past but that only works on a given vector, here I have data from two vectors namely, x and expx, this is of course assuming autocorrelation is the same as autocovariance.user1523500
I believe they are different things actually, because the diagonal entries are 1 indicating the correlation on asset to itself is 1. Auto-covariance have covariances on the diagonal entry which aren't always 1.user1523500
Your diagonal entries aren't 1 (barring something in the calculation of expx that ensures this). Yeah, maybe autocovariance is a better name. Just a scale factor difference.Ben Voigt
Also, you have only one vector, the error vector, which is e(t) = x(t) - expx(t)Ben Voigt

1 Answers

0
votes

why not this:

M=30;
C = zeros(M);
for k = 1:30
    for l = 1:30
        for i = 1:30
            C(k,l) = (x(k-i+1) - expx(k-i+1)) * (x(l-i+1) - x(l-i+1));
        end
    end
end