```python
from sympy import *
```


```python
x, u, y, v, Ax, Bu, Ay, Bv, Q, R, xf, dt, c1, c2 = symbols('x u y v Ax Bu Ay Bv Q R xf dt c1 c2')
```


```python
xm = x/2 + y/2 + dt/8*(Ax*x + Bu*u + c1) - dt/8*(Ay*y + Bv*v + c2)
um = (u+v)/2
l = (xm - xf)*Q*(xm - xf)/2 + um*R*um/2
```

Scalar results for stage cost l(xm,um) expansion


```python
diff(l,x)
```




    Q*(Ax*dt/4 + 1)*(dt*(Ax*x + Bu*u + c1)/8 - dt*(Ay*y + Bv*v + c2)/8 + x/2 - xf + y/2)/2




```python
diff(l,u)
```




    Bu*Q*dt*(dt*(Ax*x + Bu*u + c1)/8 - dt*(Ay*y + Bv*v + c2)/8 + x/2 - xf + y/2)/8 + R*(u/2 + v/2)/2




```python
diff(l,y)
```




    Q*(-Ay*dt/4 + 1)*(dt*(Ax*x + Bu*u + c1)/8 - dt*(Ay*y + Bv*v + c2)/8 + x/2 - xf + y/2)/2




```python
diff(l,v)
```




    -Bv*Q*dt*(dt*(Ax*x + Bu*u + c1)/8 - dt*(Ay*y + Bv*v + c2)/8 + x/2 - xf + y/2)/8 + R*(u/2 + v/2)/2




```python
diff(l,x,x)
```




    Q*(Ax*dt/4 + 1)*(Ax*dt + 4)/16




```python
diff(l,u,u)
```




    (Bu**2*Q*dt**2 + 16*R)/64




```python
diff(l,y,y)
```




    Q*(Ay*dt/4 - 1)*(Ay*dt - 4)/16




```python
diff(l,v,v)
```




    (Bv**2*Q*dt**2 + 16*R)/64




```python
diff(l,x,u)
```




    Bu*Q*dt*(Ax*dt/4 + 1)/16




```python
diff(l,x,y)
```




    -Q*(Ax*dt/4 + 1)*(Ay*dt - 4)/16




```python
diff(l,x,v)
```




    -Bv*Q*dt*(Ax*dt/4 + 1)/16




```python
diff(l,u,y)
```




    -Bu*Q*dt*(Ay*dt - 4)/64




```python
diff(l,u,v)
```




    (-Bu*Bv*Q*dt**2 + 16*R)/64




```python
diff(l,y,v)
```




    Bv*Q*dt*(Ay*dt/4 - 1)/16




```python

```

3191ede5263b9013816bec9fabf40d7c64ab4a2b
ipynb
Jupyter Notebook
dev_notebooks/First Order Hold (new derivation).ipynb
GathererA/TrajectoryOptimization.jl
c036b790555553b3477c7bebeaea118e17e43142
MIT
2020-05-01T16:16:08.000Z
2020-05-01T16:16:08.000Z
dev_notebooks/First Order Hold (new derivation).ipynb
GathererA/TrajectoryOptimization.jl
c036b790555553b3477c7bebeaea118e17e43142
MIT
dev_notebooks/First Order Hold (new derivation).ipynb
GathererA/TrajectoryOptimization.jl
c036b790555553b3477c7bebeaea118e17e43142
MIT
Qwen/Qwen-72B
1. YES
2. YES