Output from imlinv2.sas

Source
0 Graphs

Output from imlinv2.sas

NOTE: Capture of log output started.

NOTE: %INCLUDE (level 1) file c:\sasuser\psy6140\examples\iml\imlinv2.sas is
      file c:\sasuser\psy6140\examples\iml\imlinv2.sas.
1144 +title 'IMLINV2: Matrix inversion by elementary row operations';
1145 +proc iml;
NOTE: IML Ready
1145!+          reset print log;
1146 +   *--Gauss-Doolittle method;
1147 +
1148 +   A = {1 2 3,  2 3 0,  0 1 2};


























                    A      3 rows      3 cols    (numeric)



                                1         2         3
                                2         3         0
                                0         1         2
1149 +   *--Join an identity matrix to A;
1150 +   AI =  A || I(3);

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 2         3         0         0         1         0
                 0         1         2         0         0         1
1151 +
1152 +   *--Apply elementary row operations to reduce A to an identity
1153 +      matrix. The left three cols will then contain inv(A);
1154 +
1155 +   *-- 1. ROW 2 <- ROW 2 - 2 # ROW 1;
1156 +   AI[2,] = AI[2,] - 2#AI[1,];

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0        -1        -6        -2         1         0
                 0         1         2         0         0         1
1157 +
1158 +   *-- 2. ROW 3 <- ROW 3 + ROW 2;
1159 +   AI[3,] = AI[3,] + AI[2,];

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0        -1        -6        -2         1         0
                 0         0        -4        -2         1         1
1160 +
1161 +   *-- 3. ROW 3 <- -.25 # ROW 3;
1162 +   AI[3,] =  -.25 # AI[3,];

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0        -1        -6        -2         1         0
                 0         0         1       0.5     -0.25     -0.25
1163 +   *--continue, making off-diag =0;
1164 +   AI[2,] = -1 # AI[2,] ;

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0         1         6         2        -1         0
                 0         0         1       0.5     -0.25     -0.25
1165 +
1166 +   AI[2,] = AI[2,] - 6 # AI[3,];

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0         1         0        -1       0.5       1.5
                 0         0         1       0.5     -0.25     -0.25
1167 +   *-- row 1 <- row 1 - 2 # row 2;
1168 +   AI[1,] = AI[1,] - 2 # AI[2,];

                   AI      3 rows      6 cols    (numeric)



                 1         0         3         3        -1        -3
                 0         1         0        -1       0.5       1.5
                 0         0         1       0.5     -0.25     -0.25
1169 +
1170 +   AI[1,] = AI[1,] - 3 # AI[3,];

                   AI      3 rows      6 cols    (numeric)



                 1         0         0       1.5     -0.25     -2.25
                 0         1         0        -1       0.5       1.5
                 0         0         1       0.5     -0.25     -0.25
1171 +
1172 +   *-- last three cols are the inverse;
1173 +   AInv=AI[,{1 2 3}];

                  AINV      3 rows      3 cols    (numeric)



                                1         0         0
                                0         1         0
                                0         0         1
1174 +
1175 +   *-- compare with echelon;
1176 +   r = echelon( A || I(3));

                    R      3 rows      6 cols    (numeric)



                 1         0         0       1.5     -0.25     -2.25
                 0         1         0        -1       0.5       1.5
                 0         0         1       0.5     -0.25     -0.25
1177 +   *-- compare with inv();
1178 +   r = inv(A);

                    R      3 rows      3 cols    (numeric)



                              1.5     -0.25     -2.25
                               -1       0.5       1.5
                              0.5     -0.25     -0.25
1179 +
1180 +   *--- same, using matlib function ---;
1181 +   %include iml(matlib);
NOTE: Module ROW defined.
NOTE: Module COL defined.
NOTE: Module R defined.
NOTE: Module MINOR defined.
NOTE: Module COFACTOR defined.
NOTE: Module PROJ defined.
NOTE: Module LEN defined.
NOTE: Module DEV defined.
NOTE: Module SCP defined.
NOTE: Module CORR defined.
NOTE: Module COV defined.
NOTE: Module ROWADD defined.
NOTE: Module ROWSWAP defined.
NOTE: Module ROWMULT defined.
NOTE: Module MPOWER defined.
NOTE: Module MEDIAN defined.
1422 +   AI =  A || I(3);

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 2         3         0         0         1         0
                 0         1         2         0         0         1
1423 +   *-- 1. ROW 2 <- ROW 2 - 2 # ROW 1;
1424 +   AI = rowadd(AI, 1, 2, -2);

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0        -1        -6        -2         1         0
                 0         1         2         0         0         1
1425 +   *-- 2. ROW 3 <- ROW 3 + ROW 2;
1426 +   AI = rowadd(AI, 2, 3, 1);

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0        -1        -6        -2         1         0
                 0         0        -4        -2         1         1
1427 +   *-- 3. ROW 3 <- -.25 # ROW 3;
1428 +   AI = rowmult(AI, 3, -.25);

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0        -1        -6        -2         1         0
                 0         0         1       0.5     -0.25     -0.25
1429 +
1430 +  *--continue, making off-diag =0;
1431 +   AI = rowmult(AI, 2, -1);

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0         1         6         2        -1         0
                 0         0         1       0.5     -0.25     -0.25
1432 +   AI = rowadd(AI, 3, 2, -6);

                   AI      3 rows      6 cols    (numeric)



                 1         2         3         1         0         0
                 0         1         0        -1       0.5       1.5
                 0         0         1       0.5     -0.25     -0.25
1433 +   AI = rowadd(AI, 2, 1, -2);

                   AI      3 rows      6 cols    (numeric)



                 1         0         3         3        -1        -3
                 0         1         0        -1       0.5       1.5
                 0         0         1       0.5     -0.25     -0.25
1434 +*   AI[1,] = AI[1,] - 2 # AI[2,];
1435 +
1436 +   AI = rowadd(AI, 3, 1, -3);

                   AI      3 rows      6 cols    (numeric)



                 1         0         0       1.5     -0.25     -2.25
                 0         1         0        -1       0.5       1.5
                 0         0         1       0.5     -0.25     -0.25
1437 +*   AI[1,] = AI[1,] - 3 # AI[3,];
1438 +
1439 +
1440 +quit;
NOTE: Exiting IML.






1441 +
NOTE: %INCLUDE (level 1) ending.