```python
from sympy import init_session, init_printing, Matrix
init_session()
init_printing()
```

    IPython console for SymPy 0.7.6 (Python 2.7.8-64-bit) (ground types: python)
    
    These commands were executed:
    >>> from __future__ import division
    >>> from sympy import *
    >>> x, y, z, t = symbols('x y z t')
    >>> k, m, n = symbols('k m n', integer=True)
    >>> f, g, h = symbols('f g h', cls=Function)
    >>> init_printing()
    
    Documentation can be found at http://www.sympy.org


## Twiss Matrices


```python
B, Bi, R, mu     = symbols('B, B_{inv}, R, mu')
a0, a1, b0, b1   = symbols('alpha_0, alpha_1, beta_0, beta_1', real=True, positive=True)
# V, h, phi, eta, R, C = symbols('V, h, phi, eta, R, C')
# z, dp                = symbols('z, dp', real=True)
# Hc                   = symbols('H_c')


B  = Matrix([[1/sqrt(b0), 0], [a0/sqrt(b0), sqrt(b0)]])
R  = Matrix([[cos(mu), sin(mu)], [-sin(mu), cos(mu)]])
Bi = Matrix([[sqrt(b1), 0], [-a1/sqrt(b1), 1/sqrt(b1)]])
```


```python
expand_trig(simplify(trigsimp(Bi * R * B)))
```


```python
simplify(Bi * Matrix([[1, 0],[0, 1]]) * B)
```


```python
simplify(Bi * Matrix([[0, 1],[-1, 0]]) * B)
```

## Hamiltonian


```python
e, beta, c           = symbols('e, beta, c')
V, h, phi, eta, R, C = symbols('V, h, phi, eta, R, C')
z, dp                = symbols('z, dp', real=True)
Hc                   = symbols('H_c')

zs = C/h/2.

def H(z, dp):
    return -eta*beta*c*dp**2 + e*V/C * cos(h*z/R + phi)
H(z, dp)
```


```python
def ps(z):
    return solve(Eq(H(z,dp), 0), dp)[0]
ps(z)
```


```python
def ps(z):
    return sqrt(cos(z))
#     return -sqrt(e*V/(eta*beta*c*C) * h*z/R)
#     return -sqrt(e*V/(eta*beta*c*C) * cos(h*z/R+phi))
ps(z)
```


```python
integrate(ps(z), (z, -zs, zs))
```

b455c62a346add87dc88637d50975f99c1b88f0d
ipynb
Jupyter Notebook
Auxiliaries.ipynb
like2000/PyCOBRA
8cbac23da295b5d3b9e9a2b6c1560173f929eea1
MIT
Auxiliaries.ipynb
like2000/PyCOBRA
8cbac23da295b5d3b9e9a2b6c1560173f929eea1
MIT
Auxiliaries.ipynb
like2000/PyCOBRA
8cbac23da295b5d3b9e9a2b6c1560173f929eea1
MIT
Qwen/Qwen-72B
1. YES
2. YES