Output from imlinv1.sas

Source
0 Graphs

NOTE: Capture of log output started.
NOTE: %INCLUDE (level 1) file n:\psy6140\examples\iml\imlinv1.sas is file
      n:\psy6140\examples\iml\imlinv1.sas.
559  +title 'IMLINV1: Inverse of a matrix';
560  +proc iml;
IML Ready
560  +          reset print log fuzz;
561  +   *--INVERSE OF A MATRIX;
562  +   A = {5 1 0,  3 -1 2,  4 0 -1};
                A             3 rows      3 cols    (numeric)

                                5         1         0
                                3        -1         2
                                4         0        -1

563  +   r = det(A);
                R             1 row       1 col     (numeric)

                                         16

564  +
565  +   *-- 1. det(a)<>0, so inverse exists;
566  +   AI = inv(A);
                AI            3 rows      3 cols    (numeric)

                           0.0625    0.0625     0.125
                           0.6875   -0.3125    -0.625
                             0.25      0.25      -0.5

567  +
568  +   *-- 2. AI * A = I(nrow(A));
569  +   r = AI * A;
                R             3 rows      3 cols    (numeric)

                                1         0         0
                                0         1         0
                                0         0         1

570  +
571  +   *-- 3. Inverse is REFLEXIVE: inv(inv(A)) = A;
572  +   r = inv(AI);
                R             3 rows      3 cols    (numeric)

                                5         1         0
                                3        -1         2
                                4         0        -1

573  +
574  +   *-- 4. inv(A) is SYMMETRIC only if A is symmetric;
575  +   r = inv(A`);
                R             3 rows      3 cols    (numeric)

                           0.0625    0.6875      0.25
                           0.0625   -0.3125      0.25
                            0.125    -0.625      -0.5

576  +
577  +   B = {4 2 2, 2 3 1, 2 1 3};
                B             3 rows      3 cols    (numeric)

                                4         2         2
                                2         3         1
                                2         1         3

578  +   r = inv(B);
                R             3 rows      3 cols    (numeric)

                              0.5     -0.25     -0.25
                            -0.25       0.5         0
                            -0.25         0       0.5

579  +   r = inv(B`);
                R             3 rows      3 cols    (numeric)

                              0.5     -0.25     -0.25
                            -0.25       0.5         0
                            -0.25         0       0.5

580  +
581  +   *--PROPERTIES OF MATRIX INVERSE;
582  +
583  +   *-- 1. inv of diagonal matrix = diag( 1/ diagonal);
584  +   D =diag({ 1 2 4 });
                D             3 rows      3 cols    (numeric)

                                1         0         0
                                0         2         0
                                0         0         4

585  +   r = inv(D);
                R             3 rows      3 cols    (numeric)

                                1         0         0
                                0       0.5         0
                                0         0      0.25

586  +   r = diag(1 / {1 2 4});
                R             3 rows      3 cols    (numeric)

                                1         0         0
                                0       0.5         0
                                0         0      0.25

587  +
588  +   *-- 2. INVERSE of an INVERSE: inv(inv(A)) = A;
589  +   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

590  +   AI=inv(A);
                AI            3 rows      3 cols    (numeric)

                              1.5     -0.25     -2.25
                               -1       0.5       1.5
                              0.5     -0.25     -0.25

591  +   r = inv(AI);
                R             3 rows      3 cols    (numeric)

                                1         2         3
                                2         3         0
                                0         1         2

592  +
593  +   *-- 3. inverse of a transpose: inv(a`) = (inv(a))`;
594  +   r =inv(A`);
                R             3 rows      3 cols    (numeric)

                              1.5        -1       0.5
                            -0.25       0.5     -0.25
                            -2.25       1.5     -0.25

595  +   r = (inv(A))`;
                R             3 rows      3 cols    (numeric)

                              1.5        -1       0.5
                            -0.25       0.5     -0.25
                            -2.25       1.5     -0.25

596  +
597  +   *-- 4. inv of scalar # matrix:  inv( k#A ) = (1/k) # inv(A);
598  +   r = inv(5#A);
                R             3 rows      3 cols    (numeric)

                              0.3     -0.05     -0.45
                             -0.2       0.1       0.3
                              0.1     -0.05     -0.05

599  +   r = (1/5)#inv(A);
                R             3 rows      3 cols    (numeric)

                              0.3     -0.05     -0.45
                             -0.2       0.1       0.3
                              0.1     -0.05     -0.05

600  +
601  +   *-- 5. inverse of a matrix product: inv(A * B) = inv(B) * inv(A);
602  +   B = {1 2 3, 1 3 2, 2 4 1};
                B             3 rows      3 cols    (numeric)

                                1         2         3
                                1         3         2
                                2         4         1

603  +   r = A * B;
                R             3 rows      3 cols    (numeric)

                                9        20        10
                                5        13        12
                                5        11         4

604  +   r = inv(A * B);
                R             3 rows      3 cols    (numeric)

                                4      -1.5      -5.5
                               -2       0.7       2.9
                              0.5     -0.05     -0.85

605  +   r = (inv(B)) * (inv(A));
                R             3 rows      3 cols    (numeric)

                                4      -1.5      -5.5
                               -2       0.7       2.9
                              0.5     -0.05     -0.85

606  +quit;
Exiting IML.
NOTE: The PROCEDURE IML used 0.22 seconds.

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