user706838
user706838

Reputation: 5380

Implementation of correlation matrix in MATLAB

I want to implement the following formula in MATLAB, where u_i^(k) means the i,k element. However, I get different results from the ones I compute by hand... I believe that something is wrong with my MATLAB code. For instance, I should get:

L_ii =

    0.1022         0         0
         0    0.1657         0
         0         0    2.7321

U_ij =

    0.7514    0.3104    0.5823
   -0.6513    0.4901    0.5793
   -0.1055   -0.8145    0.5704

1,1=1-(0.1022*(+0.7514)^2+0.1657*(+0.3104)^2+2.7321*(+0.5823)^2)=-0.000049
2,2=1-(0.1022*(-0.6513)^2+0.1657*(+0.4901)^2+2.7321*(+0.5793)^2)=-0.000015
3,3=1-(0.1022*(-0.1055)^2+0.1657*(-0.8145)^2+2.7321*(+0.5704)^2)=+0.000030

Any ideas??? Please, help me fix Epsilon first (it might not need to move on Rho. Let's fix Epsilon first...)

enter image description here

enter image description here

EDIT: Here is a sample code:

E_squared_ii = ONES_j - diag(L_ii)' * (U_ij'.^ 2)

And here is the wrong result I get at the moment:

E_squared_ii =

   1.0e-15 *

   0.444089209850063   0.333066907387547  -0.222044604925031

Upvotes: 0

Views: 642

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272487

If I use your values and code, I get the expected result:

>> L_ii

L_ii =

    0.1022         0         0
         0    0.1657         0
         0         0    2.7321

>> U_ij

U_ij =

    0.7514    0.3104    0.5823
   -0.6513    0.4901    0.5793
   -0.1055   -0.8145    0.5704

>> ONES_j

ONES_j =

     1     1     1

>> E_squared_ii = ONES_j - diag(L_ii)' * (U_ij'.^ 2)

E_squared_ii =

   1.0e-04 *

   -0.4935   -0.1451    0.2985

Presumably this means that something isn't the value you think it is...

Upvotes: 1

Related Questions