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

    %% Tunable Gain With Two Independent Scheduling Variables  
% This example shows how to model a scalar gain _K_ with a bilinear dependence
% on two scheduling variables, $\alpha$ and _V_, as follows: 
%
% 
% $$K\left( {\alpha,V} \right) = {K_0} + {K_1}\alpha  + {K_2}V + {K_3}\alpha V .$$
% 
%
% For this example, $\alpha$ is an angle of incidence that ranges from 0 to 15
% degrees, and _V_ is a speed that ranges from 300 to 600 m/s. The coefficients
% $K_{0},...,K_{3}$ are the tunable parameters of this variable gain.   

% Copyright 2015 The MathWorks, Inc.


%% 
% Create a grid of design points, $(\alpha,V)$, that are linearly spaced in $\alpha$
% and _V_. These design points are where you will tune the gain surface
% coefficients. 
[alpha,V] = ndgrid(0:5:15,300:100:600); 

%%
% These arrays, |alpha| and |V|, represent the independent variation of
% the two scheduling variables, each across its full range.  

%% 
% When you tune the gain surface coefficients with |systune|, you might
% obtain better solver performance by normalizing the scheduling variables
% to fall within the interval [-1,1]. Scale the $\alpha$ and _V_ grid to fall
% within this range. 
alphaN = alpha/15;
VN = (V-450)/150;  

%% 
% Create the tunable gain surface sampled at the grid of $(\alpha_{N},V_{N})$
% values: 
% 
% $$K\left( {{\alpha _N},{V_N}} \right) = {K_0} + {K_1}{\alpha _N} + {K_2}{V_N} + {K_3}{\alpha _N}{V_N}.$$
% 

%%
% In this expansion, the basis functions are: 
% 
% $$\begin{array}{l}{F_1}\left( {{\alpha _N},{V_N}} \right) = {\alpha _N}\\{F_2}\left( {{\alpha _N},{V_N}} \right) = {V_N}\\{F_3}\left( {{\alpha _N},{V_N}} \right) = {\alpha _N}{V_N}.\end{array}$$
% 

%%
% Specify the values of the basis functions over the $(\alpha_{N},V_{N})$. 
F1 = alphaN;
F2 = VN;
F3 = alphaN.*VN;

K = gainsurf('K',1,F1,F2,F3) 

%%
% |K| is an array of generalized matrices. Each element in |K| corresponds
% to $K(\alpha_{N},V_{N})$ for a particular $(\alpha_{N},V_{N})$ pair, and depends
% on the tunable coefficients |K_0|,...,|K_3|.  

%% 
% Associate the independent variable values with the corresponding values
% of |K|. 
K.SamplingGrid = struct('alpha',alpha,'V',V);  

%% 
% The |SamplingGrid| property keeps track of the scheduling variable values
% associated with each entry in |K|. This association is convenient for
% tracing results back to independent variable values. For instance, you
% can use |view(K)| to inspect the tuned values of the gain surface after
% tuning. When you do so, |view| takes the axis range and labels from the
% entries in |SamplingGrid|. For this example, instead of tuning, manually
% set the values of the tunable blocks to non-zero values. View the resulting
% gain surface as a function of the scheduling variables. 
values = struct('K_0',1,'K_1',-1,'K_2',0.1,'K_3',-0.2);
Ktuned = setBlockValue(K,values);
view(Ktuned)    

%%
% The variable names and values that you specified in the |SamplingGrid|
% property are used to scale and label the axes.  

%% 
% You can use |K| as a tunable gain to build a control system with gain-scheduled
% tunable components. For example, use |K| to create a gain-scheduled low-pass
% filter. 
F = tf(K,[1 K]); 

%%
% You can use gain surfaces as arguments to model creation commands like
% |tf| the same way you would use numeric arguments. The resulting filter
% is a generalized state-space (|genss|) model array that depends on the
% four coefficients of the gain surface. 

%%
% Use model interconnection commands (such as |connect| and |feedback|)
% to combine |F| with an array of plant models sampled at the same values
% of $\alpha$ and _V_. You can then use |systune| to tune the gain-scheduled
% controller to meet your design requirements. Because you normalized the
% scheduling variables to model the tunable gain, you must adjust the coefficient
% values in the implementation of your tuned controller.