## Using LTV and LPV Models in MATLAB and Simulink

Using Control System Toolbox™ software, you can represent linear parameter-varying (LPV) and linear
time-varying (LTV) systems in both MATLAB^{®} and Simulink^{®}.

Environment | Model Type | Model Object or Block |
---|---|---|

MATLAB | Linear parameter-varying | `lpvss` object |

Linear time-varying | `ltvss` object | |

Simulink | Linear parameter-varying | LPV System block |

Linear time-varying | LTV System block (since R2024a) |

### Model Objects

Use `lpvss`

and `ltvss`

to represent LPV and LTV systems in MATLAB, respectively. For more information about these models, see LTV and LPV Modeling.

The following table illustrates the types of varying models that you can represent:

Model Type | Mathematical Representation | Model Object |
---|---|---|

Continuous-time LPV model |
$$\begin{array}{c}E(t,p)\dot{x}={\delta}_{0}(t,p)+A(t,p)(x-{x}_{0}(t,p))+B(t,p)(u-{u}_{0}(t,p))\\ y(t)={y}_{0}(t,p)+C(t,p)(x-{x}_{0}(t,p))+D(t,p)(u-{u}_{0}(t,p))\end{array}$$ | `lpvss` |

Discrete-time LPV model |
$$\begin{array}{c}E(k,{p}_{k}){x}_{k+1}={\delta}_{0}(k,{p}_{k})+A(k,{p}_{k})({x}_{k}-{x}_{0}(k,{p}_{k}))+B(k,{p}_{k})({u}_{k}-{u}_{0}(k,{p}_{k}))\\ {y}_{k}={y}_{0}(k,{p}_{k})+C(k,{p}_{k})({x}_{k}-{x}_{0}(k,{p}_{k}))+D(k,{p}_{k})({u}_{k}-{u}_{0}(k,{p}_{k}))\end{array}$$ | `lpvss` |

Continuous-time LTV model |
$$\begin{array}{c}E(t)\dot{x}={\delta}_{0}(t)+A(t)(x-{x}_{0}(t))+B(t)(u-{u}_{0}(t))\\ y(t)={y}_{0}(t)+C(t)(x-{x}_{0}(t))+D(t)(u-{u}_{0}(t))\end{array}$$ | `ltvss` |

Discrete-time LTV model |
$$\begin{array}{c}{E}_{k}{x}_{k+1}={\delta}_{0k}+{A}_{k}({x}_{k}-{x}_{0}{}_{k})+{B}_{k}({u}_{k}-{u}_{0}{}_{k})\\ {y}_{k}={y}_{0k}+{C}_{k}({x}_{k}-{x}_{0}{}_{k})+{D}_{k}({u}_{k}-{u}_{0}{}_{k})\end{array}$$ | `ltvss` |

#### Data Function

The `ltvss`

and `lpvss`

objects require you to
specify a user-defined MATLAB function for calculating matrices and offsets. This is called the
*data function* and must be of the following form.

Model Type | Data Function |
---|---|

Continuous-time `ltvss` |
$$[A,B,C,D,E,{\delta}_{0},{x}_{0},{u}_{0},{y}_{0},Delays]=f(t)$$ |

Discrete-time `ltvss` |
$$[A,B,C,D,E,{\delta}_{0},{x}_{0},{u}_{0},{y}_{0},Delays]=f(k)$$ |

Continuous-time `lpvss` |
$$[A,B,C,D,E,{\delta}_{0},{x}_{0},{u}_{0},{y}_{0},Delays]=f(t,p)$$ |

Discrete-time `lpvss` |
$$[A,B,C,D,E,{\delta}_{0},{x}_{0},{u}_{0},{y}_{0},Delays]=f(k,p)$$ |

To understand the anatomy of a data function, consider
`dataFcnMaglev.m`

which is provided with the LPV Model of Magnetic Levitation System
example.

function [A,B,C,D,E,dx0,x0,u0,y0,Delay] = dataFcnMaglev(~,p) % MAGLEV example: % x = [h ; dh/dt] % p=hbar (equilibrium height) mb = 0.02; % kg g = 9.81; alpha = 2.4832e-5; A = [0 1;2*g/p 0]; B = [0 ; -2*sqrt(g*alpha/mb)/p]; C = [1 0]; % h D = 0; E = []; dx0 = []; x0 = [p;0]; u0 = sqrt(mb*g/alpha)*p; % ibar y0 = p; % y = h = hbar + (h-hbar) Delay = [];

This data function performs the following tasks:

Specifies the inputs of the data function.

A data function must have time and parameter values as inputs. If your parameters do not explicitly depend on time, you can omit the time input as shown in

`dataFcnMaglev.m`

. In discrete time, the time input*k*is the integer index that counts the number of sampling periods*T*, where the absolute time is given by_{s}*t*=*kT*. And,_{s}*p*is the parameter value at the time*t*or sample*k*, that is,*p*(*t*) or*p*[*k*].You can specify additional inputs to the data function by using anonymous functions. For more information , see Anonymous Functions. This helps reduce code redundancy and computation cost. For example, if you wrote a function that also requires parameters

`m`

and`n`

and an`options`

structure, you can write the data function as follows.DF = @(t,p) myFunction(t,p(1),..,p(n),m,n,options)

Defines the matrices and offsets.

The time or parameter matrices and offsets of the LTV or LPV models. You typically obtain these from linearizing nonlinear models around operating conditions.

Specifies the values of matrices, offsets, and delays as outputs of the data function.

The data function must return valid values for the outputs

`A`

,`B`

,`C`

,`D`

,`E`

,`dx0`

,`x0`

,`u0`

,`y0`

, and`Delay`

. You can set all output arguments except`A`

,`B`

,`C`

,`D`

to`[]`

when absent for (`t`

,`p`

) values.The

`Delay`

argument is a structure with fields`Input`

and`Output`

specifying the delays in input and output channels, respectively. Set`Delay.Input`

and`Delay.Output`

to vectors with length equal to the number of input and output channels, respectively. To indicate the absence of delay in a particular channel at all times, set the corresponding value in the vector to`NaN`

. For example, for a three-input system,`Delay.Input = [0.1 NaN sin(0.2*p)]`

defines a fixed delay in the first input channel, no delay in the second channel, and a varying delay in the third input channel. The software treats any delay not marked as`NaN`

as varying. Varying delays give rise to internal delays when connecting systems, and zero internal delays are set to a minimum of one integration step for simulation. Therefore, It is important to mark absent delays with`NaN`

rather than`0`

.*(since R2024a)**Before R2023b: Set*`Delay`

to`[]`

.

### Gridded LPV Models

A common way of representing LPV models is as an interpolated array of linear state-space models. A certain number of points in the scheduling space are selected. An LTI system is assigned to each point, representing the dynamics in the local vicinity of that point. You obtain the dynamics at scheduling locations in between the grid points by interpolating LTI systems at neighboring points. For meaningful interpolations of system matrices, all the local models must use the same state basis.

This form is called the *grid-based LPV representation*. For
more information, see Gridded Models and Choice of Sampling Grid.

### Sampling and Interpolation

Use `psample`

to sample the LTV or LPV dynamics over a grid of
*t* or (*t*,*p*) values
(*k* or (*k*,*p*) in discrete
time). This gives the local linear (affine) dynamics for a given time or parameter
value. The result consists of an array of `ss`

objects with
offsets.

Conversely, `ssInterpolant`

takes an `ss`

array models with offsets
and creates an LTV or LPV model that interpolates these values between grid points
(the grid is defined by the `SamplingGrid`

property of the
`ss`

array). The resulting model is called a gridded LTV or LPV
model.

### Model Interconnection

All standard signal-based connections listed under Model Interconnection are supported for LTV and LPV models.
These operations automatically manage offsets and do not involve any approximation.
Interconnecting models using signals allow you to construct models for control
systems. You can conceptualize your control system as a block diagram containing
multiple interconnected components, such as a plant and a controller connected in a
feedback configuration. For instance, you can build and LPV model of a plant, design
a gain-scheduled controller on a *t* or
(*t*,*p*) grid, and simulate the closed-loop
control system. See Analysis of Gain-Scheduled PI Controller and Control Design for Spinning Disks for
examples.

Additionally:

Combining two

`ltvss`

models yields an`ltvss`

model.Combining two

`lpvss`

models yields an`lpvss`

model, depending on the union of parameters.Combining an

`ltvss`

model and an`lpvss`

model yields an`lpvss`

model.Combining an LTI model with an

`ltvss`

or`lpvss`

model yields an`ltvss`

or`lpvss`

model, respectively.

Before you combine models with shared parameters that each use a different test
value `p0`

for validation, you must first reconcile these values
using `setTestValue`

. For `p0`

= 0, the interconnection
functions ignore the test values.

If each model has different parameters, the combined model depends on the union of the parameters.

### Continuous and Discrete Conversions

You can convert between continuous-time and discrete-time and resample
`ltvss`

and `lpvss`

models using `c2d`

, `d2c`

, and `d2d`

.

For analytic

`ltvss`

and`lpvss`

models, the software only supports conversion using the`'tustin'`

method.For gridded LTV and LPV models (see

`ssInterpolant`

), the functions convert or resample the LTI model at each grid point and interpolate the resulting data. The software only supports conversion for gridded models using`'zoh'`

,`'impulse'`

, and`'tustin'`

methods.

### Time Response Simulation

The time-response functions such as `step`

, `impulse`

, `lsim`

, and `initial`

support LTV and LPV model
simulation along with LTI models for easy comparison. You must specify an
equisampled time vector to set the integration step size of the fixed-step LTV and
LPV solvers. There are two key differences with LTI simulation:

For LPV models, you must specify an additional input/output

`p`

depending on the syntax. As input, you can specify the parameter trajectory*p*(*t*) as a vector or matrix or implicitly as a function*p*=*h*(*t*,*x*,*u*). As output,*p*is the actual parameter trajectory.For examples that compare the two approaches, see LPV Model of Magnetic Levitation System and Hidden Couplings in Gain-Scheduled Control.

Input offsets and initial conditions matter for LTV and LPV model. You can use the

`RespConfig`

object to manage these settings. The software now supports the input offsets and initial states for LTI models for uniformity. This allows for side-by-side comparisons with LTV and LPV models. You must specify correct model offsets along with proper initial conditions for accurate time-response simulation.

### Gain-Scheduled Controller Design

You can use functions such as `pidtune`

and `systune`

to tune gain-scheduled
controllers. A gain-scheduled controller is an LPV model parameterized by the
scheduling variables. For examples that implement a gain-scheduled controller as an
analytic LPV model, see Gain-Scheduled LQG Controller and Analysis of Gain-Scheduled PI Controller. For examples
that implement a gain-scheduled controller as a gridded LPV model, see LPV Model of Magnetic Levitation Model from Batch Linearization Results, Control Design for Wind Turbine, and Design and Validate Gain-Scheduled Controller for Nonlinear Aircraft Pitch Dynamics.

### LPV System and LTV System Blocks

You can use the LPV System and LTV System blocks to represent and simulate gridded LPV and LTV models in Simulink, respectively. You can use these blocks to represent an array of state-space models and its associated offsets as an LPV or LTV model. For an example, see Using LTI Arrays for Simulating Multi-Mode Dynamics.

You can also use these blocks to implement a controller designed on a grid of trim points, and then test the closed-loop response of the controller with the nonlinear Simulink model. For examples, see LPV Model of Magnetic Levitation Model from Batch Linearization Results and Design and Validate Gain-Scheduled Controller for Nonlinear Aircraft Pitch Dynamics.

### Model Delays

*Since R2024a*

For `ltvss`

and `lpvss`

objects, use the
`Delay`

argument of the data function to define fixed, varying,
or no delays. The software manages and propagates specified delays when using
operations such as model interconnection, continuous and discrete conversion, or
simulation.

To specify delays for Simulink models containing LPV System and LTV System blocks, you can use the Varying Delay and Discrete Varying Delay blocks from the Control System Toolbox library. These blocks allow you to model fixed, varying, or no delays in the input and output signals in your Simulink model.

### Other Supported Functionality

Additionally, the following functionality is currently supported.

Use

`setTestValue`

and`getTestValue`

to manage the test values used to validate the data function.Use

`sminreal`

to eliminate structurally nonminimal states. This is only possible in gridded models and when it is done in a uniform way across models in the grid.Use

`xperm`

to reorder the states.Use

`order`

to find the number of states.

### Applications of Linear Parameter-Varying Models

#### Modeling Multimode Dynamics

You can use LPV models to represent systems that exhibit multiple modes (regimes) of operation. Examples of such systems include colliding bodies, systems controlled by operator switches, and approximations of systems affected by dry friction and hysteresis effects. For an example, see LPV Model of Bouncing Ball.

#### Proxy Modeling for Faster Simulations

This approach is useful for generating surrogate models that you can use in place of the original system, which enable faster simulations as well as hardware-in-loop (HIL) simulations and reduce the memory footprint of target hardware code. You can also use surrogate models of this type for designing gain-scheduled controllers and for initializing parameter estimation tasks in Simulink. For an example of approximating a general nonlinear system behavior by an LPV model, see Design and Validate Gain-Scheduled Controller for Nonlinear Aircraft Pitch Dynamics.

LPV models can help speed up the simulation of physical component based systems, such as those built using Simscape™ Multibody™ and Simscape Electrical™ Power Systems software. For an example of this approach, see LPV Approximation of Boost Converter Model.

## See Also

`lpvss`

| `ltvss`

| `sample`

| `ssInterpolant`

| LPV System