**
Object-Oriented Implementation
**

The main data structures in *Control System Professional*, TransferFunction and StateSpace, represent transfer-function and state-space objects. They are what may be called "active wrappers," meaning that they act as containers that keep all the relevant information about the system together and they convert between the data structures when applied over each other. Here, the relevant information is the matrix describing the input-output relations (possibly with a formal variable), or a collection of matrices describing a state-space realization of the system, the domain (continuous-time or discrete-time), and possibly a sampling period or sampling rate used to discretize the system and other information.

As an example, after loading the application,

we consider a third-order system.

Note that the scalar SISO (single-input, single-output) function is automatically "upgraded" to a MIMO (multi-input, multi-output) transfer matrix, which is a standard way to represent input-output relations in the application. To find a state-space realization of the transfer-function object, we apply the StateSpace head.

We can review the state-space and transfer-function objects in the traditional matrix notation.

"A" | |

"B" | |

"C" |

To recover the transfer-function representation, we simply apply the TransferFunction head.

Notice that the formal variable in transfer-function objects is optional. When it is not supplied, the standard *Mathematica* convention for pure functions is used and the formal variable is denoted as #. TransferFunction further resembles Function in that it can be applied to any variable. For example, here is the transfer matrix in the variable s.

We can use the same mechanism to obtain the value of the transfer matrix at a particular frequency ω.

This system is assumed to be in the continuous-time domain (that is, it represents the analog system). The function ToDiscreteTime finds the discrete-time approximation. The library of sampling methods can be accessed by choosing the value of the option Method, which currently supports such transforms as ZeroOrderHold, FirstOrderHold, ForwardRectangularRule, BackwardRectangularRule, BilinearTransform, ZeroPoleMapping, and BilinearTransform (which implements the bilinear, or Tustin, transform, with and without prewarping). Here is an example of such a conversion.

The option Sampled specifies the sampling period. It can also be set to True, to indicate a discrete-time system without giving a particular sampling period, or to False, for a continuous-time system. The default value is given by the global variable $Sampled, which is initially set to False.

One of the benefits of the object-oriented approach is that the same functions can operate on both transfer-function objects and state-space objects. For example, ToDiscreteTime can also be used to discretize the state-space object.

The function ToContinuousTime converts the system back to the continuous-time domain.

Similarly, the same functions operate on both continuous-time and discrete-time systems. The user can easily implement the same functionality when extending the application. For example, suppose we want to compute the impulse response via the inverse Laplace or *Z*-transform (for transfer functions defined on the *s*- or *z*-plane, respectively), bypassing the built-in routines that use the state-space approach. With the functions InverseLaplaceTransform and InverseZTransform, from the standard packages Calculus`LaplaceTransform` and DiscreteMath`ZTransform`, it is easy to build a function that behaves like the built-in functions.

Using the *Control System Professional* function ContinuousTimeQ (which tests whether the system is in the continuous-time domain), the new function automatically selects the appropriate transform and applies it to all elements of the transfer matrix. The options, if any, are passed to the transform. For the discrete-time transfer function

the corresponding impulse response is