# delay

Return past value of operand

## Syntax

```delay(u,tau) delay(u,tau, History = u0, MaximumDelay = taumax) ```

## Description

Use the `delay` operator in the `equations` section to refer to past values of expressions:

`delay(u,tau)` = `u(t-tau)`

The full syntax is:

`delay(u,tau, History = u0, MaximumDelay = taumax)`

The required operands are:

• `u` — The first operand is the Simscape™ expression being delayed. It can be any numerical expression that does not itself include `delay` or `der` operators.

• `tau` — The second operand is the delay time. It must be a numerical expression with the unit of time. The value of `tau` can change, but it must remain strictly positive throughout the simulation.

The optional operands may appear in any order. They are:

• `History` — The return value for the initial time interval (`t` <= `StartTime` + `tau`). The units of `u` and `u0` must be commensurate. The default `u0` is 0.

• `MaximumDelay` — The maximum delay time. `taumax` must be a constant or parametric expression with the unit of time. If you specify ```MaximumDelay = taumax```, a runtime error will be issued whenever `tau` becomes greater than `taumax`.

Note

You have to specify `MaximumDelay` if the delay time, `tau`, is not a constant or parametric expression. If `tau` is a constant or parametric expression, its value is used as the default for `MaximumDelay`, that is, `taumax` = `tau`.

At any time `t`, `delay(u,tau)` returns a value approximating `u`( `t` - `tau`) for the current value of `tau`. More specifically, the expression `delay(u,tau, History = u0)` is equivalent to

```if t <= (StartTime + tau) return u0(t) else return u(t-tau) end ```

In other words, during the initial time interval, from the start of simulation and until the specified delay time, `tau`, has elapsed, the `delay` operator returns `u0` (or 0, if `History` is not specified). For simulation times greater than `tau`, the `delay` operator returns the past value of expression, `u`( `t` - `tau`).

Note

• When simulating a model that contains blocks with delays, memory allocation for storing the data history is controlled by the Delay memory budget [kB] parameter in the Solver Configuration block. If this budget is exceeded, simulation errors out. You can adjust this parameter value based on your available memory resources.

• For recommendation on how to linearize a model that contains blocks with delays, see Linearizing with Simulink Linearization Blocks.

## Examples

This example shows implementation for a simple dynamic system:

`$\begin{array}{l}\stackrel{˙}{x}=-x\left(t-1\right)\\ x\left(t<0\right)=1\end{array}$`

The Simscape file looks as follows:

```component MyDelaySystem parameters tau = {1.0,'s'}; end variables x = 1.0; end equations x.der == -delay( x,tau,History = 1.0 )*{ 1, '1/s' }; % x' = - x(t - 1) end end ```

`MaximumDelay` is not required because `tau` is constant.

The `{ 1, '1/s' }` multiplication factor is used to reconcile the units of expression and its time derivative. See `der` reference page for more information.

For other examples of using the `delay` operator, see source for the PS Constant Delay and PS Variable Delay blocks in the Simscape Foundation library (open the block dialog box and click the Source code link).

The Variable Transport Delay example shows how you can model a variable transport delay using the `delay` operator. To see the implementation details, open the example model, look under mask of the Transport Delay subsystem, then right-click the Variable Transport Delay block and select Simscape > View source code.

## Version History

Introduced in R2012a