Work on documentation matrix3
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 9 Oct 2021 06:19:37 +0000 (23:19 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 9 Oct 2021 06:19:37 +0000 (23:19 -0700)
doc/matrices.texi

index 8adf29b035f862e16bd80dc2e02566456e9922e3..83eccb8d62a7edde2361e2adbb3addb04d31b97c 100644 (file)
@@ -1123,18 +1123,18 @@ The following subsections document each of the currently supported
 functions.  The first letter of each parameter's name indicate the
 required argument type:
 
-@table @samp
+@table @var
 @item s
-Any scalar.
+A scalar.
 
 @item n
-A scalar with a nonnegative integer value.  (Non-integers are rounded
-down to the nearest integer.)
+A nonnegative integer scalar.  (Non-integers are accepted and silently
+rounded down to the nearest integer.)
 
-@item v
+@item V
 A row or column vector.
 
-@item m
+@item M
 A matrix.
 @end table
 
@@ -1145,258 +1145,305 @@ These functions act on each element of their argument independently,
 like the elementwise operators (@pxref{Matrix Elementwise Binary
 Operators}).
 
-@deftypefn {Matrix Function} {} ABS (@var{m})
-Takes the absolute value of each element of @var{m}.
+@deffn {Matrix Function} ABS (@var{M})
+Takes the absolute value of each element of @var{M}.
 
 @t{ABS(@{-1, 2; -3, 0@}) @result{} @{1, 2; 3, 0@}}
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} ARSIN (@var{m})
-@deftypefnx {Matrix Function} {} ARTAN (@var{m})
+@deffn {Matrix Function} ARSIN (@var{M})
+@deffnx {Matrix Function} ARTAN (@var{M})
 Computes the inverse sine or tangent, respectively, of each element in
-@var{m}.  The results are in radians, between @math{-\pi/2} and
+@var{M}.  The results are in radians, between @math{-\pi/2} and
 @math{+\pi/2}, inclusive.
-@end deftypefn
 
-@deftypefn {Matrix Function} {} COS (@var{m})
-@deftypefnx {Matrix Function} {} SIN (@var{m})
-Computes the cosine or sine, respectively, of each element in @var{m},
+The value of @math{\pi} can be computed as @code{4*ARTAN(1)}.
+@end deffn
+
+@deffn {Matrix Function} COS (@var{M})
+@deffnx {Matrix Function} SIN (@var{M})
+Computes the cosine or sine, respectively, of each element in @var{M},
 which must be in radians.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} EXP (@var{m})
-Computes @math{e^x} for each element @var{x} in @var{m}.
-@end deftypefn
+@deffn {Matrix Function} EXP (@var{M})
+Computes @math{e^x} for each element @var{x} in @var{M}.
+@end deffn
 
-@deftypefn {Matrix Function} {} LG10 (@var{m})
-@deftypefnx {Matrix Function} {} LN (@var{m})
+@deffn {Matrix Function} LG10 (@var{M})
+@deffnx {Matrix Function} LN (@var{M})
 Takes the logarithm with base 10 or base @math{e}, respectively, of
-each element in @var{m}.
-@end deftypefn
+each element in @var{M}.
+@end deffn
 
-@deftypefn {Matrix Function} {} MOD (@var{m}, @var{s})
-Takes each element in @var{m} modulo nonzero scalar value @var{s},
+@deffn {Matrix Function} MOD (@var{M}, @var{s})
+Takes each element in @var{M} modulo nonzero scalar value @var{s},
 that is, the remainder of division by @var{s}.  The sign of the result
 is the same as the sign of the dividend.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} RND (@var{m})
-@deftypefnx {Matrix Function} {} TRUNC (@var{m})
-Rounds each element of @var{m} to an integer.  @code{RND} rounds to
+@deffn {Matrix Function} RND (@var{M})
+@deffnx {Matrix Function} TRUNC (@var{M})
+Rounds each element of @var{M} to an integer.  @code{RND} rounds to
 the nearest integer, with halves rounded to even integers, and
 @code{TRUNC} rounds toward zero.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} SQRT (@var{m})
-Takes the square root of each element of @var{m}, which must not be
+@deffn {Matrix Function} SQRT (@var{M})
+Takes the square root of each element of @var{M}, which must not be
 negative.
-@end deftypefn
+@end deffn
 
 @node Matrix Logical Functions
 @subsubsection Logical Functions
 
-@deftypefn {Matrix Function} {} ALL (@var{m})
-Returns a scalar with value 1 if all of the elements in @var{m} are
+@deffn {Matrix Function} ALL (@var{M})
+Returns a scalar with value 1 if all of the elements in @var{M} are
 nonzero, or 0 if at least one element is zero.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} ANY (@var{m})
-Returns a scalar with value 1 if any of the elements in @var{m} is
+@deffn {Matrix Function} ANY (@var{M})
+Returns a scalar with value 1 if any of the elements in @var{M} is
 nonzero, or 0 if all of them are zero.
-@end deftypefn
+@end deffn
 
 @node Matrix Construction Functions
 @subsubsection Matrix Construction Functions
 
-@deftypefn {Matrix Function} {} BLOCK (@var{m1}, @dots{}, @var{mn})
+@deffn {Matrix Function} BLOCK (@var{M1}, @dots{}, @var{Mn})
 Returns a block diagonal matrix with as many rows as the sum of its
 arguments' row counts and as many columns as the sum of their columns.
 Each argument matrix is placed along the main diagonal of the result,
 and all other elements are zero.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} IDENT (@var{n})
-@deftypefnx {Matrix Function} {} IDENT (@var{nr}, @var{nc})
+@deffn {Matrix Function} IDENT (@var{n})
+@deffnx {Matrix Function} IDENT (@var{nr}, @var{nc})
 Returns an identity matrix, whose main diagonal elements are one and
 whose other elements are zero.  The returned matrix has @var{n} rows
 and columns or @var{nr} rows and @var{nc} columns, respectively.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} MAGIC (@var{n})
+@deffn {Matrix Function} MAGIC (@var{n})
 Returns an @math{@var{n}@times{}@var{n}} matrix that contains each of
 the integers @math{1@dots{}@var{n}} once, in which each column, each
 row, and each diagonal sums to @math{n(n^2+1)/2}.  There are many
 magic squares with given dimensions, but this function always returns
 the same one for a given value of @var{n}.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} MAKE (@var{nr}, @var{nc}, @var{s})
+@deffn {Matrix Function} MAKE (@var{nr}, @var{nc}, @var{s})
 Returns an @math{@var{nr}@times{}@var{nc}} matrix whose elements are
 all @var{s}.
-@end deftypefn
+@end deffn
 
-@deftypefn {Matrix Function} {} MDIAG (@var{v})
-Returns a @math{|@var{v}|@times{}|@var{v}|} matrix whose main diagonal
-comes from @var{v} and whose other elements are zero.
-@end deftypefn
+@deffn {Matrix Function} MDIAG (@var{V})
+Returns a @math{|@var{V}|@times{}|@var{V}|} matrix whose main diagonal
+comes from @var{V} and whose other elements are zero.
+@end deffn
 
-@deftypefn {Matrix Function} {} RESHAPE (@var{m}, @var{nr}, @var{nc})
+@deffn {Matrix Function} RESHAPE (@var{M}, @var{nr}, @var{nc})
 Returns an @math{@var{nr}@times{}@var{nc}} matrix whose elements come
-from @var{m}, which must have the same number of elements as the new
-matrix, copying elements from @var{m} to the new matrix row by row.
-@end deftypefn
+from @var{M}, which must have the same number of elements as the new
+matrix, copying elements from @var{M} to the new matrix row by row.
+@end deffn
 
-@deftypefn {Matrix Function} {} T (@var{m})
-@deftypefnx {Matrix Function} {} TRANSPOS (@var{m})
-Returns @var{m} with rows exchanged for columns.
-@end deftypefn
+@deffn {Matrix Function} T (@var{M})
+@deffnx {Matrix Function} TRANSPOS (@var{M})
+Returns @var{M} with rows exchanged for columns.
+@end deffn
 
-@deftypefn {Matrix Function} {} UNIFORM (@var{nr}, @var{nc})
+@deffn {Matrix Function} UNIFORM (@var{nr}, @var{nc})
 Returns a @math{@var{nr}@times{}@var{nc}} matrix in which each element
 is randomly chosen from a uniform distribution of real numbers between
 0 and 1.
-@end deftypefn
+@end deffn
 
 @node Matrix Minimum and Maximum and Sum Functions
 @subsubsection Minimum, Maximum, and Sum Functions
 
-@deftypefn {Matrix Function} {} CMIN (@var{m})
-@deftypefnx {Matrix Function} {} CMAX (@var{m})
-@deftypefnx {Matrix Function} {} CSUM (@var{m})
-@deftypefnx {Matrix Function} {} CSSQ (@var{m})
-Returns a row vector with the same number of columns as @var{m}, in
+@deffn {Matrix Function} CMIN (@var{M})
+@deffnx {Matrix Function} CMAX (@var{M})
+@deffnx {Matrix Function} CSUM (@var{M})
+@deffnx {Matrix Function} CSSQ (@var{M})
+Returns a row vector with the same number of columns as @var{M}, in
 which each element is the minimum, maximum, sum, or sum of squares,
-respectively, of the elements in the same column of @var{m}.
-@end deftypefn
+respectively, of the elements in the same column of @var{M}.
+@end deffn
 
-@deftypefn {Matrix Function} {} MMIN (@var{m})
-@deftypefnx {Matrix Function} {} MMAX (@var{m})
-@deftypefnx {Matrix Function} {} MSUM (@var{m})
-@deftypefnx {Matrix Function} {} MSSQ (@var{m})
+@deffn {Matrix Function} MMIN (@var{M})
+@deffnx {Matrix Function} MMAX (@var{M})
+@deffnx {Matrix Function} MSUM (@var{M})
+@deffnx {Matrix Function} MSSQ (@var{M})
 Returns the minimum, maximum, sum, or sum of squares, respectively, of
-the elements of @var{m}.
-@end deftypefn
-
-@deftypefn {Matrix Function} {} RMIN (@var{m})
-@deftypefnx {Matrix Function} {} RMAX (@var{m})
-@deftypefnx {Matrix Function} {} RSUM (@var{m})
-@deftypefnx {Matrix Function} {} RSSQ (@var{m})
-Returns a column vector with the same number of rows as @var{m}, in
+the elements of @var{M}.
+@end deffn
+
+@deffn {Matrix Function} RMIN (@var{M})
+@deffnx {Matrix Function} RMAX (@var{M})
+@deffnx {Matrix Function} RSUM (@var{M})
+@deffnx {Matrix Function} RSSQ (@var{M})
+Returns a column vector with the same number of rows as @var{M}, in
 which each element is the minimum, maximum, sum, or sum of squares,
-respectively, of the elements in the same row of @var{m}.
-@end deftypefn
+respectively, of the elements in the same row of @var{M}.
+@end deffn
 
-@deftypefn {Matrix Function} {} SSCP (@var{m})
-Returns @code{T(@var{m}) * @var{m}}.
-@end deftypefn
+@deffn {Matrix Function} SSCP (@var{M})
+Returns @math{@var{M}^T @times{} @var{M}}.
+@end deffn
 
-@deftypefn {Matrix Function} {} TRACE (@var{m})
-Returns the sum of the elements along @var{m}'s main diagonal,
-equivalent to @code{MSUM(DIAG(@var{m}))}.
-@end deftypefn
+@deffn {Matrix Function} TRACE (@var{M})
+Returns the sum of the elements along @var{M}'s main diagonal,
+equivalent to @code{MSUM(DIAG(@var{M}))}.
+@end deffn
 
 
 @node Matrix Property Functions
 @subsubsection Matrix Property Functions
 
-@deftypefn {Matrix Function} {} NROW (@var{m})
-@deftypefnx {Matrix Function} {} NCOL (@var{m})
-Returns the number of row or columns, respectively, in @var{m}.
-@end deftypefn
+@deffn {Matrix Function} NROW (@var{M})
+@deffnx {Matrix Function} NCOL (@var{M})
+Returns the number of row or columns, respectively, in @var{M}.
+@end deffn
 
-@deftypefn {Matrix Function} {} DIAG (@var{m})
-Returns a column vector containing a copy of @var{m}'s main diagonal.
-The vector's length is the lesser of @code{NCOL(@var{m})} and
-@code{NROW(@var{m})}.
-@end deftypefn
+@deffn {Matrix Function} DIAG (@var{M})
+Returns a column vector containing a copy of @var{M}'s main diagonal.
+The vector's length is the lesser of @code{NCOL(@var{M})} and
+@code{NROW(@var{M})}.
+@end deffn
 
 @node Matrix Rank Ordering Functions
 @subsubsection Matrix Rank Ordering Functions
 
-@deftypefn {Matrix Function} {} GRADE (@var{m})
-Returns a matrix with the same dimensions as @var{m} in which each
-elements is a unique integer, from 1 to the number of elements in
-@var{m}, that corresponds to its rank within @var{m}.  The smallest
-element in @var{m} corresponds to value 1 in the returned matrix, the
-next smallest to value 2, and so on.  When multiple elements in
-@var{m} have the same value, they are assigned consecutive unique
-ranks in the return matrix.
-@end deftypefn
+The @code{GRADE} and @code{RANK} functions each take a matrix @var{M}
+and return a matrix @var{r} with the same dimensions.  Each element in
+@var{r} ranges between 1 and the number of elements @var{n} in
+@var{M}, inclusive.  When the elements in @var{M} all have unique
+values, both of these functions yield the same results: the smallest
+element in @var{M} corresponds to value 1 in @var{r}, the next
+smallest to 2, and so on, up to the largest to @var{n}.  When multiple
+elements in @var{M} have the same value, these functions use different
+rules for handling the ties.
 
-@noindent
-The @code{GRADE} function can be used to sort a vector.  For example,
-the following syntax:
+@deffn {Matrix Function} GRADE (@var{M})
+Returns a ranking of @var{M}, turning duplicate values into sequential
+ranks.  The returned matrix always contains each of the integers 1
+through the number of elements in the matrix exactly once.
 
-@example
-MATRIX.
-COMPUTE v=@{2, 5, 1, 4, 9, 7, 8, 10, 6, 3@}.
-COMPUTE v(GRADE(v))=v.
-PRINT v.
-END MATRIX.
-@end example
+@t{GRADE(@{1, 0, 3; 3, 1, 2; 3, 0, 5@})} @result{} @t{@{3, 1, 6; 7, 4, 5; 8, 2, 9@}}
+@end deffn
+
+@deffn {Matrix Function} RNKORDER (@var{M})
+Returns a ranking of @var{M}, turning duplicate values into the mean
+of their sequential ranks.
 
-@noindent yields the following sorted output:
+@t{RNKORDER(@{1, 0, 3; 3, 1, 2; 3, 0, 5@})} @*@w{ }@result{} @t{@{3.5, 1.5, 7; 7, 3.5, 5; 7, 1.5, 9@}}
+@end deffn
+
+@noindent
+One may use @code{GRADE} to sort a vector:
 
 @example
-v
-   1   2   3   4   5   6   7   8   9  10
+COMPUTE v(GRADE(v))=v.   /* Sort v in ascending order.
+COMPUTE v(GRADE(-v))=v.  /* Sort v in descending order.
 @end example
 
-@deftypefn {Matrix Function} {} RNKORDER (@var{m})
-@end deftypefn
-
 @node Matrix Algebra Functions
 @subsubsection Matrix Algebra Functions
 
-@deftypefn {Matrix Function} {} CHOL (@var{m})
-@end deftypefn
+@deffn {Matrix Function} CHOL (@var{M})
+Matrix @var{M} must be an @math{@var{n}@times{}@var{n}} symmetric
+positive-definite matrix.  Returns an @math{@var{n}@times{}@var{n}}
+matrix @var{B} such that @math{@var{B}^T@times{}@var{B}=@var{M}}.
+@end deffn
 
-@deftypefn {Matrix Function} {} DESIGN (@var{m})
-@end deftypefn
+@deffn {Matrix Function} DESIGN (@var{M})
+Returns a design matrix for @var{M}.  The design matrix has the same
+number of rows as @var{M}.  Each column @var{c} in @var{M}, from left
+to right, yields a group of columns in the output.  For each unique
+value @var{v} in @var{c}, from top to bottom, add a column to the
+output in which @var{v} becomes 1 and other values become 0.
 
-@deftypefn {Matrix Function} {} DET (@var{m})
-@end deftypefn
+@pspp{} issues a warning if a column only contains a single unique value.
 
-@deftypefn {Matrix Function} {} EVAL (@var{m})
-@end deftypefn
+@format
+@t{DESIGN(@{1; 2; 3@}) @result{} @{1, 0, 0; 0, 1, 0; 0, 0, 1@}}
+@t{DESIGN(@{5; 8; 5@}) @result{} @{1, 0; 0, 1; 1, 0@}}
+@t{DESIGN(@{1, 5; 2, 8; 3, 5@})}
+ @result{} @t{@{1, 0, 0, 1, 0; 0, 1, 0, 0, 1; 0, 0, 1, 1, 0@}}
+@t{DESIGN(@{5; 5; 5@})} @result{} (warning)
+@end format
+@end deffn
 
-@deftypefn {Matrix Function} {} GINV (@var{m})
-@end deftypefn
+@deffn {Matrix Function} DET (@var{M})
+Returns the determinant of square matrix @var{M}.
+@end deffn
 
+@deffn {Matrix Function} EVAL (@var{M})
+Returns a column vector containing the eigenvalues of symmetric matrix
+@var{M}, sorted in ascending order.
 
-@deftypefn {Matrix Function} {} GSCH (@var{m})
-@end deftypefn
+Use @code{CALL EIGEN} (@pxref{CALL EIGEN}) to compute eigenvalues and
+eigenvectors of a matrix.
+@end deffn
 
+@deffn {Matrix Function} GINV (@var{M})
+Returns the @math{@var{k}@times{}@var{n}} matrix @var{A} that is the
+@dfn{generalized inverse} of @math{@var{n}@times{}@var{k}} matrix
+@var{M}, defined such that
+@math{@var{M}@times{}@var{A}@times{}@var{M}=@var{M}} and
+@math{@var{A}@times{}@var{M}@times{}@var{A}=@var{A}}.
+@end deffn
 
-@deftypefn {Matrix Function} {} INV (@var{m})
-@end deftypefn
 
+@deffn {Matrix Function} GSCH (@var{M})
+@end deffn
 
-@deftypefn {Matrix Function} {} KRONEKER (@var{m1}, @var{m2})
-@end deftypefn
 
+@deffn {Matrix Function} INV (@var{M})
+Returns the @math{@var{n}@times{}@var{n}} matrix @var{A} that is the
+inverse of @math{@var{n}@times{}@var{n}} matrix @var{M}, defined such
+that @math{@var{M}@times{}@var{A} = @var{A}@times{}@var{M} = I}, where
+@var{I} is the identity matrix.  @var{M} must not be singular, that
+is, @math{\det(@var{M}) \ne 0}.
+@end deffn
 
+@deffn {Matrix Function} KRONEKER (@var{Ma}, @var{Mb})
+Returns the @math{@var{pm}@times{}@var{qn}} matrix @var{P} that is the
+@dfn{Kroneker product} of @math{@var{m}@times{}@var{n}} matrix
+@var{Ma} and @math{@var{p}@times{}@var{q}} matrix @var{Mb}.  One may
+view @var{P} as the concatenation of multiple
+@math{@var{p}@times{}@var{q}} blocks, each of which is the scalar
+product of @var{Mb} by a different element of @var{Ma}.  For example,
+when @code{A} is a @math{2@times{}2} matrix, @code{KRONEKER(A, B)} is
+equivalent to @code{@{A(1,1)*B, A(1,2)*B; A(2,1)*B, A(2,2)*B@}}.
+@end deffn
 
-@deftypefn {Matrix Function} {} RANK (@var{m})
-@end deftypefn
+@deffn {Matrix Function} RANK (@var{M})
+@end deffn
 
 
 
 
-@deftypefn {Matrix Function} {} SOLVE (@var{ma}, @var{mb})
-@end deftypefn
+@deffn {Matrix Function} SOLVE (@var{Ma}, @var{Mb})
+@end deffn
 
 
-@deftypefn {Matrix Function} {} SVAL (@var{m})
-@end deftypefn
+@deffn {Matrix Function} SVAL (@var{M})
+@end deffn
 
 
-@deftypefn {Matrix Function} {} SWEEP (@var{m}, @var{n})
-@end deftypefn
+@deffn {Matrix Function} SWEEP (@var{M}, @var{n})
+@end deffn
 
 
 @node Matrix IO
 @subsubsection I/O
 
-@deftypefn {Matrix Function} {} EOF (@var{file})
-@end deftypefn
+@deffn {Matrix Function} EOF (@var{file})
+@end deffn
+
+@node Matrix CALL command
+@subsection The @code{CALL} Command
+
+@anchor{CALL EIGEN}