# polyBasis

Polynomial basis functions for tunable gain surface

## Syntax

``shapefcn = polyBasis('canonical',degree)``
``shapefcn = polyBasis('chebyshev',degree)``
``shapefcn = polyBasis(___,nvars)``
``shapefcn = polyBasis(___,varnames)``

## Description

You use basis function expansions to parameterize gain surfaces for tuning gain-scheduled controllers. `polyBasis` generates standard polynomial expansions in any number of scheduling variables. Use the resulting functions to create tunable gain surfaces with `tunableSurface`.

example

````shapefcn = polyBasis('canonical',degree)` generates a function that evaluates the powers of an input variable, x, up to `degree`: $shapefcn\left(x\right)=\left[x,{x}^{2},\dots ,{x}^{order}\right].$```

example

````shapefcn = polyBasis('chebyshev',degree)` generates a function that evaluates Chebyshev polynomials up to `degree`:$shapefcn\left(x\right)=\left[{T}_{1}\left(x\right),\dots ,{T}_{order}\left(x\right)\right].$The Chebyshev polynomials are defined recursively by:${T}_{0}\left(x\right)=1;\text{ }{T}_{1}\left(x\right)=x;\text{ }{T}_{i+1}\left(x\right)=2x{T}_{i}\left(x\right)-{T}_{i-1}\left(x\right).$```

example

````shapefcn = polyBasis(___,nvars)` generates an `nvars`-dimensional polynomial expansion by taking the outer product of `nvars` 1-D polynomial expansions. The resulting function `shapefcn` takes `nvars` input arguments and returns a vector with `(degree+1)^(nvars-1)` entries. For example, for `nvars` = 3 and canonical polynomials, $shapefcn\left(x,y,z\right)=\left[{x}^{i}{y}^{j}{z}^{k}\text{\hspace{0.17em}}:\text{\hspace{0.17em}}\text{\hspace{0.17em}}0\le i,j,k\le order,\text{\hspace{0.17em}}\text{\hspace{0.17em}}i+j+k>0\right].\text{ }$Thus, to specify a bilinear function in two scheduling variables, use:shapefcn = polyBasis('canonical',1,2);Using the resulting function with `tunableSurface` defines a variable gain of the form:$K\left(x,y\right)={K}_{0}+{K}_{1}x+{K}_{2}y+{K}_{3}xy.$Here, x and y are the normalized scheduling variables, whose values lie in the range [–1,1]. (See `tunableSurface` for more information.) To specify basis functions in multiple scheduling variables where the expansions are different for each variable, use `ndBasis`.```

example

````shapefcn = polyBasis(___,varnames)` specifies variable names. Use this syntax with any of the previous syntaxes to name the variables in `shapefcn`. Using variable names improves readability of the `tunableSurface` object display and of any MATLAB® code you generate using `codegen`. ```

## Examples

collapse all

Create basis functions for a gain that varies as a cubic function of one scheduling variable.

`shapefcn = polyBasis('canonical',3);`

`shapefcn` is a handle to a function of one variable that returns an array of values corresponding to the first three powers of its input. In other words, `shapefcn(x) = [x x^2 x^3]`. For example, examine `shapefcn(-0.2)`.

```x = -0.2; shapefcn(x)```
```ans = 1×3 -0.2000 0.0400 -0.0080 ```

Evaluating `[x x^2 x^3]` for `x` = -0.2 returns the same result.

`[x x^2 x^3]`
```ans = 1×3 -0.2000 0.0400 -0.0080 ```

Use `shapefcn` as an input argument to `tunableSurface` to define a polynomial gain surface. This `shapefcn` is equivalent to using:

`shapefcn = @(x) [x x^2 x^3];`

Create a set of basis functions that are Chebyshev polynomials of a single variable, up to third degree.

`shapefcn = polyBasis('chebyshev',3);`

Create basis functions for a bilinear gain surface, $\left[x,y,xy\right]$. Name the variables to make the function more readable.

`shapefcn = polyBasis('canonical',1,2,{'x','y'})`
```shapefcn = function_handle with value: @(x,y)utFcnBasisOuterProduct(FDATA_,x,y) ```

Confirm the values returned by `shapefcn` for a particular $\left(x,y\right)$ pair.

```x = 0.2; y = -0.5; shapefcn(x,y)```
```ans = 1×3 0.2000 -0.5000 -0.1000 ```

This `shapefcn` is equivalent to:

`shapefcn = @(x,y)[x,y,x*y];`

The basis functions of `shapefcn` are first-order in each of the two variables. To create a set of basis functions in different degrees for each variable, use `ndBasis`.

## Input Arguments

collapse all

Degree of the polynomial expansion, specified as a positive integer.

Number of scheduling variables, specified as a positive integer.

Variable names in the generated function `shapefcn`, specified as a:

• Character vector, for monovariable basis functions.

• Cell array of character vectors, for multivariable basis functions.

If you do not specify `varnames`, then the variables in `shapefcn` are named `{'x1','x2',...}`.

Example: `{'alpha','V'}`

## Output Arguments

collapse all

Polynomial expansion, specified as a function handle. `shapefcn` takes as input arguments the number of variables specified by `nvars`. The function evaluates polynomials in those variables up to the specified degree, and returns the resulting values in a vector. When you use `shapefcn` to create a gain surface, `tunableSurface` automatically generates tunable coefficients for each polynomial term in the vector.

Introduced in R2015b