Accelerating the pace of engineering and science

# gainsurf

Create tunable gain surface for gain scheduling

gainsurf lets you express gain in terms of tunable parameters for tuning gain-scheduled controllers.

In gain-scheduled controllers, each controller gain, K(σ), is a function of the scheduling variables, σ. For tuning purposes, it is convenient to parameterize K(σ) as a smooth gain surface of the form:

$K\left(\sigma \right)={K}_{0}+{K}_{1}{F}_{1}\left(\sigma \right)+\dots +{K}_{M}{F}_{M}\left(\sigma \right).$

F1(σ),...,FM(σ) are user-selected basis functions. K0,...,KM are the coefficients to be tuned. You can use terms in a generic polynomial expansion as basis functions. Or, when you have a priori knowledge of the expected shape of K(σ), you can use more specific functions. You can then use systune, to tune the coefficients K0,...,KM, subject to your design requirements.

## Syntax

• K = gainsurf(name,K0init,F1,...,FM) example

## Description

example

K = gainsurf(name,K0init,F1,...,FM) constructs a tunable model of the gain surface $K\left(\sigma \right)={K}_{0}+{K}_{1}{F}_{1}\left(\sigma \right)+\dots +{K}_{M}{F}_{M}\left(\sigma \right)$, sampled at a discrete set of σ values (the design points). The arrays F1,...,FM contain the values of the basis functions F1(σ),...,FM(σ) at those design points. The gain surface model, K, depends on the tunable coefficients K0,...,KM. You can combine K with other static or dynamic elements to construct a closed-loop model of your gain-scheduled control system. Then, use systune to tune K0,...,KM so that the closed-loop system meets your design requirements at the selected design points.

## Examples

expand all

### Tunable Gain With One Scheduling Variable

Create a scalar gain K that varies as a quadratic function of a single scheduling variable, t:

This gain surface can represent a gain that varies with time. The coefficients , , and are the tunable parameters of this time-varying gain.

To represent the tunable gain surface K(t) in MATLAB®, 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 =

1x9 array of generalized matrices with 1 rows, 1 columns, and the following blocks:
K_0: Scalar parameter, 1 occurrences.
K_1: Scalar parameter, 1 occurrences.
K_2: Scalar parameter, 1 occurrences.

Type "double(K)" to see the current value, "get(K)" to see all properties, and "K.Blocks" to interact with the blocks.



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 . The second element, K(:,:,2), is , 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 , , and at the sample times t = 0,5,...,40.

### 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, and V, as follows:

For this example, 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 are the tunable parameters of this variable gain.

Create a grid of design points, , that are linearly spaced in 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 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 values:

In this expansion, the basis functions are:

Specify the values of the basis functions over the .

F1 = alphaN;
F2 = VN;
F3 = alphaN.*VN;

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

K =

4x4 array of generalized matrices with 1 rows, 1 columns, and the following blocks:
K_0: Scalar parameter, 1 occurrences.
K_1: Scalar parameter, 1 occurrences.
K_2: Scalar parameter, 1 occurrences.
K_3: Scalar parameter, 1 occurrences.

Type "double(K)" to see the current value, "get(K)" to see all properties, and "K.Blocks" to interact with the blocks.



K is an array of generalized matrices. Each element in K corresponds to for a particular 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 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.

### Gain Surface Over Nonregular Grid

Create a gain surface sampled at scheduling variable values that do not form a regular grid in the operating domain. The gain surface varies as a bilinear function of variables and :

Suppose that the values of interest of the scheduling variables are the following pairs.

Specify the sample values as vectors.

alpha = [-0.9;-1.5;-1.5;-2.5;-3.2;-3.9];
beta = [0.05;0.6;0.95;0.5;0.7;0.3];


Instead of a regular grid of values, here the gain surface is sampled at irregularly spaced points on -space.

plot(alpha,beta,'o')


The basis functions of the expansion of are:

Evaluate the basis functions at each of the sample points.

F1 = alpha;
F2 = beta;
F3 = alpha.*beta;


Create the tunable model of the gain surface using these sampled function values.

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

K =

6x1 array of generalized matrices with 1 rows, 1 columns, and the following blocks:
K_0: Scalar parameter, 1 occurrences.
K_1: Scalar parameter, 1 occurrences.
K_2: Scalar parameter, 1 occurrences.
K_3: Scalar parameter, 1 occurrences.

Type "double(K)" to see the current value, "get(K)" to see all properties, and "K.Blocks" to interact with the blocks.



The gain surface is represented by a 6-by-1 array of generalized matrices. Because K is a scalar gain, each element in the array is 1-by-1. Each element in the array represents for the corresponding sample. Each of these elements depends on the tunable parameters K_0,...,K_3.

Use the SamplingGrid property to associate the and values with the corresponding entries in K.

SG = struct('alpha',alpha,'beta',beta);
K.SamplingGrid = SG;


## Input Arguments

expand all

### name — Identifying label for the tunable gainstring

Identifying label for the tunable gain surface, specified as a string. The tunable coefficients of the gain surface are assigned names based on this identifying label. For example, suppose you create a gain surface using the name Kp. The tunable coefficients are realp blocks in the resulting genmat. These blocks have names Kp_0, Kp_1,...,Kp_M.

Additionally, you can use this label to refer to the gain surface. For example, you can extract tuned coefficient values from a control system model, M, that depends on the gain surface using [K0,K1,...,KM] = gainsurfdata(M,'Kname').

### K0init — Initial value of K0scalar | array

Initial value of the tunable coefficient K0, specified as a scalar or an array. The dimensions of K0init determine the I/O dimensions of the gain surface. For example, if the gain surface represents a two-input, two-output gain, you can set K0init = zeros(2). Doing so automatically sets the I/O dimensions of the other terms in the gain surface.

### F1,...,FM — Values of the basis functions at sample values of scheduling variablesnumeric arrays

Function values describing the dependence of the gain surface on the scheduling variables, specified as numeric arrays. Each Fj(σ) in the expansion of the gain surface is a scalar-valued function. The corresponding input argument, Fj, is a numeric array containing the values of Fj(σ) at the corresponding scheduling variable values. For instance, in the following illustration, Fj(σ) is a function of two scheduling variables. The corresponding matrix FJ contains the values of Fj(σ) sampled over a 2-D grid of (σ1,σ2) values.

To construct the arguments F1,...,FM when your sampling grid is regular, evaluate each Fj(σ) over that grid. For example, consider a gain that depends on two scheduling variables, α and β:

$K\left(\alpha ,\beta \right)={K}_{0}+{K}_{1}\alpha \beta +{K}_{2}\alpha +{K}_{3}\beta .$

For this gain, F1 = αβ, F2 = α, and F3 = β. To create the input argument F1, you first create a grid of α and β values that spans the operating range of these variables. Then, you compute the values of F1 over that grid.

[alpha,beta] = ndgrid(0:1:10,50:5:100);
F1 = alpha.*beta;

You can improve performance of the tuning algorithm by specifying the function values in terms of normalized scheduling variables that fall in the range [–1,1]. To do this, subtract the mean value from each variable grid and divide by the variable's half-range. For example:

alphaN = (alpha-5)/5;
betaN = (beta-75)/25;
F1 = alphaN.*betaN;

In this example the values of α and β are regularly spaced. However, regular grid spacing is not required. Suppose your sampling values are arbitrary (α,β) pairs. In this case, α and β are specified as vectors, where (α(i),β(i) represents one sample point. Each Fj is also a vector:

${F}_{j}=\left[{F}_{j}\left({\alpha }_{1},{\beta }_{1}\right),{F}_{j}\left({\alpha }_{2},{\beta }_{2}\right),\dots ,{F}_{j}\left({\alpha }_{N},{\beta }_{N}\right)\right].$

For an example, see Gain Surface Over Nonregular Grid.

## Output Arguments

expand all

### K — Tunable gain surfacegeneralized matrix

Tunable gain surface, returned as an array of generalized matrices (genmat).

The dimensions of each generalized matrix in the array (the I/O dimensions of the gain surface) are determined by the dimensions of K0init. The dimensions of the array itself are determined by the sampling grid used to specify the basis functions. Thus, each entry in the array represents the gain at the corresponding scheduling variable value.

The gain surface depends on the tunable coefficients K0,...,KM. Each coefficient is modeled as a realp block of the same size as K. For instance, if the gain surface models a scalar gain, then each coefficient is a scalar realp block. If the gain surface models a 2-by-3 gain matrix, then each coefficient is a 2-by-3 realp block.