Login  Register

Solving Two Equations using MATRIX

Posted by Ryan on Jul 19, 2015; 6:32pm
URL: http://spssx-discussion.165.s1.nabble.com/Solving-Two-Equations-using-MATRIX-tp5730174.html

Dear SPSS-L,

Suppose we have a 6X6 correlation matrix. I have two equations I need to solve. 

The following is GIVEN: 

COMPUTE r11 = 1.
COMPUTE r12 = .20.
COMPUTE r13 = .25.
COMPUTE r14 = .85.
COMPUTE r15 = .30.
COMPUTE r16 = .15.
COMPUTE r21 = .20.
COMPUTE r22 = 1.
COMPUTE r23 = .10.
COMPUTE r24 = .05.
COMPUTE r25 = .70.
COMPUTE r26 = .30.
COMPUTE r31 = .25.
COMPUTE r32 = .10.
COMPUTE r33 = 1.
COMPUTE r34 = .35.
COMPUTE r35 = .40.
COMPUTE r36 = .80.
COMPUTE r41 = .85.
COMPUTE r42 = .05.
COMPUTE r43 = .35.
COMPUTE r44 = 1.
COMPUTE r45 = .50.
COMPUTE r46 = .45.
COMPUTE r51 = .30.
COMPUTE r52 = .70.
COMPUTE r53 = .40.
COMPUTE r54 = .50.
COMPUTE r55 = 1.
COMPUTE r56 = .55.
COMPUTE r61 = .15.
COMPUTE r62 = .30.
COMPUTE r63 = .80.
COMPUTE r64 = .45.
COMPUTE r65 = .55.
COMPUTE r66 = 1.

COMPUTE wjk14 =  2.
COMPUTE wjk15 = -1.
COMPUTE wjk16 = -1.
COMPUTE wjk24 = -1.
COMPUTE wjk25 =  2.
COMPUTE wjk26 = -1.
COMPUTE wjk34 = -1.
COMPUTE wjk35 = -1.
COMPUTE wjk36 =  2.

FIRST EQUATION:

Sum[{j=1,3},{k=4,6}: w[j,k]*r[j,k]]   

COMPUTE x = wjk14*r14 + wjk15*r15 + wjk16*r16 + 
            wjk24*r24 + wjk25*r25 + wjk26*r26 +
            wjk34*r34 + wjk35*r35 + wjk36*r36.   

While x is easy to solve outside of MATRIX, I'm curious how x could be solved more efficiently in MATRIX.

Suppose the following is GIVEN as well:

COMPUTE whm14 =  2.
COMPUTE whm15 = -1.
COMPUTE whm16 = -1.
COMPUTE whm24 = -1.
COMPUTE whm25 =  2.
COMPUTE whm26 = -1.
COMPUTE whm34 = -1.
COMPUTE whm35 = -1.
COMPUTE whm36 =  2.

SECOND EQUATION:

y = Sqrt[(.5/(N-1))*Sum[{j=1,3},{k=4,6},{h=1,3},{m=4,6}:      
         w[j,k]*w[h,m]*(                                                          
         (r[j,h]-r[j,k]*r[k,h])*(r[k,m]-r[k,h]*r[h,m]) +                     
         (r[j,m]-r[j,h]*r[h,m])*(r[k,h]-r[k,j]*r[j,h]) +                       
         (r[j,h]-r[j,m]*r[m,h])*(r[k,m]-r[k,j]*r[j,m]) +                     
         (r[j,m]-r[j,k]*r[k,m])*(r[k,h]-r[k,m]*r[m,h]))]] 

As you can see, y is far more tedious to solve outside of MATRIX. The first of 81 "Sum[{..." terms could be solved using COMPUTE as follows:

COMPUTE jk14_hm14 = wjk14*whm14*((r11-r14*r41)*(r44-r41*r14)+(r14-r11*r14)*(r41-r41*r11)+(r11-r14*r41)*(r44-r41*r14)+(r14-r14*r44)*(r41-r44*r41)).

but then I'd have to work it out for the following 80 terms:

compute jk15_hm14 = .
compute jk16_hm14 = .
compute jk24_hm14 = .
compute jk25_hm14 = .
compute jk26_hm14 = .
compute jk34_hm14 = .
compute jk35_hm14 = .
compute jk36_hm14 = .

compute jk14_hm24 = .
compute jk15_hm24 = .
compute jk16_hm24 = .
compute jk24_hm24 = .
compute jk25_hm24 = .
compute jk26_hm24 = .
compute jk34_hm24 = .
compute jk35_hm24 = .
compute jk36_hm24 = .

compute jk14_hm34 = .
compute jk15_hm34 = .
compute jk16_hm34 = .
compute jk24_hm34 = .
compute jk25_hm34 = .
compute jk26_hm34 = .
compute jk34_hm34 = .
compute jk35_hm34 = .
compute jk36_hm34 = .

compute jk14_hm15 = .
compute jk15_hm15 = .
compute jk16_hm15 = .
compute jk24_hm15 = .
compute jk25_hm15 = .
compute jk26_hm15 = .
compute jk34_hm15 = .
compute jk35_hm15 = .
compute jk36_hm15 = .

compute jk14_hm16 = .
compute jk15_hm16 = .
compute jk16_hm16 = .
compute jk24_hm16 = .
compute jk25_hm16 = .
compute jk26_hm16 = .
compute jk34_hm16 = .
compute jk35_hm16 = .
compute jk36_hm16 = .

compute jk14_hm25 = .
compute jk15_hm25 = .
compute jk16_hm25 = .
compute jk24_hm25 = .
compute jk25_hm25 = .
compute jk26_hm25 = .
compute jk34_hm25 = .
compute jk35_hm25 = .
compute jk36_hm25 = .

compute jk14_hm26 = .
compute jk15_hm26 = .
compute jk16_hm26 = .
compute jk24_hm26 = .
compute jk25_hm26 = .
compute jk26_hm26 = .
compute jk34_hm26 = .
compute jk35_hm26 = .
compute jk36_hm26 = .

compute jk14_hm35 = .
compute jk15_hm35 = .
compute jk16_hm35 = .
compute jk24_hm35 = .
compute jk25_hm35 = .
compute jk26_hm35 = .
compute jk34_hm35 = .
compute jk35_hm35 = .
compute jk36_hm35 = .

compute jk14_hm36 = .
compute jk15_hm36 = .
compute jk16_hm36 = .
compute jk24_hm36 = .
compute jk25_hm36 = .
compute jk26_hm36 = .
compute jk34_hm36 = .
compute jk35_hm36 = .
compute jk36_hm36 = .

and then sum the 81 terms and multiply by Sqrt[(.5/(N-1)).

Any tips would be most appreciated. 

Thanks,

Ryan
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD