Documentation

## Vary Uncertainty Values Across Multiple Uncertain State Space Blocks

This example shows the workflow for varying uncertainty values across multiple Uncertain State Space blocks in a Simulink® model. Use this approach for complex models with large number of uncertain variables or Uncertain State Space blocks.

This section uses a Simulink model to provide step-by-step instructions for toggling between nominal and user-defined uncertainty values at the MATLAB® prompt.

1. Open the Simulink model `rct_sim_ex2`.

`rct_sim_ex2`

The model contains two Uncertain State Space blocks, as shown in the following figure. The `Unmodeled dynamics` and ```First order with uncertain pole``` blocks depend on the uncertain variables `input_unc` and `a`.

2. Double-click the `Unmodeled dynamics` block to open the block parameters dialog box. The Uncertainty value field contains the variable `val_all`. Similarly, the Uncertainty value field in the ```First order with uncertain pole``` block parameters dialog contains the variable `val_all`. You use this variable to vary the uncertain variable values across both the Uncertain State Space blocks. ### Note

When defining `val_all`, you can enter only a subset of uncertain variables referenced by the model in the structure. When you do not specify some uncertain variables, the software uses their nominal value during simulation.

3. At the MATLAB prompt, specify `val_all = []; `and click to simulate the model.

The software uses the nominal values of the uncertain variables `a` and `input_unc` during simulation. After the simulation completes, the MultiPlot Graph block shows the following figure. 4. Generate random samples of uncertainty values:

1. Find all Uncertain State Space blocks and associated uncertain variables in the model.

`uvars=ufind('rct_sim_ex2')`

MATLAB returns the following result:

`uvars = `

``` a: [1x1 ureal] input_unc: [1x1 ultidyn] ```

The uncertain variables `a` and `input_unc` are `ureal` and `ultidyn` objects, respectively and the structure `uvars` lists them by name.

2. Randomly sample the uncertain variables.

`val_all = usample(uvars)`

MATLAB returns the following result:

`val_all =`

``` a: -1.1167 input_unc: [1x1 ss] ```

The structure `val_all` contains sample values of the uncertain variables `a` and `input_unc`. The software samples the values within the specified uncertainty ranges for `a` and `input_unc`.

5. Simulate the model for the uncertainty values `val_all`. By repeating the process inside a for-loop, you can assess how uncertainty affects the model responses. For example, perform 10 simulations using random uncertainty values:

```for i=1:10; val_all = usample(uvars) sim('rct_sim_ex2',10); end```

During each simulation, the software samples values of the uncertain variables `input_unc` and `a` and plots the response for the sampled values. The MultiPlot Graph block shows the following responses obtained using random sample values of uncertain variables. ##### Support Get trial now