Main Content

rsampleBlock

Randomly sample Control Design blocks in generalized model

Description

example

Msamp= rsampleBlock(M,names,N)randomly samples a subset of the Control Design blocks in thegeneralized modelM. Thenamesargument specifies which blocks to sample, andNspecifies how many samples to take. The resultMsampis a model array of size[size(M) N]obtained by replacing the sampled blocks with their randomized values.

example

Msamp= rsampleBlock(M,names1,N1,names2,N2,...,namesM,NM)takesN1samples of the blocks listed innames1,N2samples of the blocks listed innames2, and so on. The resultMsampis a model array of size[size(M) N1 N2 ... NM].

[Msamp,samples] = rsampleBlock(___)also returns a data structure containing the block replacement values for each sampling point. You can use this syntax with any of the preceding input argument combinations.

Examples

collapse all

Create the first-order model G ( s ) = 1 / ( τ s + 1 ) , where τ is a tunable real parameter.

tau = realp('tau',5); G = tf(1,[tau 1]);

Restraintauto nonnegative values only.

G.Blocks.tau.Minimum = 0;

Generate 20 random samples ofG. The result is a 20-by-1 array of first-order models with random values oftautaken from the range oftau.

Gs = rsampleBlock(G,'tau',20); size(Gs)
20x1 array of state-space models. Each model has 1 outputs, 1 inputs, and 1 states.

Take random samples of a model with both tunable and uncertain blocks. Using uncertain blocks requires Robust Control Toolbox™. Random sampling of tunable blocks works the same way as shown in this example.

Create an uncertain model of G ( s ) = a / ( τ s + 1 ) , whereais an uncertain parameter that varies in the interval [3,5], and τ = 0.5 +/- 30%. Also, create a tunable PI controller, and form a closed-loop system from the tunable controller and uncertain system.

a = ureal('a',4); tau = ureal('tau',.5,'Percentage',30); G = tf(a,[tau 1]); C = tunablePID('C','pi'); T = feedback(G*C,1);

T is a generalized state-space model with two uncertain blocks,aandtau, and one tunable block,C. SampleTat 20 random(a,tau)pairs.

[Ts,samples] = rsampleBlock(T,{'a','tau'},20);

Tsis a 20-by-1 array ofgenssmodels. The tunable blockC, which is not sampled, is preserved inTs. The structuresampleshas fieldssamples.aandsamples.tauthat contain the values at which those blocks are sampled.

Groupingaandtauinto a cell array causesrsampleBlockto sample them together, as(a,tau)pairs. Sampling the blocks independently generates a higher-dimensionality arrays. For example, independently taking 10 random samples ofaand 5 samples oftaugenerates a 10-by-5 model array.

[TsInd,samples] = rsampleBlock(T,'a',10,'tau',5); TsInd
TsInd = 10x5 array of generalized continuous-time state-space models. Each model has 1 outputs, 1 inputs, 2 states, and the following blocks: C: Tunable PID controller, 1 occurrences. Type "ss(TsInd)" to see the current value, "get(TsInd)" to see all properties, and "TsInd.Blocks" to interact with the blocks.

In this array,avaries along one dimension andtauvaries along the other.

Input Arguments

collapse all

Model to sample, specified as a:

  • Generalized model (genssorgenfrd)

  • Generalized matrix (genmat)

  • Uncertain model (uss(Robust Control Toolbox)orufrd(Robust Control Toolbox))

  • Uncertain matrix (umat(Robust Control Toolbox))

Control Design blocks to sample, specified as a character vector or cell array of character vectors. The entries innamescorrespond to the names of at least a subset of the Control Design blocks inM. For example, suppose thatMis agenssmodel with tunable blockst1andt2, and uncertain blocksu1andu2. Then,{'t1','u2'}is one possible value fornames.

Grouping block names together in a cell array generates samples of the group rather than independent samples of each block. For example, the following code generates a 10-by-1 array of models, where each entry in the array has a random value for the pair(t1,u2).

Msamp = rsampleBlock(M,{'t1','u2'},10);

To sample parameters independently, do not group them. For example, the following code generates a 10-by-20 array of models, wheret1varies along the first dimension andu2varies along the second dimension.

Msamp = rsampleBlock(M,'t1',10,'u2',20);

rsampleBlockignores any entry innamesthat does not appear inM.

Number of samples to take of the preceding block or blocks, specified as a positive integer.

Output Arguments

collapse all

Array of model samples, returned as a generalized model array,ssarray,frdarray, or numeric array.Msampis of the same type asM, unless all blocks are sampled. In that case,Msampis a numeric array,ssarray, orfrdarray. For example, suppose thatMis aussmodel with uncertain blocksu1andu2. The following command returns an array ofussmodels, with uncertain blocku2.

Msamp1 = rsampleBlock(M,'u1',10);

下面的命令块和retu样品rns an array ofssmodels.

Msamp2 = rsampleBlock(M,{'u1','u2'},10);

rsampleBlockuses values that fall within the uncertainty range when sampling uncertain blocks, and within the maximum and minimum parameter values when sampling tunable blocks.

Block sample values, returned as a structure. The fields ofsamplesare the names of the sampled blocks. The values are arrays containing the corresponding random values used to generate the entries inMsamp. For instance, suppose that you run the following command, whereMis agenssmodel with tunable blockst1andt2.

[Msamp,samples] = rsampleBlock(M,{'t1','t2'},10);

Then,samples.t1contains the 10 values oft1andsamples.t2contains the 10 values oft2. If you sample a block that is not scalar valued, the corresponding field ofsamplescontains values compatible with the block. For instance, if you sample atunablePIDblock,samplescontains an array of state-space models that represent PID controllers.

See Also

|||||(Robust Control Toolbox)

Introduced in R2016a