[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

5. Data

Entities are the basic objects (constants and variables) in Algae. They contain members and elements. Members contain information about the entity, such as the number of rows in a matrix. An entity's elements, if it has any, contain the data such as the value of a scalar. There are five classes:

The `scalar' data structure contains a single element, its value, which may have any of the data types described above. Its members are:

The string `"scalar"'.

The type (like `"integer"' or `"real"').

Notice that a scalar is not the same as a one-element vector or matrix.

The `vector' entity contains a one-dimensional array of elements. Its members are:

The string `"vector"'.

The type (like `"integer"' or `"real"').

Either `"dense"' or `"sparse"'.

The number of elements.

The number of non-zero elements.

The element labels.

The element labels of a vector are themselves a vector.

The `matrix' data structure contains two-dimensional arrays of elements. It contains zero or more rows and columns. The members of a matrix are:

The string `"matrix"'.

The type (like `"integer"' or `"real"').

One of `"general"', `"symmetric"', or `"hermitian"'.

One of `"dense"', `"sparse"' or `"sparse_upper"'.

The number of rows.

The number of columns.

The number of nonzero elements. For matrices with "sparse_upper" density, this number does not include the elements on the diagonal, all of which are stored. Sorry.

The row labels.

The column labels.

The row and column labels of a matrix are vectors. The row label vector has the same number of elements as its matrix has rows, and likewise for the column label.

The `table' object is like a bucket that can contain any number of other objects.

Several functions return tables. For example, the eig function returns a table that contains the matrices values and vectors.

The entities contained in a table are members of it, so they can be extracted using the . operator. Thus eig(A).values returns the eigenvalues of `A'.

Functions are entities just like scalars and matrices, and can be operated on in the same manner. Functions have two members: `class', which is "function", and `ilk', which is either "user" or "builtin".

The scalar, vector, and matrix classes are known collectively as arrays. These are the only classes that contain elements, and all have the member type that specifies the data type. There are four types:

On most machines this is a 32-bit integer, like 42 or -273.

This is a floating point number like 3.1415. It is stored in 64 bits on most machines.

This is a complex number having both real and imaginary parts.

This is a character string like `"Hello"'.

Scalar constants are specified in a manner similar to that used in other programming languages. Numeric constants can be given in decimal form, such as `32' or `32.0', or in scientific notation, such as `3.2E1'. In the latter notation, the letters `e' and `E' may be used interchangeably to prefix the exponent. White space (space, tab, etc.) is significant in that context, of course, so that `1.2e+3' (1200.0) is definitely not the same as `1.2e +3' (4.2).

A `character' constant is a sequence of one or more characters surrounded by matching double-quotes. Within the quotes, the backslash character may be used to introduce "escape sequences" for unusual characters like newline. For example, the string `"\""' is a string containing a single character (the right double-quote). The following escape sequences may be used:

carriage return
vertical tab
octal number
hexadecimal number

The escape sequence \ooo consists of a backslash followed by one, two, or three octal digits, which are taken to specify the value of the desired character. For example, \33 is the ASCII "escape" character (which is also given by \e). Likewise, the sequence \xhh consists of a backslash followed by `x', followed by one or two hexadecimal digits, which specify the value of the desired character. For example, \x1b also specifies the ASCII "escape" character.

If the character following the backslash is not one of those specified above, then that character is taken literally. For example, \" specifies the double-quote character--not the end of the character constant.

Matrices may be generated by specifying their elements within brackets. Commas separate elements within rows and semicolons separate the rows. Thus [1,2;3,4] specifies the matrix

[ 1  2 ]
[ 3  4 ]

A vector may be generated by using either of the forms `i:j' or `i:j:k'. It is obtained by starting with the value `i' and incrementing by `k' (or 1 if the first form is used) while remaining between `i' and `j', inclusive. (Notice that this is not the same format used by MATLAB.) For example, [1:8:2] is the same as [1,3,5,7]. All elements within a matrix have the same type (`integer', `real', etc.); conversion will be performed automatically if possible.

The terms within the brackets may be constants, variables, or expressions. For example, [1+2,3] is the same as [3,3]. Matrices may be involved, as long as their dimensions are appropriate. For example, if the variable `A' is defined to be equal to the square matrix `[1,2;3,4]', then a new column could be appended to it with the expression [A,[5;6]] to yield

[ 1  2  5 ]
[ 3  4  6 ]

Matrices may be partitioned by specifying the desired row and column numbers within brackets. For example, if `A' is a previously defined matrix then A[1;1] specifies a scalar having the value of the element in the first row and the first column of `A'. The semicolon within the parentheses separates the row specifiers from the column specifiers.

Members of data structures are referred to by using the member operator `.'. For example, the number of rows in a matrix is stored in the member nr, so A.nr returns the number of rows in the matrix A. The member operator associates left to right, so that A.type.type returns the string "character".

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by K. Scott Hunziker on February, 22 2004 using texi2html