RATS 11.1
RATS 11.1

Functions /

Matrix Functions

Home Page

← Previous Next →

Below is an is an alphabetical list of the matrix functions available. It's a rather long list, so we have a set of smaller lists by topic:

 

Commonly Used Functions

Size Functions

Reshaping Functions

Matrix Creation Functions

Element-wise Functions

Scalar Functions of Arrays

Specialized Products

Decompositions/Factorizations

Sort/Rank Functions

Extraction and Related Functions

Sparse and Packed Matrix Functions

Full List

 

%abs(A)

Elementwise absolute value of a matrix

%avg(A)

Average of values

%blockdiag(VR)

Creates a block diagonal matrix from VECT[RECTANG]

%blockglue(G)

Concatenation of matrices

%blocksplit(A,I)

Partitioning of matrix

%bqfactor(S,LS)

Blanchard-Quah factorization

%chol(S)

Cholesky factor

%cols(A)

Number of columns of a matrix

%compress(A,v)

Compress out rows of A where elements of V are zero

%const(x)

Fill matrix with a constant value

%corr(A,B)

Correlation coefficient

%corrtocv(C,V)

Convert correlation matrix to covariance matrix

cos(A)

Cosine of each member of A

%cov(A,B)

Covariance of two arrays

%cvtocorr(V)

Converts a covariance matrix to correlations

%cxadj(z)

Complex matrix adjoint (conjugate transpose)

%cxdiag(cv)

Complex diagonal from a complex vector or 1xN rectangular

%cxeigdecomp(z)

Complex Eigen decomposition

%cxinv(z)

Complex matrix inverse

%cxsvd(Z)

Complex singular value decomposition

%ddivide(A,v)

Divides columns of A by corresponding elements in vector v

%decomp(A)

Cholesky decomposition

%det(A)

Determinant of an array

%diag(A)

Diagonal matrix from a 1-dimensional array

%dims(A)

Dimensions (# of rows and columns) of an array

%dlmgfroma(A)

Creates a matrix which transforms to stationarity a state-space model

%dlminit(A,SW,F,Z)

Full solution for initial conditions for a state space model

%dmult(A,v)

Multiplies columns of A by elements in vector v

%dnn(N)

Duplication matrix operator (for symmetric to full size)

%dnninv(N)

(General) inverse duplication matrix operator

%dot(A,B)

Dot product of two arrays

%eigdecomp(S)

Eigen decomposition of symmetric array

%exp(x)

Elementwise exponentiation function

%fill(r,c,v)

Create matrix filled with a single value

%fractiles(A,F)

Fractiles of an array

%ginv(A)

Generalized inverse of a matrix

%girfmatrix(S)

Matrix required for generalized impulse responses

%gsortho(A)

Gram-Schmidt orthonormalization

%identity(size)

Create identity matrix

%index(V)

Sorting index for a vector

%innerxx(A)

Matrix Inner cross product

inv(A)

Inverse of a matrix

%knn(N)

Connector (transposition) operator matrix

%kroneker(A,B)

Kroneker product of two arrays

%kronid(A,B)

Kroneker product with identity, post multiplied

%kronmult(A,B,C)

Kroneker product, post multiplied

%lnn(N)

Elimination matrix operator (rectangular to symmetric)

%lnnx(N)

Elimination matrix operation (rectangular to below diagonal)

%log(A)

Elementwise natural log function

%logdetxx(s)

Returns the log determinant of a symmetric matrix

%ltinv(L)

Inverse of packed triangular matrix

%ltouterxx(A)

Outer matrix product of packed triangular matrix

%matpeek(A,coords)

Extracting entries from a sparse matrix

%matpoke(A,coords,v)

Filling entries in a sparse matrix

%maxindex(A)

Location of maximum value of an array

%maxvalue(A)

Get maximum value of an array

%minindex(A)

Location of minimum value of an array

%minus(A)

Returns a matrix with negative values of A

%minvalue(A)

Get minimum value of an array

%mqform(A,B)

Matrix quadratic form operation

%mqformdiag(A,B)

Diagonal of matrix quadratic form

%mscalar(x)

Create a scalar matrix

%mspexpand(P)

Markov switching transition probability transform

%mspreduce(P)

Markov switching transition probability transform

%normsqr(A)

Sum of the squared elements of a matrix or vector

%nullspace(A)

Column null space

%ones(rows,cols)

Creates a matrix with all elements equal to one

%outerxx(A)

Matrix outer cross product

%parmspeek(P)

Extract parameters from a PARMSET

%parmspoke(P,v)

Put vector into a PARMSET

%patchmat(A,B)

Replaces NA’s in A with entries from B

%patchzero(A)

Replaces NA’s in A with zeros

%perp(A)

Returns a matrix forming basis for null space of A

%plus(A)

Returns a matrix with positive values of A

%psddiag(A,B)

Diagonalizer matrix for a symmetric

%psdfactor(A,I)

General Cholesky factorization

%psdinit(A,W)

Stationary solution for initializing state space model

%psubmat(A,r,c,B)

Copy values from one array into another

%psubvec(VA,p,VB)

Copy values from one vector into another

%pt(v,t,x)

Puts information from an array into an array of series

%qform(A,B)

Quadratic form

%qformd(A,B)

Diagonal quadratic form

%qforminv(S,V)

Quadratic form using an inverted matrix.

%qrdecomp(A)

QR decomposition

%ran(x)

Random normal draw

%ranks(A)

Ranks the elements of a matrix

%ranmat(m,n)

Rectangular of random normal draws

%ranmvnormal(F)

Random multivariate normal draw

%ranmvt(f,nu)

Returns a random draw from a multivariate t distribution

%ransphere(n)

Random draw on unit sphere

%ranwishart(n,r)

Random Wishart matrix

%ranwishartf(F,r)

Random Wishart given a covariance matrix

%ranwisharti(F,r)

Random inverse Wishart matrix

%reshape(A,rows,cols)

Reshapes matrix to different dimensions

%rows(A)

Number of rows in a matrix

%rsscmom(C,B)

Residual sum of squares from cross-product matrix

%scalar(A)

First element of a matrix

%seqa(start,incr,n)

Creates a sequence of real numbers

%seqrange(lower,upper,n)

Creates a sequence of real numbers

%sigmacmom(C,B)

Sum of squared multivariate error matrix from CMOM

sin(A)

Sin of each member of A

%size(A)

Size (number of elements) of an array

%skewnn(N)

Skew-symmetric matrix operator

%solve(A,B)

Solve linear equations

%sort(A)

Sorts an array

%sortc(A,c)

Sorts an array based on the values in a column

%sortcl(A,list)

Sorts an array based on values in multiple columns

%sqrt(A)

Elementwise square root

%stereo(V)

Stereo projection

%sum(A)

Sum of array elements

%sumc(A)

Sum columns to create vector

%sumr(A)

Sum rows to create vector

%svdecomp(A)

Singular value decomposition

%sweep(A,k)

Sweep function of a matrix

%sweeplist(A,list)

Sweep function over a list of pivots

%sweeptop(A,k)

Sweep function over pivots in top rows

%symmcol(n)

Returns column number for packed position n

%symmpos(r,c)

Returns position in “packed” symmetric of element (r,c)

%symmrow(r)

Returns row number for packed position n

tan(A)

Tangent of each member of A

%testdiff(base,test)

Test difference of two arrays

tr(A)

Transpose of a matrix

%trace(A)

Trace of a matrix

%unitv(n,i)

Creates unit vector

%valid(A)

Returns 1 if and only if all members of A are valid (not missing)

%vec(A)

Vectorizes an array

%vech(A)

Vectorizes a SYMMETRIC array

%vectorect(V,r)

Reshapes Vector to Rectangular

%vectosymm(V,r)

Reshapes Vector to Symmetric

%wfractiles(A,W,F)

Weighted fractiles

%xcol(A,i)

Extract column of a matrix

%xdiag(A)

Extract diagonal from a matrix

%xrow(A,i)

Extracts row of a matrix

%xsubmat(A,m,n,o,p)

Extracts a rectangular block from a matrix

%xsubvec(V,sr,er)

Extracts a block from a vector

%xt(v,t)

Extracts information from an array of series

%zeros(rows,cols)

Returns a matrix of zeros


 

Commonly Used Functions

%chol(S)

Cholesky factor

%cols(A)

Number of columns of a matrix

%decomp(A)

Cholesky decomposition

%fill(r,c,v)

Create matrix filled with a single value

%identity(size)

Create identity matrix

inv(A)

Inverse of a matrix

%ran(x)

Random normal draw

%ranmat(m,n)

Rectangular of random normal draws

%rows(A)

Number of rows in a matrix

%solve(A,B)

Solve linear equations

tr(A)

Transpose of a matrix

%unitv(n,i)

Creates unit vector

%zeros(rows,cols)

Returns a matrix of zeros

 

Size Functions (apply to any type of array)

%cols(A)

Number of columns of a matrix

%dims(A)

Dimensions (# of rows and columns) of an array

%rows(A)

Number of rows in a matrix

%size(A)

Size (number of elements) of an array


 

Reshaping Functions

%blockdiag(VR)

Creates a block diagonal matrix from VECT[RECTANG]

%blockglue(G)

Concatenation of matrices

%blocksplit(A,I)

Partitioning of matrix

%diag(A)

Diagonal matrix from a 1-dimensional array

%dnn(N)

Duplication matrix operator (for symmetric to full size)

%dnninv(N)

(General) inverse duplication matrix operator

%knn(N)

Connector (transposition) operator matrix

%lnn(N)

Elimination matrix operator (rectangular to symmetric)

%lnnx(N)

Elimination matrix operation (rectangular to below diagonal)

%reshape(A,rows,cols)

Reshapes matrix to different dimensions

%skewnn(N)

Skew-symmetric matrix operator

%symmcol(n)

Returns column number for packed position n

%symmpos(r,c)

Returns position in “packed” symmetric of element (r,c)

%symmrow(r)

Returns row number for packed position n

%vec(A)

Vectorizes an array

%vech(A)

Vectorizes a SYMMETRIC

%vectorect(V,r)

Reshapes Vector to Rectangular

%vectosymm(V,r)

Reshapes Vector to Symmetric

%xcol(A,i)

Extract column of a matrix

%xdiag(A)

Extract diagonal from a matrix

%xrow(A,i)

Extracts row of a matrix

%xsubmat(A,m,n,o,p)

Extracts a rectangular block from a matrix

%xsubvec(V,sr,er)

Extracts a block from a vector


 

Matrix Creation Functions

%const(x)

Fill matrix with a constant value

%fill(r,c,v)

Create matrix filled with a single value

%identity(size)

Create identity matrix

%mscalar(x)

Create a scalar matrix

%ones(rows,cols)

Creates a matrix with all elements equal to one

%ranmat(m,n)

Rectangular of random normal draws

%seqa(start,incr,n)

Creates a sequence of real numbers

%seqrange(lower,upper,n)

Creates a sequence of real numbers

%unitv(n,i)

Creates unit vector

%zeros(rows,cols)

Returns a matrix of zeros


 

Element-wise Functions

These are generally fine if an elementwise calculation is simple. However, you shouldn't generally do a string of these; if an element by element calculation is more complicated, use the EWISE instruction.


 

%abs(A)

Elementwise absolute value of a matrix

cos(A)

Cosine of each member of A

%exp(x)

Elementwise exponentiation function

%log(A)

Elementwise natural log function

%minus(A)

Returns a matrix with negative values of A

%patchmat(A,B)

Replaces NA’s in A with entries from B

%patchzero(A)

Replaces NA’s in A with zeros

%plus(A)

Returns a matrix with positive values of A

sin(A)

Sin of each member of A

%sqrt(A)

Elementwise square root

tan(A)

Tangent of each member of A


 

Scalar Functions of Arrays

%avg(A)

Average of values

%corr(A,B)

Correlation coefficient

%cov(A,B)

Covariance of two arrays

%det(A)

Determinant of an array

%dot(A,B)

Dot product of two arrays

%fractiles(A,F)

Fractiles of an array

%logdetxx(s)

Returns the log determinant of a symmetric matrix

%maxvalue(A)

Get maximum value of an array

%minvalue(A)

Get minimum value of an array

%normsqr(A)

Sum of the squared elements of a matrix or vector

%qform(A,B)

Quadratic form

%qformd(A,B)

Diagonal quadratic form

%qforminv(S,V)

Quadratic form using an inverted matrix.

%rsscmom(C,B)

Residual sum of squares from cross-product matrix

%scalar(A)

First element of a matrix

%sum(A)

Sum of array elements

%sumc(A)

Sum columns to create vector

%sumr(A)

Sum rows to create vector

%testdiff(base,test)

Test difference of two arrays

%trace(A)

Trace of a matrix

%valid(A)

Returns 1 if and only if all members of A are valid (not missing)

%wfractiles(A,W,F)

Weighted fractiles


 

Specialized Products

%ddivide(A,v)

Divides columns of A by corresponding elements in vector v

%dmult(A,v)

Multiplies columns of A by elements in vector v

%innerxx(A)

Matrix Inner cross product

%kroneker(A,B)

Kroneker product of two arrays

%kronid(A,B)

Kroneker product with identity, post multiplied

%kronmult(A,B,C)

Kroneker product, post multiplied

%ltouterxx(A)

Outer matrix product of packed triangular matrix

%mqform(A,B)

Matrix quadratic form operation

%mqformdiag(A,B)

Diagonal of matrix quadratic form

%outerxx(A)

Matrix outer cross product

%qform(A,B)

Quadratic form

%qformd(A,B)

Diagonal quadratic form

%qforminv(S,V)

Quadratic form using an inverted matrix.


 

Decompositions/Factorizations

The mathematics behind many of these is described in Matrix Decompositions.


 

%bqfactor(S,LS)

Blanchard-Quah factorization

%chol(S)

Cholesky factor

%cxeigdecomp(z)

Complex Eigen decomposition

%cxsvd(Z)

Complex singular value decomposition

%decomp(A)

Cholesky decomposition

%eigdecomp(S)

Eigen decomposition of symmetric array

%girfmatrix(S)

Matrix required for generalized impulse responses

%gsortho(A)

Gram-Schmidt orthonormalization

%perp(A)

Returns a matrix forming basis for null space of A

%psddiag(A,B)

Diagonalizer matrix for a symmetric

%psdfactor(A,I)

General Cholesky factorization

%qrdecomp(A)

QR decomposition

%svdecomp(A)

Singular value decomposition


 

Sort/Rank Functions

%fractiles(A,F)

Fractiles of an array

%index(V)

Sorting index for a vector

%maxindex(A)

Location of maximum value of an array

%maxvalue(A)

Get maximum value of an array

%minindex(A)

Location of minimum value of an array

%minvalue(A)

Get minimum value of an array

%ranks(A)

Ranks the elements of a matrix

%sort(A)

Sorts an array

%sortc(A,c)

Sorts an array based on the values in a column

%sortcl(A,list)

Sorts an array based on values in multiple columns

%wfractiles(A,W,F)

Weighted fractiles


 

Extraction and Related Functions

%compress(A,v)

Compress out rows of A where elements of V are zero

%matpeek(A,coords)

Extracting entries from a sparse matrix

%matpoke(A,coords,v)

Filling entries in a sparse matrix

%parmspeek(P)

Extract parameters from a PARMSET

%parmspoke(P,v)

Put vector into a PARMSET

%psubmat(A,r,c,B)

Copy values from one array into another

%psubvec(VA,p,VB)

Copy values from one vector into another

%pt(v,t,x)

Puts information from an array into an array of series

%sumc(A)

Sum columns to create vector

%sumr(A)

Sum rows to create vector

%xcol(A,i)

Extract column of a matrix

%xdiag(A)

Extract diagonal from a matrix

%xrow(A,i)

Extracts row of a matrix

%xsubmat(A,m,n,o,p)

Extracts a rectangular block from a matrix

%xsubvec(V,sr,er)

Extracts a block from a vector

%xt(v,t)

Extracts information from an array of series


 

Sparse and Packed Matrix Functions

%compress(A,v)

Compress out rows of A where elements of V are zero

%ltinv(L)

Inverse of packed triangular matrix

%ltouterxx(A)

Outer matrix product of packed triangular matrix

%matpeek(A,coords)

Extracting entries from a sparse matrix

%matpoke(A,coords,v)

Filling entries in a sparse matrix

%patchmat(A,B)

Replaces NA’s in A with entries from B

%patchzero(A)

Replaces NA’s in A with zeros


 


Copyright © 2026 Thomas A. Doan