SYNOPSIS
#include "matrix.h" MAT *m_ident(MAT *A) MAT *m_ones(MAT *A) VEC *v_ones(VEC *x) MAT *m_rand(MAT *A) VEC *v_rand(VEC *x) MAT *m_zero(MAT *A) VEC *v_zero(VEC *x) Real mrand() void smrand(int seed) void mrandlist(Real a[], int len)
#include "zmatrix.h" ZMAT *zm_rand(ZMAT *A) ZVEC *zv_rand(ZVEC *x) ZMAT *zm_zero(ZMAT *A) ZVEC *zv_zero(ZVEC *x)
DESCRIPTION
The routine m_ident() sets the matrix A to be the identity matrix. That is, the diagonal entries are set to~1, and the off-diagonal entries to~0. The routines m_ones(), v_ones() fill A and x with ones. The routines v_rand(), m_rand() and zv_rand(), zm_rand() fill A and x with random entries. For real vectors or matrices the entries are between zero and one as determined by the mrand() function. For complex vectors or matrices, the entries have both real and imaginary parts between zero and one as determined by the mrand() function. The routines m_zero(), v_zero() and zm_zero(), zv_zero() fill A and x with zeros. These routines will raise an E_NULL error if A is NULL. The routine mrand() returns a pseudo-random number in the range $[0,1)$ using an algorithm based on Knuth's lagged Fibonacci method in Seminumerical Algorithms: The Art of Computer Programming, vol.~2 \S\S3.2--3.3. The implementation is based on that in Numerical Recipes in C, pp.~212--213, \S7.1. Note that the seeds for mrand() are initialised using smrand() with a fixed seed. Thus mrand() will produce the same pseudo-random sequence (unless smrand() is called) in different runs, different programs, and but for differences in floating point systems, on different machines. The routine smrand() allows the user to re-set the seed values based on a user-specified seed. Thus mrand() can produce a wide variety of reproducible pseudo-random numbers. The routine mrandlist() fills an array with pseudo-random numbers using the same algorithm as mrand(), but is somewhat faster for reasonably long vectors.
EXAMPLE
Let $e=[1,1,\dots,1]^T$.
MAT *A; ZMAT *zA; VEC *x; ZVEC *zx; PERM *pi; ...... m_zero(A); /* A == zero matrix */ m_ident(A); /* A == identity matrix */ m_ones(A); /* A == e.e^T */ m_rand(A); /* A[i][j] is random in interval [0,1) */ zm_rand(zA);/* zA[i][j] is random in [0,1) x [0,1) */ v_zero(x); /* x == zero vector */ v_ones(x); /* x == e */ v_rand(x); /* x[i] is random in interval [0,1) */ zv_rand(zx);/* zx[i] is random in [0,1) x [0,1) */
BUGS
The routine m_ident() ``works'' even if A is not square. There is also the observation of von~Neumann, {\em Various techniques used in connection with random digits}, National Bureau of Standards (1951), p.~36: ``Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin.''
SOURCE FILE: init.c, matop.c, zmatop.c, zmemory.c,\newline zvecop.c