# Rocket Model Derrivation


```python
from sympy import *
init_printing()
```


```python
# State
x,y,vx,vy,theta,omega,m = symbols('x y vx vy theta, omega, m')
r = Matrix([x, y]) # Position
v = Matrix([vx, vy]) # Velocity
s = Matrix([r, v,[theta], [omega], [m]])

# Costate
lx,ly,lvx,lvy,ltheta,lomega,lm = symbols('lx ly lvx lvy ltheta lomega, lm')
lr = Matrix([lx, ly])
lv = Matrix([lvx,lvy])
l  = Matrix([lr, lv, [ltheta], [lomega], [lm]])

# Parametres
c1, c2, c3, g, a = symbols('c1 c2 c3 g a')
# Control
u, ut1, ut2 = symbols('u ut1 ut2')
c  = Matrix([u, ut1, ut2])

# Fullstate
fs = Matrix([s,l])
```


```python
# State dynamics
dx     = vx
dy     = vy
dvx    = c1*u/m*ut1 - 1/2*rho*
dvy    = c1*u/m*ut2 - g
dtheta = omega
domega = -c1/c3*u/m*(ut1*cos(theta) + ut2*sin(theta))
dm     = -c1/c2*u
ds     = Matrix([dx, dy, dvx, dvy, dtheta, domega, dm])
```


```python
# Homotopic Cost Lagrangian
L = a*c1/c2*u+(1-a)*c1**2/c2*u**2
```


```python
# Hamiltonian
H = l.dot(ds) + L
print cse(H)
```

    ([(x0, 1/c2), (x1, c1*u*x0), (x2, c1*u/m)], [a*x1 + c1**2*u**2*x0*(-a + 1) - lm*x1 + ltheta*omega + lvx*ut1*x2 + lvy*(-g + ut2*x2) + lx*vx + ly*vy - lomega*x2*(ut1*cos(theta) + ut2*sin(theta))/c3])



```python
# Costate dynamics
dl = -Matrix([diff(H, i) for i in s])
```


```python
# Fullstate dynamics
dfs = Matrix([ds, dl])
```


```python
lax = lvx - lomega /c3*cos(theta)
lay = lvy + lomega /c3*sin(theta)
la  = sqrt(lax**2 + lay**2)
ut1s = -lax / la
ut2s = -lay / la
uts = Matrix([ut1s, ut2s])
S = 1 - lm - la *c2 /m
us = 1/2/c1/(1-a)*(lm+la*c2/m-a)
us = (lm + c2/m * la - a)/(2*(1-a)*c1)
print cse(Matrix([ut1s, ut2s, S, us]))
```

    ([(x0, lomega/c3), (x1, x0*cos(theta)), (x2, x0*sin(theta)), (x3, sqrt((lvx - x1)**2 + (lvy + x2)**2)), (x4, 1/x3), (x5, c2*x3/m)], [Matrix([
    [                x4*(-lvx + x1)],
    [                x4*(-lvy - x2)],
    [                  -lm - x5 + 1],
    [(-a + lm + x5)/(c1*(-2*a + 2))]])])



```python

```

e02a804d71350e6a94356e31b3adec8b5973c951
ipynb
Jupyter Notebook
src/Notebook/Rocket_Model.ipynb
cisprague/Astro.IQ
4e2df67ddc0ffc518c4f65d0bf558380e6a7c6d1
MIT
2017-11-21T18:25:52.000Z
2022-03-16T18:18:41.000Z
src/Notebook/Rocket_Model.ipynb
siddharthdeore/Astro.IQ
4e2df67ddc0ffc518c4f65d0bf558380e6a7c6d1
MIT
2017-08-16T19:51:03.000Z
2017-11-14T21:03:18.000Z
src/Notebook/Rocket_Model.ipynb
siddharthdeore/Astro.IQ
4e2df67ddc0ffc518c4f65d0bf558380e6a7c6d1
MIT
2019-07-08T23:10:11.000Z
2022-03-15T15:32:53.000Z
Qwen/Qwen-72B
1. YES
2. YES