📄 mf_diag.hlp
字号:
{smcl}
{* 16mar2005}{...}
{bf:help mata diag()}
{hline}
{* index diag()}{...}
{* index extract diagonal}{...}
{* index diagonal matrix}{...}
{title:Title}
{p 4 8 2}
{bf:[M-5] diag() -- Create diagonal matrix}
{title:Syntax}
{p 8 12 2}
{it:numeric matrix}
{cmd:diag(}{it:numeric matrix Z}{cmd:)}
{p 8 12 2}
{it:numeric matrix}
{cmd:diag(}{it:numeric vector z}{cmd:)}
{title:Description}
{p 4 4 2}
{cmd:diag()} creates diagonal matrices.
{p 4 4 2}
{cmd:diag(}{it:Z}{cmd:)}, {it:Z} a matrix, extracts the principal diagonal
of {it:Z} to create a new matrix. {it:Z} must be square.
{p 4 4 2}
{cmd:diag(}{it:z}{cmd:)}, {it:z} a vector, creates a new matrix with
the elements of {it:z} on its diagonal.
{title:Remarks}
{p 4 4 2}
Do not confuse {cmd:diag()} with its functional inverse,
{cmd:diagonal()}; see
{bf:{help mf_diagonal:[M-5] diagonal()}}.
{cmd:diag()} creates a matrix from a vector (or matrix);
{cmd:diagonal()} extracts the diagonal of a matrix into a vector.
{p 4 4 2}
Use of {cmd:diag()} should be avoided because it is wasteful of memory.
The colon operators will allow you to use vectors directly:
Desired calculation equivalent
{hline 45}
{cmd:diag(}{it:v}{cmd:)*}{it:X},
{it:v} a column {it:v}{cmd::*}{it:X}
{it:v} a row {it:v}{bf:'}{cmd::*}{it:X}
{it:v} a matrix {cmd:diagonal(}{it:v}{cmd:):*}{it:X}
{it:X}{cmd:*diag(}{it:v}{cmd:)}
{it:v} a column {it:X}{cmd::*}{it:v}{bf:'}
{it:v} a row {it:X}{cmd::*}{it:v}
{it:v} a matrix {it:X}{cmd::*diagonal(}{it:v}){bf:'}
{hline 45}
{p 4 4 2}
In the above table, it is assumed that {it:v} is real. If {it:v} might be
complex, the transpose operators that appear must be changed to
{cmd:transposeonly()} calls, because we do not want the conjugate. For
instance, {it:v}{bf:'}{cmd::*}{it:X} would become
{cmd:transposeonly(}{it:v}{cmd:):*}{it:X}.
{title:Conformability}
{cmd:diag(}{it:Z}{cmd:)}:
{it:Z}: {it:m x n}
{it:result}: min({it:m},{it:n}) {it:x} min({it:m},{it:n})
{cmd:diag(}{it:z}{cmd:)}:
{it:z}: {it:1 x n} or {it:n x 1}
{it:result}: {it:n x n}
{title:Diagnostics}
{p 4 4 2}
None.
{title:Source code}
{p 4 4 2}
{view diag.mata, adopath asis:diag.mata}
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-5] diag()}
{p 4 13 2}
Online: help for
{bf:{help mf_diagonal:[M-5] diagonal()}},
{bf:{help mf_isdiagonal:[M-5] isdiagonal()}};
{bf:{help m4_manipulation:[M-4] manipulation}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -