Command Reference : Matrix Language : Matrix Expressions
  
Matrix Expressions
 
Matrix Operators
Negation (–)
Addition (+)
Subtraction (–)
Multiplication (*)
Division (/)
Relational Operators (=, >, >=, <, <=, <>)
A matrix expression is an expression which combines matrix objects with mathematical operators or relations, functions, and parentheses. While we discuss matrix functions in great detail below, some examples will demonstrate the relevant concepts.
Examples:
@inner(@convert(grp, s1))
mat1*vec1
@inverse(mat1+mat2)*vec1
mat1 > mat2
EViews uses the following rules to determine the order in which the expression will be evaluated:
You may nest any number of pairs of parentheses to clarify the order of operations in a matrix expression.
If you do not use parentheses, the operations are applied in the following order:
1. Unary negation operator and functions.
2. Multiplication and division operators.
3. Addition and subtraction operators.
4. Comparison operators: “>=”, “>”, “<=”, “<”, “<>”.
Examples:
@inverse(mat1+mat2)+@inverse(mat3+mat4)
vec1*@inverse(mat1+mat2)*@transpose(vec1)
In the first example, the matrices MAT1 and MAT2 will be added and then inverted. Similarly the matrices MAT3 and MAT4 are added and then inverted. Finally, the two inverses will be added together. In the second example, EViews first inverts MAT1+MAT2 and uses the result to calculate a quadratic form with VEC1.
Matrix Operators
EViews provides standard mathematical operators for matrix objects.
(Note that element multiplication, division, inverse, and powers are not available using operators, but are instead supported via functions).
Negation (–)
The unary minus changes the sign of every element of a matrix object, yielding a matrix or vector of the same dimension. Example:
matrix jneg = -jpos
Addition (+)
You can add two matrix objects of the same type and size. The result is a matrix object of the same type and size. Example:
matrix(3,4) a
matrix(3,4) b
matrix sum = a + b
You can add a square matrix and a sym of the same dimension. The upper triangle of the sym is taken to be equal to the lower triangle. Adding a scalar to a matrix object adds the scalar value to each element of the matrix or vector object.
Subtraction (–)
The rules for subtraction are the same as the rules for addition. Example:
matrix(3,4) a
matrix(3,4) b
matrix dif = a - b
Subtracting a scalar object from a matrix object subtracts the scalar value from every element of the matrix object.
Multiplication (*)
You can multiply two matrix objects if the number of columns of the first matrix is equal to the number of rows of the second matrix.
Example:
matrix(5,9) a
matrix(9,22) b
matrix prod = a * b
In this example, PROD will have 5 rows and 22 columns.
One or both of the matrix objects can be a sym. Note that the product of two sym objects is a matrix, not a sym. The @inner function will produce a sym by multiplying a matrix by its own transpose.
You can premultiply a matrix or a sym by a vector if the number of columns of the matrix is the same as the number of elements of the vector. The result is a vector whose dimension is equal to the number of rows of the matrix.
Example:
matrix(5,9) mat
vector(9) vec
vector res = mat * vec
In this example, RES will have 5 elements.
You can premultiply a rowvector by a matrix or a sym if the number of elements of the rowvector is the same as the number of rows of the matrix. The result is a rowvector whose dimension is equal to the number of columns of the matrix.
Example:
rowvector rres
matrix(5,9) mat
rowvector(5) row
rres = row * mat
In this example, RRES will have 9 elements.
You can multiply a matrix object by a scalar. Each element of the original matrix is multiplied by the scalar. The result is a matrix object of the same type and dimensions as the original matrix. The scalar can come before or after the matrix object. Examples:
matrix prod = 3.14159*orig
matrix xxx = d_mat*7
To perform element multiplication where you multiply every element of a matrix by very element of another matrix, you should use the @emult function.
Division (/)
You can divide a matrix object by a scalar. Example:
matrix z = orig/3
Each element of the object ORIG will be divided by 3.
To perform element division where you divide every element of a matrix by very element of another matrix, you should use the @ediv function.
Relational Operators (=, >, >=, <, <=, <>)
Two matrix objects of the same type and size may be compared using the comparison operators (=, >, >=, <, <=, <>). The result is a scalar logical value. Every pair of corresponding elements is tested, and if any pair fails the test, the value 0 (FALSE) is returned; otherwise, the value 1 (TRUE) is returned.
For example,
if result <> value then
run crect
endif
It is possible for a vector to be not greater than, not less than, and not equal to a second vector. For example:
vector(2) v1
vector(2) v2
v1(1) = 1
v1(2) = 2
v2(1) = 2
v2(2) = 1
Since the first element of V1 is smaller than the first element of V2, V1 is not greater than V2. Since the second element of V1 is larger than the second element of V2, V1 is not less than V2. The two vectors are not equal.