www.gusucode.com > robust 案例源码程序 matlab代码 > robust/TunableGainWithOneSchedulingVariableExample.m
%% Tunable Gain With One Scheduling Variable % Create a scalar gain _K_ that varies as a quadratic function of a single % scheduling variable, _t_: % % $$K(t) = K_{0} + K_{1}t + K_{2}t^{2}.$$ % % This gain surface can represent a gain that varies with time. The coefficients % $K_{0}$, $K_{1}$, and $K_{2}$ are the tunable parameters of this time-varying % gain. % Copyright 2015 The MathWorks, Inc. %% % To represent the tunable gain surface _K_(_t_) in MATLAB(R), first choose % a vector of _t_ values in the range of interest for your problem. Then, % obtain the values of each basis function in the expansion of _K_(_t_), at % those _t_ values. For this example, suppose that _t_ varies from 0 to % 40. t = 0:5:40; F1 = t; F2 = t.^2; %% % Create a tunable model of the gain surface _K_(_t_), sampled at the _t_ values. K = gainsurf('K',1,F1,F2) %% % |K| is an array of generalized matrices. Each element in |K| describes % _K_(_t_) for a particular value of _t_, and depends on the tunable coefficients % |K_0|, |K_1|, and |K_2|. For example, the first element, |K(:,:,1)|, is % $K(0) = K_{0} + K_{1}*0 + K_{2}*0^{2} = K_{0}$. The second element, |K(:,:,2)|, % is $K(5) = K_{0} + K_{1}*5 + K_{2}*5^{2}$, and so on. %% % Associate the independent variable values with the corresponding values % of |K|. K.SamplingGrid = struct('time',t); %% % 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 as a function of time. %% values = struct('K_0',1,'K_1',-1,'K_2',0.1); view(setBlockValue(K,values)) %% % You can use |K| as a tunable gain to design a gain-scheduled controller. % Use |systune| to tune the coefficients $K_{0}$, $K_{1}$, and $K_{2}$ at % the sample times _t_ = 0,5,...,40.