Diag {lazy.mat}R Documentation

Diag(x) creats a diagonam matrix from its argument vector or matrix

Description

Diag(x) creats a diagonam matrix from its argument vector or matrix

Usage

Diag(x, drop = FALSE)

Arguments

x

Input square matrix or scalar

drop

= 1 to make the result a scalar when Diag(x) is 1 x 1.

Details

Diag(x) returns a diagonal matrix whose diagonal elements are:
1) the diagonal elements of x when x is a genuine matrix,
2) x when x is a vector, row vector, or column vector.

Can be used with a character matrix

Value

A diagonal matrix

Examples

Diag(demomat(2,2))
Diag(1:3)
Diag(matrix(1:3,1))
Diag(2)
Diag(demomat(2,2,root="a"))
Diag(diag(demomat(2,2,root="a")))

# Semi Symbolic Partitioned Matrix:  Super Matrix with SMdim attributes
A=demomat(c(2,3),c(2,3),root="a")
Printb(A)
resA=Diag(A,A)
Printb(resA)
resAB=b_diag(A,demomat(2,2,root="b"),A)
Printb(resAB, sep=".")


# Fully Symbolic Partitioned Matrix: No SMdim attribute but fullsymb attribute
Ap=demomat(2,2,root="A", fullsymb=1)
Printb(Ap)
resAp=Diag(Ap)
Printb(resAp)
resABp=b_diag(Ap,demomat(2,2,root="b"),Ap)
Printb(resABp, sep=".")


[Package lazy.mat version 0.1.3 Index]