www.gusucode.com > robust 案例源码程序 matlab代码 > robust/CreateUncertainRealParametersExample.m

    %% Create Uncertain Real Parameters
% This example shows how to create uncertain real parameters, modify
% properties such as range of uncertainty, and sample uncertain
% parameters.
%% 
% Create an uncertain real parameter, nominal value 3, with default values
% for all unspecified properties (including plus/minus variability of 1).

% Copyright 2015 The MathWorks, Inc.

a = ureal('a',3) 
%%
% View the properties and their values, and note that the |Range| and |Percentage| descriptions
% of variability are automatically maintained.
get(a)

%% 
% Create an uncertain real parameter, nominal value 2, with 20%
% variability. Again, view the properties, and note that the |Range| and
% |PlusMinus| descriptions of variability are automatically maintained.
b = ureal('b',2,'Percentage',20) 
get(b)
%% 
% Change the range of the parameter.   All descriptions of variability are
% automatically updated, while the nominal value remains fixed. Although
% the change in variability was accomplished by specifying the
% |Range|, the |Mode| is unaffected, and remains
% |Percentage|.
b.Range = [1.9 2.3];
get(b)
%%
% As mentioned, the |Mode| property signifies what
% aspect of the uncertainty remains unchanged when |NominalValue| is
% modified. Hence, if a real parameter is in |Percentage| mode,
% then the |Range| and |PlusMinus| properties
% are determined from the |Percentage| property and |NominalValue|.
% Changing |NominalValue| preserves the |Percentage| property,
% and automatically updates the |Range| and |PlusMinus| properties.
b.NominalValue = 2.2;
get(b)
%%
% Create an uncertain parameter with an asymmetric variation about its
% nominal value.  Examine the properties to confirm the asymmetric range.
c = ureal('c',-5,'Percentage',[-20 30]); 
get(c) 
%%
% Create an uncertain parameter, specifying variability with |Percentage|,
% but force the |Mode| to be |Range|.
d = ureal('d',-1,'Mode','Range','Percentage',[-40 60]); 
get(d) 
%% 
% Finally, create an uncertain real parameter, and set the |AutoSimplify| property
% to |'full'|.
e = ureal('e',10,'PlusMinus',[-23],'Mode','Percentage','AutoSimplify','Full') 
get(e) 
%%
% Specifying conflicting values for |Range/Percentage/PlusMinus| when
% creating a |ureal| element does not result in an error. In this case, the
% last specified property is used. This last occurrence also
% determines the |Mode|, unless |Mode| is explicitly specified, in which
% case that is used, regardless of the property/value pairs ordering.
f = ureal('f',3,'PlusMinus',[-2 1],'Percentage',40) 
g = ureal('g',2,'PlusMinus',[-2 1],'Mode','Range','Percentage',40) 
g.Mode 
%% 
% Create an uncertain real parameter, use <docid:robust_ref.f10-90725> to
% generate 1000 instances (resulting in a 1-by-1-by-1000 array), reshape
% the array, and plot a histogram, with 20 bins (within the range of
% 2 to 4).
h = ureal('h',3); 
hsample = usample(h,1000); 
hist(reshape(hsample,[1000 1]),20); 
%% 
% Make the range unsymmetric about the nominal value, and repeat the
% sampling, and histogram plot (with 40 bins over the range of 2-to-6)
h.Range = [2 6]; 
hsample = usample(h,1000); 
hist(reshape(hsample,[1000 1]),40); 
%% 
% Note that the distribution is skewed. However, the number of samples less
% than the nominal value and the number of samples greater than the nominal
% value are equal (on average). Verify this.
length(find(hsample(:) < h.NominalValue)) 
%%
length(find(hsample(:) > h.NominalValue)) 
%% 
% The distribution used in usample is uniform in the normalized description
% of the uncertain real parameter. See <docid:robust_ug.f15-42635> to learn
% more about the normalized description.
%%
% There is no notion of an empty |ureal| (or
% any other uncertain element, for that matter).  |ureal|, by itself, creates an 
% element named |'UNNAMED'|, with default property values.