Main Content

diag

Diagonal uncertain matrices; diagonals of an uncertain matrix

Description

MV = diag(V) creates an uncertain matrix MV whose diagonal elements are the elements of the uncertain vector V and whose off-diagonal elements are 0.

example

MV = diag(V,K) places the elements of V on the Kth diagonal of the matrix MV. K > 0 is above the main diagonal and K < 0 is below the main diagonal.

example

VM = diag(M) extracts a vector VM containing the diagonal elements of the uncertain matrix M.

example

VM = diag(M,K) extracts the elements of the Kth diagonal of the matrix M. K > 0 is above the main diagonal and K < 0 is below the main diagonal.

example

Examples

collapse all

Create an uncertain matrix MV in which the diagonal elements are the elements of an uncertain vector V, and the off-diagonal elements are all 0. First, create the uncertain vector V.

a = ureal('a',10);
b = ureal('b',5);
V = [1+a 2 3-b 4]
Uncertain matrix with 1 rows and 4 columns.
The uncertainty consists of the following blocks:
  a: Uncertain real, nominal = 10, variability = [-1,1], 1 occurrences
  b: Uncertain real, nominal = 5, variability = [-1,1], 1 occurrences

Type "V.NominalValue" to see the nominal value and "V.Uncertainty" to interact with the uncertain elements.

V is a 1-by-4 umat uncertain matrix, or in other words, an uncertain row vector with four elements. Create MV such that the diagonals of MV are the elements of V.

MV = diag(V)
Uncertain matrix with 4 rows and 4 columns.
The uncertainty consists of the following blocks:
  a: Uncertain real, nominal = 10, variability = [-1,1], 1 occurrences
  b: Uncertain real, nominal = 5, variability = [-1,1], 1 occurrences

Type "MV.NominalValue" to see the nominal value and "MV.Uncertainty" to interact with the uncertain elements.

To verify that MV is a diagonal matrix, examine its nominal value.

MV.NominalValue
ans = 4×4

    11     0     0     0
     0     2     0     0
     0     0    -2     0
     0     0     0     4

Next, create a matrix in which V forms the elements of the first diagonal below the main diagonal.

MV1 = diag(V,-1)
Uncertain matrix with 5 rows and 5 columns.
The uncertainty consists of the following blocks:
  a: Uncertain real, nominal = 10, variability = [-1,1], 1 occurrences
  b: Uncertain real, nominal = 5, variability = [-1,1], 1 occurrences

Type "MV1.NominalValue" to see the nominal value and "MV1.Uncertainty" to interact with the uncertain elements.
MV1.NominalValue
ans = 5×5

     0     0     0     0     0
    11     0     0     0     0
     0     2     0     0     0
     0     0    -2     0     0
     0     0     0     4     0

Obtain a vector by extracting the diagonal elements of an uncertain matrix. First, create an uncertain matrix.

a = ureal('a',10);
b = ureal('b',5);
M = [1+a 2 3+b; 4 5+a 6; 7 8 9]
Uncertain matrix with 3 rows and 3 columns.
The uncertainty consists of the following blocks:
  a: Uncertain real, nominal = 10, variability = [-1,1], 2 occurrences
  b: Uncertain real, nominal = 5, variability = [-1,1], 1 occurrences

Type "M.NominalValue" to see the nominal value and "M.Uncertainty" to interact with the uncertain elements.

M is a 3-by-3 uncertain matrix. Extract the diagonals of M into a three-element column vector.

VM = diag(M)
Uncertain matrix with 3 rows and 1 columns.
The uncertainty consists of the following blocks:
  a: Uncertain real, nominal = 10, variability = [-1,1], 1 occurrences

Type "VM.NominalValue" to see the nominal value and "VM.Uncertainty" to interact with the uncertain elements.

VM is a 3-by-1 umat, or an uncertain column vector. Note that V depends only on the uncertain parameter a, because the diagonal elements of M do not depend on b.

Next, extract a vector containing the elements of the first diagonal below the main diagonal of M.

VM1 = diag(M,-1)
Uncertain matrix with 2 rows, 1 columns, and no uncertain blocks.

Type "VM1.NominalValue" to see the nominal value and "VM1.Uncertainty" to interact with the uncertain elements.

This vector contains no uncertain elements at all. Examine its values.

VM1.NominalValue
ans = 2×1

     4
     8

Input Arguments

collapse all

Uncertain vector, specified as a umat object with dimensions 1-by-N (row vector) or N-by-1 (column vector).

Uncertain matrix, specified as a umat object.

Index of diagonal, specified as an integer. K = 0 represents the main diagonal, K > 0 is above the main diagonal, and K < 0 is below the main diagonal.

Output Arguments

collapse all

Uncertain diagonal matrix, returned as a umat object. The elements of the input vector V form the Kth diagonal of the matrix. If you omit K, then V forms the main diagonal of the matrix. MV is a square matrix of order length(V) + abs(K).

Uncertain column vector, returned as a umat object. The elements of VM are the diagonal elements of the input matrix M.

Version History

Introduced before R2006a

See Also

| |