# Partial differentiation of vector to find Jacobian (extended Kalman filter)

I am working through some coursework on self-tuning control and part of one of the questions requires the use of the extended Kalman filter for joint parameter and state estimation. For completeness, my system in state-space form is (skip to "My Problem" if you want):

$$x_{k+1} =A(\theta_{k})x_k + B(\theta_{k})u_k, \quad x_0=\bar{x_0}$$ $$y_k=C(\theta_{k})x_k+e_k$$

Where $u_k$ is the system input, $y_k$ is the system output and $e_k$ is an uncoloured white noise sequence. Note that I only need to consider this measurement noise, i.e. the $\Gamma, v_k, q_k$ that might also be included are all considered to be zero. Also, (omitting "$k$"s for ease of reading):

$$A(\theta)= \begin{bmatrix} 0 & -a_2 \\ 1 & -a_1 \end{bmatrix} \quad , \quad B(\theta)= \begin{bmatrix} b_1\\ b_0 \end{bmatrix} \quad , \quad C(\theta)= \begin{bmatrix} 0 & 1 \end{bmatrix}$$

Where $a_i$ and $b_j$ are the coefficients of the $A(q^{-1})$ and $B(q^{-1})$ polynomials of an ARX system.

The extended state-space form is then:

$$z_{k+1}=\mathcal{F}(z_k,u_k)$$ $$y_k=\mathcal{H}(z_k)+e_k$$

Where:

$$\mathcal{F}(z_k,u_k)= \begin{bmatrix} A(\theta_k)x_k+B(\theta_k)u_k\\ \theta_k \end{bmatrix} \quad, \quad \mathcal{H}(z_k)=C(\theta_k)x_k$$

The EKF prediction step is then: $$\hat{z}_{k|k-1}=\mathcal{F}(\hat{z}_{k-1|k-1},u_{k-1})$$ $$P_{k|k-1}=\mathcal{F}^*_{k-1}P_{k-1|k-1}\mathcal{F}^{*^T}_{k-1}$$

And the correction step is: $$L_k=P_{k|k-1}\mathcal{H}^{*^T}_{k}(\mathcal{H}^{*}_{k}P_{k|k-1}\mathcal{H}^{*^T}_{k}+\sigma^2_e)^{-1}$$ $$\hat{z}_{k|k}=\hat{z}_{k|k-1}+L_k[y_k-\mathcal{H}(\hat{z}_{k|k})]$$ $$P_k=(I-L_k\mathcal{H}^{*}_{k})P_{k|k-1}$$

Where: $$\mathcal{F}^*_{k-1}=\begin{bmatrix} A(\theta_{k-1|k-1}) & R_1\\ 0 & I \end{bmatrix} \quad , \quad \mathcal{H}^*_{k}=\begin{bmatrix} C(\hat{\theta}_{k|k-1}) & R_2 \end{bmatrix}$$

With the Jacobians $$R_1=\frac{\partial[A(\theta_k)x_k+B(\theta_k)u_k]}{\partial\theta_k}\bigg|_{\hat{z}_{k-1|k-1}}$$ $$R_2=\frac{\partial C(\theta_k)}{\partial\theta_k}\bigg|_{\hat{\theta}_{k|k-1}}$$

### My Problem

I have performed the partial differentiation to find the Jacobians $R_1$ and $R_2$, and thus tried to build $\mathcal{H}^{*}_{k}$ and $\mathcal{F}^{*}_{k}$, but I have made an error somewhere that I cannot find! I have:

$$R_1=\begin{bmatrix} 0 & -x_{2,k}\\ -x_{2,k} & 0\\ 0 & u_k\\ u_k & 0 \end{bmatrix}\bigg|_{\hat{z}_{k-1|k-1}} \quad , \quad R_2=\begin{bmatrix} 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 \end{bmatrix}\bigg|_{\hat{\theta}_{k|k-1}}$$

But this $R_2$ does not allow the construction of $\mathcal{H}^*_{k}$ since it and $C(\theta_k)$ are of different size. (I'm not very familiar with partial differentiation of vectors, so it's entirely possible I have made errors in finding both $R_1$ and $R_2$!)

-
Maybe too much about the background knowledge. If it is merely a question on Jacobian, see en.wikipedia.org/wiki/Jacobian_matrix_and_determinant – Shiyu May 3 '11 at 12:03
Thanks - I essentially followed the method set-out at the Wikipedia page (I already have to construct Jacobians for my non-linear systems analysis course). But I don't understand how the Jacobian of a 1x2 (row) vector wrt a 4x1 (column) vector can have anything other than 8 elements. The required form is a 1x4 row vector though. – IainCunningham May 3 '11 at 13:15
I heard from my lecturer by e-mail, required forms are $R_1 \in \mathbb{R}^{2\times 4}$ (I understand having re-read the Wikipedia page that my previous attempt at this was correct, but transposed) and $R_2 \in \mathbb{R}^{1\times 4}$. I also understand that $R_2$ is a zero matrix since it does not contain elements of $\theta$, but I don't understand why it is a single row instead of 2. – IainCunningham May 3 '11 at 13:23
OK, mystery solved. There is an error in the text that I have used for my reference for the EKF for calculating $R_2$. The correct version is of the form: $R_2=\frac{\partial [C(\theta_k)x_{k|k-1}]}{\partial\theta_k}\bigg|_{\hat{\theta}_{k|k-1}}$ this then gives the 1x4 result that I'm after. The answer is therefore that there was a typo in my reference material! (If someone can tell me how to mark this answered I will do so!) – IainCunningham May 3 '11 at 13:41