```python
import numpy as np
import sympy as sy
from sympy import I, exp
from sympy.utilities.codegen import codegen
```


```python
z = sy.symbols("z", real=False)
wn, zeta, a,h,r1,s0,s1 = sy.symbols("wn, zeta,a,h,r1,s0,s1", real=True)
```


```python
pc1 = -wn*zeta + I*wn*sy.sqrt(1-zeta**2)
pc2 = -wn*zeta - I*wn*sy.sqrt(1-zeta**2)

rd = exp(-wn*zeta*h)
argd = wn*sy.sqrt(1-zeta**2)*h
reald = rd*sy.cos(argd)
imd = rd*sy.sin(argd)
Ac = sy.poly(z**2 - 2*reald*z + rd**2, z)
ad = sy.exp(-a*h)
Ao = sy.poly(z-ad, z)
Acl = Ac*Ao

A = sy.poly((z-1)*(z-exp(-2*h)), z)
B = sy.poly((-1+h+exp(-2*h))*z + 1-(1+h)*exp(-2*h), z)

print Ac
```


```python
A.subs(h,0.14).subs(wn, 2*np.sqrt(2)).subs(zeta, np.cos(np.pi/4.0))
```




    z**2 - 1.75578374145573*z + 0.755783741455725




```python
R = sy.poly(z+r1, z)
S = sy.poly(s0*z + s1, z)
dioph=(A*R+B*S-Acl).all_coeffs()
```


```python
sol=sy.solve(dioph, (r1,s0,s1))
```


```python
print sy.simplify(sy.expand(sol[r1].subs(h,0.14).subs(wn, 2*np.sqrt(2)).subs(zeta, np.cos(np.pi/4.0))))
print sy.simplify(sy.expand(sol[s0].subs(h,0.14).subs(wn, 2*np.sqrt(2)).subs(zeta, np.cos(np.pi/4.0))))
print sy.simplify(sy.expand(sol[s1].subs(h,0.14).subs(wn, 2*np.sqrt(2)).subs(zeta, np.cos(np.pi/4.0))))
```

    -2.16080564088232*exp(-0.14*a) + 1.54163168497804
    -11.1384313455197*exp(-0.14*a) + 11.8844037451403
    7.67227291664397*exp(-0.14*a) - 8.4182453162646



```python
# Reorganize solution expression for matlab code generation
sol_expr = ('RST_example', [sol[r1], sol[s0], sol[s1], Ac.subs(z, 1)/B.subs(z,1), ad])  
```


```python
# Export to matlab code
[(m_name, m_code)] = codegen(sol_expr, 'octave')
```


```python
print m_code
with open("/home/kjartan/Dropbox/undervisning/tec/MR2007/matlab/RST_example.m", "w") as text_file:
    text_file.write(m_code)
```


```python

```




    [s1, s0, r1]




```python
np.exp(-0.28)
```


```python
0.28*180.0/np.pi
```


```python
hh=0.14
-1+hh+np.exp(-2*hh)
```


```python
1-(1+hh)*np.exp(-2*hh)
```


```python
np.exp(-2*hh)
```


```python
sy.expand()
```

1b1809ca0f5b9465d5edc147635af9fb02a3abe7
ipynb
Jupyter Notebook
polynomial-design/notebooks/L10-pole-placement-polynomial-approach.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2020-11-07T05:20:37.000Z
2020-12-22T09:46:13.000Z
polynomial-design/notebooks/L10-pole-placement-polynomial-approach.ipynb
alfkjartan/control-computarizado
5b9a3ae67602d131adf0b306f3ffce7a4914bf8e
MIT
2020-06-12T20:44:41.000Z
2020-06-12T20:49:00.000Z
polynomial-design/notebooks/L10-pole-placement-polynomial-approach.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2021-03-14T03:55:27.000Z
2021-03-14T03:55:27.000Z
Qwen/Qwen-72B
1. YES
2. YES