- Scilab Online Help
- Elementary Functions
- Discrete mathematics
- Floating point
- Integer representation
- Trigonometry
- abs
- amell
- and
- &
- binomial
- bitand
- bitor
- bloc2exp
- bloc2ss
- cat
- cell2mat
- cellstr
- char
- cumprod
- cumsum
- delip
- diag
- diff
- dsearch
- exp
- eye
- flipdim
- gsort
- imag
- imult
- ind2sub
- intersect
- inttrap
- isdef
- isempty
- isequal
- isequalbitwise
- isreal
- isvector
- kron
- lex_sort
- linspace
- log
- log10
- log1p
- log2
- logm
- logspace
- lstsize
- max
- meshgrid
- min
- modulo
- ndgrid
- ndims
- nextpow2
- norm
- ones
- or
- |
- pen2ea
- permute
- pertrans
- prod
- rand
- real
- resize_matrix
- setdiff
- sign
- signm
- size
- solve
- sqrt
- sqrtm
- squarewave
- ssrand
- sub2ind
- sum
- sysconv
- sysdiag
- syslin
- toeplitz
- trfmod
- trianfml
- tril
- trisolve
- triu
- typeof
- union
- unique
- vectorfind
- zeros
Please note that the recommended version of Scilab is 2026.0.0. This page might be outdated.
See the recommended documentation of this function
diag
diagonal including or extracting
Calling Sequence
[y]=diag(vm, [k])
Arguments
- vm
vector or matrix (full or sparse storage)
- k
integer (default value 0)
- y
vector or matrix
Description
for vm a (row or column) n-vector
diag(vm) returns a diagonal matrix with entries of
vm along the main diagonal.
diag(vm,k) is a
(n+abs(k))x(n+abs(k)) matrix with the entries of
vm along the kth diagonal. k=0 is
the main diagonal k>0 is for upper diagonals and
k<0 for lower diagonals.
For a matrix vm, diag(vm,k) is
the column vector made of entries of the kth diagonal of
vm. diag(vm) is the main diagonal of
vm. diag(diag(x)) is a diagonal
matrix.
If vm is a sparse matrix
diag(vm,k) returns a sparse matrix.
To construct a diagonal linear system, use
sysdiag.
Note that eye(A).*A returns a diagonal matrix
made with the diagonal entries of A. This is valid for
any matrix (constant, polynomial, rational, state-space linear
system,...).
Examples
| << delip | Elementary Functions | diff >> |