www.gusucode.com > control 案例程序 matlab源码代码 > control/RandomSamplesOfRealParametersExample.m
%% Randomly Sample Multiple Parameters % % Take random samples of a model with both tunable and uncertain blocks. % Using uncertain blocks requires Robust Control Toolbox(TM). % Random sampling of tunable blocks works the same way as shown in this % example. %% % Create an uncertain model of $G\left( s \right) = {a \mathord{\left/ % {\vphantom {1 {\left( {\tau s + 1} \right)}}} \right. % \kern-\nulldelimiterspace} {\left( {\tau s + 1} \right)}}$, where _a_ is % an uncertain parameter that varies in the interval [3,5], and $\tau$ = % 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, |a| and % |tau|, and one tunable block, |C|. Sample |T| at 20 random |(a,tau)| pairs. [Ts,samples] = rsampleBlock(T,{'a','tau'},20); %% % |Ts| is a 20-by-1 array of |genss| models. The tunable block |C|, which % is not sampled, is preserved in |Ts|. The structure |samples| has fields % |samples.a| and |samples.tau| that contain the values at which those % blocks are sampled. % % Grouping |a| and |tau| into a cell array causes |rsampleBlock| to sample % them together, as |(a,tau)| pairs. Sampling the blocks independently % generates a higher-dimensionality arrays. For example, independently taking 10 % random samples of |a| and 5 samples of |tau| generates a 10-by-5 model % array. [TsInd,samples] = rsampleBlock(T,'a',10,'tau',5); TsInd %% % In this array, |a| varies along one dimension and |tau| varies along the % other.