Previous Page | Next Page

The FCMP Procedure

Special Functions and CALL Routines: Matrix CALL Routines


CALL Routines and Matrix Operations

The FCMP procedure provides you with a number of CALL routines for performing simple matrix operations on declared arrays. These CALL routines are automatically provided by the FCMP procedure. With the exception of ZEROMATRIX, FILLMATRIX, and IDENTITY, the CALL routines listed below do not support matrices or arrays that contain missing values.

Function or CALL routine Description
ADDMATRIX CALL Routine
performs an element-wise addition of two matrices or a matrix and a scalar.
CHOL CALL Routine
(CHOLESKY_DECOMP CALL routine) calculates the Cholesky decomposition for a given symmetric matrix.
DET CALL Routine
calculates the determinant of a specified matrix that should be square.
ELEMMULT CALL Routine
performs an element-wise multiplication of two matrices.
EXPMATRIX CALL Routine
returns a matrix etA given the input matrix A and a multiplier t. The CALL routine uses a Padé approximation algorithm.
FILLMATRIX CALL Routine
replaces all of the element values of the input matrix with the specified value. You can use the FILLMATRIX CALL routine with multidimensional numeric arrays.
IDENTITY CALL Routine
converts the input matrix to an identity matrix. Diagonal element values of the matrix will be set to 1, and the rest of the values will be set to 0.
INV CALL Routine
calculates a matrix that is the inverse of the provided input matrix that should be a square, non-singular matrix.
MULT CALL Routine
calculates the multiplicative product of two input matrices.
POWER CALL Routine
raises a square matrix to a given scalar value.
SUBTRACTMATRIX CALL Routine
performs an element-wide subtraction of two matrices or a matrix and a scalar.
TRANSPOSE CALL Routine
returns the transpose of a matrix.
ZEROMATRIX CALL Routine
replaces all of the element values of the numeric input matrix with 0.


ADDMATRIX CALL Routine

The ADDMATRIX CALL routine performs an element-wise addition of two matrices or a matrix and a scalar.

The syntax of the ADDMATRIX CALL routine has the following form:

CALL ADDMATRIX (X, Y, Z)

where

X

specifies an input matrix with dimensions m x n (that is, X[m, n]) or a scalar.

Y

specifies an input matrix with dimensions m x n (that is, Y[m, n]) or a scalar.

Z

specifies an output matrix with dimensions m x n (that is, Z[m, n]).

such that

[equation]

Note that all input and output matrices need to have the same dimensions.

The following example uses the ADDMATRIX CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,2] (0.3, -0.78, -0.82, 0.54, 1.74, 1.2);
   array mat2[3,2] (0.2, 0.38, -0.12, 0.98, 2, 5.2);
   array result[3,2];
   call addmatrix (mat1, mat2, result);
   call addmatrix (2, mat1, result);
   put result=;
 quit;

Output from the ADDMATRIX CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=2.3 result[1, 2]=1.22 result[2, 1]=1.18 result[2, 2]=2.54
result[3, 1]=3.74 result[3, 2]=3.2

CHOL CALL Routine

The CHOL CALL routine (CHOLESKY_DECOMP CALL routine) calculates the Cholesky decomposition for a given symmetric matrix.

The syntax of the CHOL CALL routine has the following form:

CALL CHOL (X, Y <, validate>)

where

X

specifies a symmetric positive-definite input matrix with dimensions m x m (that is, X[m, m]).

Y

specifies an output matrix with dimensions m x m (that is, Y[m, m]). This variable contains the Cholesky decomposition.

validate

specifies an optional argument which can increase the processing speed by avoiding error checking.

If validate = 0 or is not specified, then the matrix X will be checked for symmetry.

If validate = 1, then the matrix is assumed to be symmetric.

such that

[equation]

where Y is a lower triangular matrix with strictly positive diagonal entries and Y* denotes the conjugate transpose of Y.

Note that both input and output matrices need to be square and have the same dimensions. X must be symmetric positive-definite, and Y will be a lower triangle matrix.

If X is not symmetric positive-definite, Y will be filled with missing values.

The following example uses the CHOL CALL routine:

proc fcmp;
   array xx[3,3] 2 2 3 2 4 2 3 2 6;
   array yy[3,3];
   call chol(xx, yy, 0);
   do i = 1 to 3;
      put yy[i, 1] yy[i, 2] yy[i, 3];
   end;
run;

SAS produces the following output:

Output from PROC FCMP and the CHOL CALL Routine

                                 The SAS System                                1

                               The FCMP Procedure

1.4142135624 0 0
1.4142135624 1.4142135624 0
2.1213203436 -0.707106781 1

DET CALL Routine

The DET CALL routine calculates the determinant of a specified matrix that should be square.

The determinant, the product of the eigenvalues, is a single numeric value. If the determinant of a matrix is zero, then that matrix is singular; that is, it does not have an inverse. The method performs an LU decomposition and collects the product of the diagonals (Forsythe, Malcolm, and Moler 1967). See the SAS/IML User's Guide for more information.

The syntax of the DET CALL routine has the following form:

CALL DET (X, a)

where

X

specifies an input matrix with dimensions m x n (that is, X[m, m]).

a

specifies the returned determinate value.

such that

[equation]

Note that the input matrix X needs to be square.

The following example uses the DET CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,3] (.03, -0.78, -0.82, 0.54, 1.74,
                     1.2, -1.3, 0.25, 1.49);
   call det (mat1, result);
   put result=;
quit;

Output from the DET CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result=-0.052374

ELEMMULT CALL Routine

The ELEMMULT CALL routine performs an element-wise multiplication of two matrices.

The syntax of the ELEMMULT CALL routine has the following form:

CALL ELEMMULT (X, Y, Z)

where

X

specifies an input matrix with dimensions m x n (that is, X[m, n]).

Y

specifies an input matrix with dimensions m x n (that is, Y[m, n]).

Z

specifies an output matrix with dimensions m x n (that is, Z[m, n]).

Note that all input and output matrices need to have the same dimensions.

The following example uses the ELEMMULT CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,2] (0.3, -0.78, -0.82, 0.54, 1.74, 1.2);
   array mat2[3,2] (0.2, 0.38, -0.12, 0.98, 2, 5.2);
   array result[3,2];
   call elemmult (mat1, mat2, result);
   call elemmult (2.5, mat1, result);
   put result=;
 quit;

Output from the ELEMMULT CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=0.75 result[1, 2]=-1.95 result[2, 1]=-2.05 result[2, 2]=1.35
result[3, 1]=4.35 result[3, 2]=3

EXPMATRIX CALL Routine

The EXPMATRIX CALL routine returns a matrix etA given the input matrix A and a multiplier t. The CALL routine uses a Padé approximation algorithm as presented in Golub and van Loan (1989), p. 558. Note that this module does not exponentiate each entry of a matrix. Refer to the EXPMATRIX documentation in the SAS/IML User's Guide for more information.

The syntax of the EXPMATRIX CALL routine has the following form:

CALL EXPMATRIX (X, t, Y)

where

X

specifies an input matrix with dimensions m x m (that is, X[m, m]).

t

specifies a double scalar value.

Y

specifies an output matrix with dimensions m x m (that is, Y[m, m]).

such that

[equation]

Note that both input and output matrices need to be square and have the same dimensions. t can be any scalar value.

The following example uses the EXPMATRIX CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,3] (0.3, -0.78, -0.82, 0.54, 1.74,
                    1.2, -1.3, 0.25, 1.49);
   array result[3,3];
   call expmatrix (mat1, 3, result);
   put result=;
quit;

Output from the EXPMATRIX CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=365.58043585 result[1, 2]=-589.6358476 result[1, 3]=-897.1034008
result[2, 1]=-507.0874798 result[2, 2]=838.64570481 result[2, 3]=1267.3598426
result[3, 1]=-551.588816 result[3, 2]=858.97629382 result[3, 3]=1324.8187125

FILLMATRIX CALL Routine

The FILLMATRIX CALL routine replaces all of the element values of the input matrix with the specified value. You can use the FILLMATRIX CALL routine with multidimensional numeric arrays.

The syntax of the FILLMATRIX CALL routine has the following form:

CALL FILLMATRIX (X, Y)

where

X

specifies an input numeric matrix.

Y

specifies the numeric value that will fill the matrix.

The following example shows how to use the FILLMATRIX CALL routine.

options pageno=1 nodate ls=80 ps=64;

proc fcmp;
   array mat1[3, 2] (0.3, -0.78, -0.82, 0.54, 1.74, 1.2);
   call fillmatrix(mat1, 99);
   put mat1=;
quit;

Output from the FILLMATRIX CALL Routine

                                The SAS System                                1

                               The FCMP Procedure

mat1[1, 1]=99 mat1[1, 2]=99 mat1[2, 1]=99 mat1[2, 2]=99 mat1[3, 1]=99
mat1[3, 2]=99

IDENTITY CALL Routine

The IDENTITY CALL routine converts the input matrix to an identity matrix. Diagonal element values of the matrix will be set to 1, and the rest of the values will be set to 0.

The syntax of the IDENTITY CALL routine has the following form:

CALL IDENTITY (X)

where

X

specifies an input matrix with dimensions m x m (that is, X[m, m]).

Note that the input matrix needs to be square.

The following example uses the IDENTITY CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,3] (0.3, -0.78, -0.82, 0.54, 1.74, 1.2,
                     -1.3, 0.25, 1.49); 
   call identity (mat1);
   put mat1=;
quit;

Output from the IDENTITY CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

mat1[1, 1]=1 mat1[1, 2]=0 mat1[1, 3]=0 mat1[2, 1]=0 mat1[2, 2]=1 mat1[2, 3]=0
mat1[3, 1]=0 mat1[3, 2]=0 mat1[3, 3]=1

INV CALL Routine

The INV CALL routine calculates a matrix that is the inverse of the provided input matrix that should be a square, non-singular matrix.

The syntax of the INV CALL routine has the following form:

CALL INV (X, Y)

where

X

specifies an input matrix with dimensions m x m (that is, X[m, m]).

Y

specifies an output matrix with dimensions m x m (that is, Y[m, m]).

such that

[equation]

where ' denotes inverse

[equation]

and I is the identity matrix.

Note that both the input and output matrices need to be square and have the same dimensions.

The following example uses the INV CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,3] (0.3, -0.78, -0.82, 0.54, 1.74,
                    1.2, -1.3, 0.25, 1.49);
   array result[3,3];
   call inv(mat1, result);
   put result=;
quit; 

Output from the INV CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=4.0460407887 result[1, 2]=1.6892917399 result[1, 3]=0.8661767509
result[2, 1]=-4.173108283 result[2, 2]=-1.092427483 result[2, 3]=-1.416802558
result[3, 1]=4.230288655 result[3, 2]=1.6571719011 result[3, 3]=1.6645841716

MULT CALL Routine

The MULT CALL routine calculates the multiplicative product of two input matrices. The syntax of the MULT CALL routine has the following form:

CALL MULT (X, Y, Z)

where

X

specifies an input matrix with dimensions m x n (that is, X[m, n]).

Y

specifies an input matrix with dimensions n x p (that is, Y[n, p]).

Z

specifies an output matrix with dimensions m x p (that is, Z[m, p]).

such that

[equation]

Note that the number of columns for the first input matrix needs to be the same as the number of rows for the second matrix. The calculated matrix is the last argument.

The following example uses the MULT CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[2,3] (0.3, -0.78, -0.82, 0.54, 1.74, 1.2);
   array mat2[3,2] (1, 0, 0, 1, 1, 0);
   array result[2,2];
   call mult(mat1, mat2, result);
   put result=;
quit; 

Output from the MULT CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=-0.52 result[1, 2]=-0.78 result[2, 1]=1.74 result[2, 2]=1.74

POWER CALL Routine

The POWER CALL routine raises a square matrix to a given scalar value. Large scalar values should be avoided because the POWER CALL routine's internal use of the matrix multiplication routine might cause numerical precision problems. If the scalar is not an integer, it is truncated to an integer. If the scalar is less than 0, then it is changed to 0. See the SAS/IML User's Guide for more information.

The syntax of the POWER CALL routine has the following form:

CALL POWER (X, a, Y)

where

X

specifies an input matrix with dimensions m x m (that is, X[m, m]).

a

specifies an integer scalar value (power).

Y

specifies an output matrix with dimensions m x m (that is, Y[m, m]).

such that

[equation]

Note that both input and output matrices need to be square and have the same dimensions.

The following example uses the POWER CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,3] (0.3, -0.78, -0.82, 0.54, 1.74,
                    1.2, -1.3, 0.25, 1.49);
   array result[3,3];
   call power (mat1, 3, result);
   put result=;
quit;

Output from the POWER CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=2.375432 result[1, 2]=-4.299482 result[1, 3]=-6.339638
result[2, 1]=-3.031224 result[2, 2]=6.272988 result[2, 3]=8.979036
result[3, 1]=-4.33592 result[3, 2]=5.775695 result[3, 3]=9.326529

SUBTRACTMATRIX CALL Routine

The SUBTRACTMATRIX CALL routine performs an element-wide subtraction of two matrices or a matrix and a scalar.

The syntax of the SUBTRACTMATRIX CALL routine has the following form:

CALL SUBTRACTMATRIX (X, Y, Z)

where

X

specifies an input matrix with dimensions m x n (that is, X[m, n]) or a scalar.

Y

specifies an input matrix with dimensions m x n (that is, Y[m, n]) or a scalar.

Z

specifies an output matrix with dimensions m x n (that is, Z[m, n]).

such that

[equation]

Note that all input and output matrices need to have the same dimensions.

The following example uses the SUBTRACTMATRIX CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,2] (0.3, -0.78, -0.82, 0.54, 1.74, 1.2);
   array mat2[3,2] (0.2, 0.38, -0.12, 0.98, 2, 5.2);
   array result[3,2];
   call subtractmatrix (mat1, mat2, result);
   call subtractmatrix (2, mat1, result);
   put result=;
 quit;

Output from the SUBTRACTMATRIX CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=1.7 result[1, 2]=2.78 result[2, 1]=2.82 result[2, 2]=1.46
result[3, 1]=0.26 result[3, 2]=0.8

TRANSPOSE CALL Routine

The TRANSPOSE CALL routine returns the transpose of a matrix.

The syntax of the TRANSPOSE CALL routine has the following form:

CALL TRANSPOSE (X, Y)

where

X

specifies an input matrix with dimensions m x n (that is, X[m, n]).

Y

specifies an output matrix with dimensions n x m (that is, Y[n, m])

such that

[equation]

Note that the number of rows for the input matrix should be equal to the number of columns of the output matrix, and the number of rows for the output matrix should be equal to the number of columns of the input matrix.

The following example uses the TRANSPOSE CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,2] (0.3, -0.78, -0.82, 0.54, 1.74, 1.2);
   array result[2,3];
   call transpose (mat1, result);
   put result=;
quit;

Output from the TRANSPOSE CALL Routine

                                The SAS System                               1

                              The FCMP Procedure

result[1, 1]=0.3 result[1, 2]=-0.82 result[1, 3]=1.74 result[2, 1]=-0.78
result[2, 2]=0.54 result[2, 3]=1.2

ZEROMATRIX CALL Routine

The ZEROMATRIX CALL routine replaces all of the element values of the numeric input matrix with 0. You can use the ZEROMATRIX CALL routine with multi-dimensional numeric arrays.

The syntax of the ZEROMATRIX CALL routine has the following form:

CALL ZEROMATRIX (X)

where

X

specifies a numeric input matrix.

The following example uses the ZEROMATRIX CALL routine:

options pageno=1 nodate;

proc fcmp;
   array mat1[3,2]  (0.3, -0.78, -0.82, 0.54, 1.74, 1.2);
   call zeromatrix (mat1);
   put mat1=;
quit;

Output from the ZEROMATRIX CALL Routine

                                 The SAS System                                1

                               The FCMP Procedure

mat1[1, 1]=0 mat1[1, 2]=0 mat1[2, 1]=0 mat1[2, 2]=0 mat1[3, 1]=0 mat1[3, 2]=0

Previous Page | Next Page | Top of Page