# How to get state-space equations form from a block diagram?

This is the block diagram that I'd like to transform into a state-space representation, where u1 and u2 are inputs and y1 and y2 are the outputs of the system

I tried to place state variables on the diagram and go from there (is there a cleaner way to do this?):

$x_{1}=y_{1}$

$x_{2}=x\dot{}_{1}$

$x_{3}=x\dot{}_{2}$

$x_{4}=y_{2}$

$x_{5}=x\dot{}_{4}$

$x_{6}=x\dot{}_{5}$

I am not sure how to go about from here. The $$\frac{1}{s+1}$$ block is confusing me. I know I can write the output signal from the $$\frac{1}{s+1}$$ block like this:

$out_{1}=u_{1}-o\dot{}ut_{1}$

$out_{2}=u_{2}-o\dot{}ut_{2}$

But I don't see if that's even useful and if it is, I don't know how to proceed.

So lets start with $$x_1$$: \begin{aligned} x_1 &= \frac{1}{s+1}u_1 & \rightarrow x_1 &= u_1-\dot{x}_1 \\ x_2 &= x_1 - u_1 + u_2 & \rightarrow x_2 &= u_2 - \dot{x}_1 \\ \dot{x}_3 &= x_2 \\ \dot{x}_4 &= x_3 \end{aligned} And the other side: \begin{aligned} x_5 &= \frac{1}{s+1}u_2 &\rightarrow x_5 = u_2-\dot{x}_5 \\ x_6 &= x_5 + x_3 - x_7 \\ \dot{x}_7 &= x_6 \\ \dot{x}_8 &= x_7 \\ \end{aligned} And now substitute where ever needed to write everything as an equation of a state derivative: \begin{aligned} \dot{x}_1 &=u_1 - x_1 \\ \dot{x}_3 &= u_2 - u_1 - x_1 \\ \dot{x}_4 &= x_3 \\ \dot{x}_5 &= u_2-x_5 \\ \dot{x}_7 &= x_5 + x_3 - x_7 \\ \dot{x}_8 &= x_7 \\ \end{aligned} As there are 6 integrators, having 6 states does make sense. Despite that, I do think it can be simplified, but lets first implement it into a state space $$\dot{x} = \begin{bmatrix}-1 & 0 & 0 & 0 & 0 & 0 \\ -1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 &0 \\ 0 & 0 & 0 & -1 & 0 & 0 \\ 0 & 1 & 0 & 1 & -1 & 0 \\ 0 &0 &0&0&1&0\end{bmatrix}\begin{bmatrix}x_1 \\ x_3 \\ x_4 \\ x_5 \\ x_7 \\ x_8\end{bmatrix} + \begin{bmatrix}1 & 0 \\ -1 & 1 \\ 0&0 \\0&1\\0&0\\0&0\end{bmatrix}\begin{bmatrix}u_1 \\ u_2\end{bmatrix}$$