## Modelica_LinearSystems2.WorkInProgress

Package for developments and internal models

### Package Content

Name | Description
--- | ---
DiscreteStateSpace | Discrete state space description of a linear, time invariant difference equation system (data + operations)
Controller |
Icons | Icons used in the Linear Systems library
Optimizer |
StateSpace | State space functions
TransferFunction |
ZerosAndPoles |
Tests | Functions to test the LinearSystems functions
Math |
MPC | Model Predictive Control
Junk | rubbish
StateSpace2 | Continuous state space description of a linear, time invariant differential equation system (data + operations)

## Modelica_LinearSystems2.WorkInProgress.DiscreteStateSpace

Discrete state space description of a linear, time invariant difference equation system (data + operations)

### Information

This record defines a linear time invariant difference equation system in state space form:

         x(Ts*(k+1)) = A * x(Ts*k) + B * u(Ts*k)
         y(Ts*k)     = C * x(Ts*k) + D * u(Ts*k)
         x_continuous(Ts*k) = x(Ts*k) + B2 * u(Ts*k)

with

- Ts - the sample time
- k - the index of the actual sample instance (k=0,1,2,3,...)
- t - the time
- u(t) - the input vector,
- y(t) - the output vector,
- x(t) - the discrete state vector (x(t=Ts*0) is the initial state),
- x_continuous(t) - the state vector of the continuous system from which the discrete block has been derived (details see below),
- A,B,C,D,B2 - matrices of appropriate dimensions.

A discrete system is usually derived by discretization from a continuous block, e.g., by function LinearSystems.DiscreteStateSpace.fromStateSpace. If the discretization method, e.g., the trapezoidal method, accesses actual and past values of the input u (e.g. u(Ts*k), u(Ts*(k-1), u(Ts*(k-2))), a state transformation is needed to get the difference equation above where only the actual value u(Ts*k) is accessed.

If the original continuous state vector should be computed from the sampled data system above, the matrices of this transformation have to be known. For simplicity and efficiency, here only the specific transformation used by function LinearSystems.DiscreteStateSpace.fromStateSpace is stored in the data record of the discrete system via matrix B2. Therefore, the state vector of the underlying continuous system can be calculated by adding the term B2*u to the state vector of the discretized system.

In Modelica notation, the difference equation above can be implemented as:

         when {initial(), sample(Ts,Ts)} then
            new_x = A * x + B * u;
                y = C * x + D * u;
                x = pre(new_x);
            x_continuous = x + B2 * u;
         end when;

Since no "next value" operator is available in Modelica, an auxiliary variable new_x stores the value of x for the next sampling instant. The relationship between new_x and x is defined via equation "x = pre(new_x)".

The body of the when-clause is active during initialization and at the next sample instant t=Ts. Note, the when-equation is not active after the initialization at t=0 (due to sample(Ts,Ts)), since the state x of the initialization has to be used also at t=0.

In library Blocks.Controller additional equations are added for the initialization to uniquely compute the initial vector x:

      initial equation
         if init == InitialState then
            x = x_start;
         elseif init == SteadyState then
            x = new_x;
         end if;

Optionally, x is set to a given start vector x_start. As default initialization, the equation "x = new_x" is added that defines steady state initialization for the discrete system. As a consequence, the output y(Ts*k), k=0,1,2,.., remains constant after this initialization, provided the input vector u(Ts*k) remains constant.

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
new_x = A*x + B*u; y = C*x + D*u; x_cont = x + B2*u
A[:, size(A, 1)] |
B[size(A, 1), :] |
C[:, size(A, 1)] |
D[size(C, 1), size(B, 2)] |
Data used to construct discrete from continuous system
Ts | Sample time [s]
B2[size(B, 1), size(B, 2)] | Reconstruct continuous state
method | Discretization method

## Modelica_LinearSystems2.WorkInProgress.StateSpace2

Continuous state space description of a linear, time invariant differential equation system (data + operations)

### Information

This record defines a linear time invariant differential equation system in state space form:

        der(x) = A * x + B * u
            y  = C * x + D * u

with

- u - the input vector
- y - the output vector
- x - the state vector
- A,B,C,D - matrices of appropriate dimensions

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
der(x) = A*x + B*u; y = C*x + D*u
A[:, size(A, 1)] |
B[size(A, 1), :] |
C[:, size(A, 1)] |
D[size(C, 1), size(B, 2)] |