MATLAB Examples

Sample Uncertain Elements to Create Arrays

A common way to generate an array is to sample the uncertain elements of an uncertain object. This example shows how to generate arrays by taking random samples of a umat uncertain matrix that has two uncertain elements. To generate arrays by sampling at specific values, use usubs.

Create an uncertain matrix.

a = ureal('a',4);
b = ureal('b',2);
M = [a b;b*b a/b;1-b 1+a*b]
M =

  Uncertain matrix with 3 rows and 2 columns.
  The uncertainty consists of the following blocks:
    a: Uncertain real, nominal = 4, variability = [-1,1], 3 occurrences
    b: Uncertain real, nominal = 2, variability = [-1,1], 6 occurrences

Type "M.NominalValue" to see the nominal value, "get(M)" to see all properties, and "M.Uncertainty" to interact with the uncertain elements.

Sample the uncertain real parameter b in the matrix M, at 20 random points within its range.

[Ms,bvalues] = usample(M,'b',20);

This results in an array of 20 3-by-2 umat matrices, with only one uncertain element, a. The uncertain element b of M has been sampled out, leaving a new array dimension in its place.

Ms
Ms =

  20x1 array of uncertain matrices with 3 rows, 2 columns, and the following uncertain blocks:
    a: Uncertain real, nominal = 4, variability = [-1,1], 3 occurrences

Type "Ms.NominalValue" to see the nominal value, "get(Ms)" to see all properties, and "Ms.Uncertainty" to interact with the uncertain elements.

Addtionally, bvalues is a structure containing the corresponding sampled values of b.

bvalues
bvalues = 

  20x1 struct array with fields:

    b

Next, sample the remaining uncertain real parameter a in the matrix Ms. This removes the second uncertain block, resulting in a 3-by-2-by-20-by-15 double.

[Mss,avalues] = usample(Ms,'a',15);
size(Mss)
ans =

     3     2    20    15

You can also sample multiple parameters at once. The following operation returns Mss1, which is identical to Mss.

[Mss1,values] = usample(M,'b',20,'a',15);

Rather than sampling the each variable (a and b) independently, generating a 20-by-15 grid in a 2-dimensional space, you can sample the two-dimensional space can be sampled. Sample the 2-dimensional space with 800 points.

[Ms2d,values] = usample(M,{'a' 'b'},800);

Ms2d is a 3-by-2-by-800 umat array, where each entry corresponds to a different randomly selected (a,b) pair. The structure array values contains these (a,b) values.

values
values = 

  800x1 struct array with fields:

    a
    b