# ECE-GY 9243/ME-GY 7973, Optimal and learning control for robotics, Exercise series 2
## 1
### a) whether stable when uncontrolled?
#### 1)
We know that every vector can be represented as a linear combination of the eigenvectors of an (non-degenerate) operator.
The next state will be
$$
{\bf{x}}_{n}=\sum_i c_i {\bf{v}}_{i}
\\
{\mathbf{x}}_{n+1}=\sum_i c_i \lambda_i {\bf{v}}_{i}
$$
where ${\bf{v}}_{i}$, $c_i$, and ${\lambda_i}$ are eigenvector, coefficient, and eigenvalue.
As we can see, if the system has $\|{\lambda_i\|}>1$, the system is unstable.
The eigenvalues of the state evolution matrix here is
```python
import numpy as np
A = np.array([[0.5, 0, 0.5],[0, 0, -2],[4, 2, 1]])
print(abs(np.linalg.eig(A)[0])
```
```python
[1. 1.41421356 1.41421356]
```
So the system is not stable.
#### 2)
```
[0.87743883 0.37743883 0.37743883]
```
Stable.
#### 3)
[1.41421356 1.41421356 2. ]
Unstable.
### b)
We want to know whether the influence of the control can be passed to all of the degree of freedom.
#### 1) **controllable**
#### 2) **controllable**
#### 3) **not controllable**
```python=
A = np.array([[.5, 0, .5],
[0, 0, -2],
[4, 2, 1]])
B = np.array([[0,0],[1,0],[0,1]])
tmp1 = B
tmp2 = np.matmul(A,B)
tmp3 = np.matmul(A,tmp2)
tmp4 = np.concatenate((tmp1, tmp2),1)
tmp5 = np.concatenate((tmp4, tmp3),1)
print(matrix_rank(tmp5))
A = np.array([[.5, 0, .5],
[0, 0, -.5],
[.5, .5, .5]])
B = np.array([[0,0],[1,0],[0,1]])
tmp1 = B
tmp2 = np.matmul(A,B)
tmp3 = np.matmul(A,tmp2)
tmp4 = np.concatenate((tmp1, tmp2),1)
tmp5 = np.concatenate((tmp4, tmp3),1)
print(matrix_rank(tmp5))
A = np.array([[2, 0, 0],
[0, 0, -2],
[1, 1, 0]])
B = np.array([[0,0],[1,0],[0,1]])
tmp1 = B
tmp2 = np.matmul(A,B)
tmp3 = np.matmul(A,tmp2)
tmp4 = np.concatenate((tmp1, tmp2),1)
tmp5 = np.concatenate((tmp4, tmp3),1)
print(matrix_rank(tmp5))
```
### c)
If the system is not controllable, then it is not promised that we can bring it to any desired state, even given infinite number of steps.
### d)
rank is 3
is controllable


rank is 3
is controllable


rank is 2
is not controllable

