Overview
The matrix implementation utilizes the tools of linear algebra to create a bathtub model.
Formulation
In a basic linear algebra formulation, the variables being modeled are arranged in a column vector. In this example, we will assume a simple model with only two tubs. We would then create a state vector defined as follows :
{%
S= \begin{bmatrix}
W_1(t) \\
I_1(t) \\
O_1(t) \\
W_2(t) \\
I_2(t) \\
O_2(t) \\
\end{bmatrix}
%}
Next we create a matrix that describes how the state vector above evolves with each time step.
That is, we will want to find a matrix A such that
{% S_{t+\Delta T} = A S_t %}
We know that in the case of the two tub model above, we will need a 6x6 matrix. Given the basic setup, the matrix will
look something like the following, where the questions marks are to be filled in later.
{%
\begin{bmatrix}
1 & 1 & -1 & 0 & 0 & 0 \\
? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? \\
0 & 0 & 0 & 1 & 1 & -1 \\
? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? \\
\end{bmatrix}
%}
Here, the basic structure indicates that the change in the water in each tub is the input to that tub minus the output.
Next, we will have to fill in the question marks. That is, we will have to specify how the input and output flows are determined from a prior state.
For example, if the inputs and outputs are assumed to be constant, then we will have the following:
{%
\begin{bmatrix}
1 & 1 & -1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 1 & -1 \\
0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
\end{bmatrix}
%}
Then the only remaining thing to do is to determining the initial state, that is, how much water is in each tub initially and
how fast are the flows into and out of each tub.