Creation and initialization of matrices

The built-in functions zeros, ones, rand, band, binary, sparse, upper, lower, and symm are used to generate vectors and matrices.

The function zeros returns vectors or matrices of zeros.

zeros(n) column matrix of zeros (double precision)
zeros(m, n) matrix of zeros (double precision)
zeros(n, domain) column matrix of zeros; storage type specified by domain
zeros(m, n, domain) column matrix of zeros; storage type specified by domain
zeros(m1, m2, m3, ...) multi-dimensional matrix of zeros (double precision)

The values of m, n, and m1, m2, m3, ... are positive integers. domain is one of the following built-in set functions

_Z machine integers
_L arbitrary size integers
_B bytes
_M arbitrary precision floating point numbers

The function ones and rand are similar to zeros; ones create matrices of 1's and rand creates matrices of random numbers.

The function rand has a public parameter range, which is a vector of two numbers. The rand function returns random numbers that are uniformly distributed between them.

For example, to create a matrix of random machine integers

x = rand(5, 1, _Z);
or
x = rand(5, _Z);
To create a matrix of arbitrary precision random floating point numbers
x = rand(5, 3, _M);

To change the parameter range of rand, use either

global.rand.range = [0, 10];  // alter the range parameter of rand
or
f = rand[[0, 10]];  // spawn a copy of rand with new range

The function sparse creates sparse matrices of double precision floating point numbers. sparse(m, n) return sparse matrix, and sparse(n) return sparse matrix (a row vector).

The function band creates banded square matrices of double precision floating point numbers. band(n, l, u) returns an banded matrix with with l sub-diagonals and u super-diagonals.

The functions upper, lower, and symm creates square upper triangular, lower triangular, and symmetric matrices respectively. The usage is upper(n), lower(n), symm(n), where n is the number of rows (and the number of columns) of the matrix.

Note that sparse, band, upper, lower, and symm all create matrices of zeros. The elements of these matrices can be altered using the normal assignment operations.

Note also that the matrices created by sparse and band use special storage schemes and may save on memory as well as make operations more efficient. Matrices created by upper, lower, and symm use the regular dense storage scheme. Although it is not memory efficient, some linear algebraic routines may still take advantage of the fact that the matrix is triangular or symmetric.

Binary scalars and matrices are created using function binary.

binary(n): column binary matrix of zeros
binary(m, n): byte binary matrix of zeros

linspace(a, b): create a row vector of 100 elements evenly spaced between a and b.

linspace(a, b, n): create a row vector of n elements evenly spaced between a and b.

oz 2009-12-22