Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Eviews5 / EViews5 / Docs / EViews 5 Command Ref.pdf
Скачиваний:
47
Добавлен:
23.03.2015
Размер:
5.23 Mб
Скачать

Chapter 3. Matrix Language

EViews provides you with tools for working directly with data contained in matrices and vectors. You can use the EViews matrix language to perform calculations that are not available using the built-in views and procedures.

The following objects can be created and manipulated using the matrix command language:

coef: column vector of coefficients to be used by equation, system, pool, logl, and sspace objects

matrix: two-dimensional array

rowvector: row vector

scalar: scalar

sym: symmetric matrix (stored in lower triangular form)

vector: column vector

We term these objects matrix objects (despite the fact that some of these objects are not matrices).

Declaring Matrices

You must declare matrix objects prior to use. Detailed descriptions of declaration statements for the various matrix objects are provided in Appendix A, “Object, View and Procedure Reference”, on page 153.

Briefly, a declaration consists of the object keyword, followed either by size information in parentheses and the name to be given to the object, followed (optionally) by an assignment statement. If no assignment is provided, the object will be initialized to have all zero values.

The various matrix objects require different sizing information. A matrix requires the number of rows and the number of columns. A sym requires that you specify a single number representing both the number of rows and the number of columns. A vector, rowvector, or coef declaration can include information about the number of elements. A scalar requires no size information. If size information is not provided, EViews will assume that there is only one element in the object.

For example:

matrix(3,10) xdata

24—Chapter 3. Matrix Language

sym(9) moments vector(11) betas rowvector(5) xob

creates a 3 × 10 matrix XDATA, a symmetric 9 × 9 matrix MOMENTS, an 11 × 1 column vector BETAS, and a 1 × 5 rowvector XOB. All of these objects are initialized to zero.

To change the size of a matrix object, you can repeat the declaration statement. Furthermore, if you use an assignment statement with an existing matrix object, the target will be resized as necessary. For example:

sym(10) bigz

matrix zdata

matrix(10,2) zdata

zdata = bigz

will first declare ZDATA to be a matrix with a single element, and then redeclare ZDATA to be a 10 × 2 matrix. The assignment statement in the last line will resize ZDATA so that it contains the contents of the 10 × 10 symmetric matrix BIGZ.

Assigning Matrix Values

There are three ways to assign values to the elements of a matrix: you may assign values to specific matrix elements, you may fill the matrix using a list of values, or you may perform matrix assignment.

Element assignment

The most basic method of assigning matrix values is to assign a value for a specific row and column element of the matrix. Simply enter the matrix name, followed by the row and column indices, in parentheses, and then an assignment to a scalar value.

For example, suppose we declare the 2 × 2 matrix A:

matrix(2,2) a

The first command creates and initializes the 2 × 2 matrix A so that it contains all zeros. Then after entering the two commands:

a(1,1) = 1

a(2,1) = 4

we have

 

 

 

 

 

 

A =

1

0

.

(3.1)

 

4

0

 

 

 

 

 

 

 

 

Assigning Matrix Values—25

You can perform a large number of element assignments by placing them inside of programming loops:

vector(10) y matrix (10,10) x for !i = 1 to 10

y(!i) = !i

for !j = 1 to 10 x(!i,!j) = !i + !j

next next

Note that the fill procedure provides an alternative to using loops for assignment.

Fill assignment

The second assignment method is to use the fill procedure to assign a list of numbers to each element of the matrix in the specified order. By default, the procedure fills the matrix column by column, but you may override this behavior.

You should enter the name of the matrix object, followed by a period, the fill and then a comma delimited list of values. For example, the commands:

vector(3) v

v1.fill 0.1, 0.2, 0.3

matrix(2,4) x

matrix.fill 1, 2, 3, 4, 5, 6, 7, 8

create the matrix objects:

 

 

 

 

 

 

 

 

 

 

 

 

0.1

 

 

 

 

 

 

 

 

V =

,

X =

1

3

5

7

0.2

2

4

6

8

 

0.3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

keyword,

(3.2)

If we replace the last line with

matrix.fill(b=r) 1,2,3,4,5,6,7,8

then X is given by:

 

 

 

 

 

 

 

X =

1 2

3

4

.

(3.3)

 

5 6

7

8

 

 

 

 

 

 

 

 

 

26—Chapter 3. Matrix Language

In some situations, you may wish to repeat the assignment over a list of values. You may use the “l” option to fill the matrix by repeatedly looping through the listed numbers until the matrix elements are exhausted. Thus,

matrix(3,3) y

y.fill(l) 1, 0, -1

creates the matrix:

Y =

1

1

1

 

 

0

0

0

 

(3.4)

 

 

 

 

−1 −1 −1

 

 

 

 

 

 

 

See fill (p. 293) for a complete description of the fill procedure.

Matrix assignment

You can copy data from one matrix object into another using assignment statements. To perform an assignment, you should enter the name of the target matrix followed by the equal sign “=”, and then a matrix object expression. The expression on the right-hand side should either be a numerical constant, a matrix object, or an expression that returns a matrix object.

There are a variety of rules for how EViews performs the assignment that depend upon the types of objects involved in the assignment.

Scalar values on the right-hand side

If there is a scalar on the right-hand side of the assignment, every element of the matrix object is assigned the value of the scalar.

Examples:

matrix(5,8) first

scalar second

vec(10) third

first = 5

second = c(2)

third = first(3,5)

Since declaration statements allow for initialization, you can combine the declaration and assignment statements. Examples:

matrix(5,8) first = 5

scalar second = c(2)

vec(10) third = first(3,5)

Соседние файлы в папке Docs