# Solution {-}

PVA model


```python
from sympy import Matrix, symbols, sqrt, eye, integrate
from lib.vanloan import numeval

q, dt = symbols('q dt')

F = Matrix([[0, 1, 0],
            [0, 0, 1],
            [0, 0, 0]])

G = Matrix([[0],
            [0],
            [sqrt(q)]])

phi = eye(3) + F*dt + (F*dt)**2/2
phi
```




$\displaystyle \left[\begin{matrix}1 & dt & \frac{dt^{2}}{2}\\0 & 1 & dt\\0 & 0 & 1\end{matrix}\right]$




```python
# Process noise
Q = integrate(phi@G@G.T@phi.T, dt)
Q
```




$\displaystyle \left[\begin{matrix}\frac{dt^{5} q}{20} & \frac{dt^{4} q}{8} & \frac{dt^{3} q}{6}\\\frac{dt^{4} q}{8} & \frac{dt^{3} q}{3} & \frac{dt^{2} q}{2}\\\frac{dt^{3} q}{6} & \frac{dt^{2} q}{2} & dt q\end{matrix}\right]$



Numerical example


```python
from numpy import array, zeros, arange
import matplotlib.pyplot as plt

# System parameters
dt = 0.1
q = 1

F = array([[0, 1, 0],
           [0, 0, 1],
           [0, 0, 0]])

G = array([[0],
           [0],
           [sqrt(q)]])

# Numerical evaluation
[phi, Q_true] = numeval(F, G, dt)

# Process noise approximation
Q_approx = array([[0, 0, 0],
                  [0, 0, 0],
                  [0, 0, q*dt]])

# Plot vectors
var_true = []
var_approx = []

# Initial covariance
P = zeros([3, 3])
for i in range(0, 200):
    P = phi@P@phi.T + Q_true
    var_true.append(P)

# Initial covariance
P = zeros([3, 3])
for i in range(0, 200):
    P = phi@P@phi.T + Q_approx
    var_approx.append(P)

# Difference at step 200
print(var_true[199] - var_approx[199])
```

    [[1.99333335e+03 1.99500000e+02 9.98333333e+00]
     [1.99500000e+02 1.99666667e+01 1.00000000e+00]
     [9.98333333e+00 1.00000000e+00 0.00000000e+00]]


e6656a7073886e2b8a508b0f733ded7d3b045eeb
ipynb
Jupyter Notebook
Problem 4.2.ipynb
mfkiwl/GMPE340
3602b8ba859a2c7db2cab96862472597dc1ac793
MIT
Problem 4.2.ipynb
mfkiwl/GMPE340
3602b8ba859a2c7db2cab96862472597dc1ac793
MIT
Problem 4.2.ipynb
mfkiwl/GMPE340
3602b8ba859a2c7db2cab96862472597dc1ac793
MIT
Qwen/Qwen-72B
1. YES
2. YES