📄 matrix_functions.hlp
字号:
{smcl}
{* 03feb2005}{...}
{cmd:help matrix functions}
{hline}
{title:Title}
{p2colset 5 22 24 2}{...}
{p2col :{hi:[D] functions} {hline 2}}Functions{p_end}
{p2colreset}{...}
{title:Description}
{pstd}This is a quick reference to matrix functions. See {help matrix} for
background information and links to more matrix help. For help on all
functions, see {help functions}.
{pstd}
Let {it:A}, {it:B}, {it:C}, ..., represent matrix names or matrix
expressions and let {it:a}, {it:b}, {it:c}, ..., represent numbers or scalar
expressions.
{title:Matrix functions}
{title:Matrix functions returning scalar}
{p 8 26 2}{cmd:colnumb(}{it:A}{cmd:,}{it:s}{cmd:)} {space 2} first column number
named {it:s}, {it:s} a string or string expression.{p_end}
{p 8 26 2}{cmd:colsof(}{it:B}{cmd:)} {space 5} number of columns{p_end}
{p 8 26 2}{cmd:det(}{it:B}{cmd:)} {space 8} determinant{p_end}
{p 8 26 2}{cmd:diag0cnt(}{it:B}{cmd:)} {space 3} number of zeros on
diagonal{p_end}
{p 8 26 2}{cmd:el(}{it:A}{cmd:,}{it:i}{cmd:,}{it:j}{cmd:)} {space 5} the
{it:i},{it:j} element of {it:A} (same as
{cmd:A[}{it:i}{cmd:,}{it:j}{cmd:]}){p_end}
{p 8 26 2}{cmd:issymmetric(}{it:A}{cmd:)} {space 6} returns 1 if {it:A}
is symmetric, 0 otherwise.{p_end}
{p 8 26 2}{cmd:matmissing(}{it:A}{cmd:)} {space 1} returns 1 if any
elements of matrix {it:A} are missing, 0 otherwise.{p_end}
{p 8 26 2}{cmd:mreldif(}{it:B}{cmd:,}{it:C}{cmd:)} {space 2} relative
difference{p_end}
{p 8 26 2}{cmd:rownumb(}{it:A}{cmd:,}{it:s}{cmd:)} {space 2} first row number
named {it:s}, {it:s} a string or string expression.{p_end}
{p 8 26 2}{cmd:rowsof(}{it:B}{cmd:)} {space 5} number of rows{p_end}
{p 8 26 2}{cmd:trace(}{it:B}{cmd:)} {space 6} sum of diagonal of square
matrix{p_end}
{pstd}
Matrix functions returning scalar may be used in any expression context, not
just matrix expression contexts.
{title:Matrix functions returning matrix}
{p 8 26 2}{cmd:cholesky(}{it:B}{cmd:)} {space 3} square root of symmetric
positive-definite matrix{p_end}
{p 8 26 2}{cmd:corr(}{it:B}{cmd:)} {space 7} correlation transform{p_end}
{p 8 26 2}{cmd:diag(}{it:V}{cmd:)} {space 7} if matrix {it:V} is
1 x n or n x 1; returns
n x n matrix with diagonal elements {it:V}{p_end}
{p 8 26 2}{cmd:get(}{it:name}{cmd:)} {space 5} return system matrix (see
{helpb get()}){p_end}
{p 8 26 2}{cmd:hadamard(}{it:A}{cmd:,}{it:B}{cmd:)} {space 1} returns a matrix
with {cmd:[}{it:i, j}{cmd:]} element equal to
{break}{it:A}{cmd:[}{it:i, j}{cmd:]}*{it:B}{cmd:[}{it:i, j}{cmd:]}.
{p_end}
{p 8 26 2}{cmd:I(}{it:n}{cmd:)} {space 10} {it:n} x {it:n} identity matrix{p_end}
{p 8 26 2}{cmd:inv(}{it:B}{cmd:)} {space 8} inverse of square matrix{p_end}
{p 8 26 2}{cmd:invsym(}{it:B}{cmd:)} {space 5} inverse of symmetric matrix; if
{it:B} is not positive definite, returns g2 inverse{p_end}
{p 8 26 2}{cmd:J(}{it:r}{cmd:,}{it:c}{cmd:,}{it:z}{cmd:)} {space 6} {it:r} x
{it:c} matrix containing constant element {it:z}{p_end}
{p 8 26 2}{cmd:matuniform(}{it:r}{cmd:,}{it:c}{cmd:)} {it:r} x {it:c}
matrix containing uniformly distributed pseudorandom numbers on the
interval [0,1). See {helpb generate} for setting the seed.{p_end}
{p 8 26 2}{cmd:nullmat(}{it:A}{cmd:)} {space 4} is for use with the
row-join({cmd:,}) and column-join({cmd:\}) operators in programming
situations; see {help matrix operators}.
The {cmd:nullmat()} function
informs Stata that you know {it:A} might not exist and, in that case,
the operators row-join and column-join are to be generalized. If
{it:A} does not exist, then {cmd:mat {it:A} = (nullmat({it:A}), 3)}
will result in {it:A} being the 1x1 matrix = (3).{p_end}
{p 8 26 2}{cmd:sweep(}{it:A}{cmd:,}{it:z}{cmd:)} {space 4} sweep of square
matrix; return {it:A} with zth row/column swept{p_end}
{p 8 26 2}{cmd:vec(}{it:A}{cmd:)} {space 8} returns a column vector formed by
listing the elements of {it:A} starting with the first
column and proceeding column by column{p_end}
{p 8 26 2}{cmd:vecdiag(}{it:B}{cmd:)} {space 4} returns row vector containing
diagonal of square matrix{p_end}
{title:Examples}
{phang}{cmd:. matrix beta = invsym(X'*X)*X'*y}{p_end}
{phang}{cmd:. display trace(X)}{p_end}
{phang}{cmd:. matrix L = cholesky(0.1*I(rowsof(X)) + 0.9*X)}
{title:Also see}
{psee}
Manual: {bf: [D] functions}
{psee}
Online: {helpb matrix},
{helpb matrix define},
{help matrix operators}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -