# Code Samples


```python
import sympy as sp
import numpy
import pandas
```


```python
sp.init_printing()
```


```python
x, y, z, k1, k2, k3 = sp.symbols("x, y, z, k1, k2, k3")
```


```python
sp.solveset(sp.sin(x) - 1, x)
```


```python
matrix = sp.Matrix([sp.sin(x) -1, sp.cos(y) -1 ])
matrix
```




$\displaystyle \left[\begin{matrix}\sin{\left(x \right)} - 1\\\cos{\left(y \right)} - 1\end{matrix}\right]$




```python
sp.solve(matrix)
```


```python
kinetics = sp.Matrix([k1*x*y - 3, k2*x/(1 -x) - 4])
```


```python
sp.nonlinsolve(kinetics, [x,y])
```


```python
sp.plot(2*x**2 + 3*x)
```


```python
from sympy.plotting import plot3d_parametric_line

t = sp.symbols('t')
alpha = [sp.cos(t), sp.sin(t), t]
plot3d_parametric_line(*alpha)

```


```python
# Plots for the reaction flux
#  x + y -> z; k1*x*y
flux = sp.Matrix([x, y, k1*x*y])
flux_plot = flux.subs({k1: 3})
plot3d_parametric_line(x, x**2, 3*x**3)
```


```python
f, g = sp.symbols('f g', cls=sp.Function)
diffeq = sp.Eq(f(x).diff(x, x) - 2*f(x).diff(x) + f(x), sp.sin(x))
diffeq
```


```python
result = sp.dsolve(diffeq, f(x))
```


```python
syms = list(result.free_symbols)
syms[0]
result1 = result.subs({syms[0]: 1, syms[1]: 1})
sp.plot(result1.rhs)
```


```python
sp.solve(x**2 - 2*x + 1, x)
```


```python
result1.rhs
```

# Workflow for Solving LTI Systems
1. Given $A, B, C$, find 
   1. $e^{At}$
   1. $\int_0^t e^{A(t - \tau)} u(\tau) d \tau$ for 
   $u(\tau) \in \{ \delta(t), 1(t), t \} $
   1. $x(t)$
   1. $y(t)$

1. Plot $x$, $y$

1. Solve for observability, controllability

# Workflow for Reaction Networks
1. Simulate the original model
1. Convert model to sympy
1. Get symbolic Jaccobian
1. Construct LTI models for different points in state space

8de1223ec4f07121645e6f249abbf1faad9e9b5f
ipynb
Jupyter Notebook
save/MatrixExponential.ipynb
joseph-hellerstein/advanced-controls-lectures
dc43f6c3517616da3b0ea7c93192d911414ee202
MIT
save/MatrixExponential.ipynb
joseph-hellerstein/advanced-controls-lectures
dc43f6c3517616da3b0ea7c93192d911414ee202
MIT
save/MatrixExponential.ipynb
joseph-hellerstein/advanced-controls-lectures
dc43f6c3517616da3b0ea7c93192d911414ee202
MIT
Qwen/Qwen-72B
1. YES
2. YES