# diag

Diagonal uncertain matrices; diagonals of an uncertain matrix

## Description

## Examples

### Create Uncertain Diagonal Matrix from Uncertain Vector

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

### Extract Diagonal Elements of Uncertain Matrix

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

`V`

— Uncertain vector

`umat`

object

Uncertain vector, specified as a `umat`

object with dimensions
1-by-*N* (row vector) or *N*-by-1 (column
vector).

`M`

— Uncertain matrix

`umat`

object

Uncertain matrix, specified as a `umat`

object.

`K`

— Index of diagonal

0 (default) | integer

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

`VM`

— Uncertain column vector

`umat`

object

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**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)