Solving Systems of Linear Equations Using PROC IML

 

 

Suppose the system of linear equation is given below:

 

3x- y+2z = 8

2x-2y+3z = 2

4x+ y-4z = 9

 

in order to solve this equation,

 

      | 3 -1  2 |

let A=| 2 -2  33 |

      | 4  1 -4 |

 

 

be the coefficient matrix,

 

    | 8 |        | x |

C = | 2 |    X = | y |

    | 9 |        | z |

 

then by using matrix language, we can write the equation as:

 

   AX = C

 

and the solution of the given linear equation is:

 

   X = C*A-1

 

By using PROC IML, we can easily solve the equation. */

 

 

*--- Solving a System of Linear Equations using PROC IML;

*---SAS Program: Solve_LE.SAS;

 

proc iml;

 

reset print;

 

a={3  -1  2,

   2  -2  3,

   4   1 -4};

 

c={8, 2, 9};

 

/* Now write the solution equation, x = inv(a)*c, as an IML statement. The appropriate

   statement is an assignment statement that uses a built-in function and an operator

   (INV is a built-in function that takes the inverse of a square matrix, and * is the

   operator for matrix multiplication).

*/

 

x=inv(a)*c;

 

quit;

 

 

SAS Output (solution is given below)

 

           Solving System of Linear Equations

 

         A      3 rows      3 cols    (numeric)

 

 

 

                     3        -1         2

                     2        -2         3

                     4         1        -4

 

         C      3 rows      1 col     (numeric)

 

 

 

                               8

                               2

                               9

 

         X      3 rows      1 col     (numeric)

 

 

 

                               3

                               5

                               2