# Finite Differences on Sparse Grids for Continuous-Time Heterogeneous Agent Models
## 4 Numerical Approach Using an Upwind Scheme
#### 4.1.4 Matrix Notation  
After linearizing and discretizing the HJB equation, we can easily formulate the resulting equations as a system for the value function. Note that we indicate vectors, i.e., one-dimensional arrays, by bold formatting and lower-case letters, whereas we indicate matrices by bold formatting and upper-case letters. By reordering the discretized HJB equation by its subscripts, we can setup the respective matrices to formulate the discretized HJB equation in case of a diffusion process to compute an iterate of the value function \(\mathbf{v}^{n}\) following the implicit scheme (17) by  
\[\frac{1}{\Delta}(\mathbf{v}^{n+1}-\mathbf{v}^{n})+\rho\mathbf{v}^{n+1}= \mathbf{u}^{n}+(\mathbf{A}^{n}+\mathbf{\Lambda})\mathbf{v}^{n+1} \tag{18}\]  
where \(\mathbf{A}^{n}\in\mathbb{R}^{m\times m}\) is the non-stochastic _drift matrix_ and \(\mathbf{\Lambda}\in\mathbb{R}^{m\times m}\) is the _intensity matrix_ which models the stochastic process for productivity \(z\). To define \(\mathbf{A}^{n}\) and \(\mathbf{\Lambda}\) more formally, one can denote the construction via finite difference operators and specific scalar matrix-row multiplications. Let us show this for Equation (17). We denote the row-wise vector matrix scalar multiplication, i.e., scalar multiplication of vector entry \(i\), \(1\leq i\leq m\) with matrix row \(i\) by \(\star\). To denote (17) using matrix notation (18), we have with \(\mathbf{D}\) for a finite difference operator and \(\mathbf{s}^{F}\), \(\mathbf{s}^{B}\) for the vector with entries (14)  
\[\mathbf{A}^{n}=(\mathbf{s}^{F,n})^{+}\star\mathbf{D}_{b}^{F}+(\mathbf{s}^{B,n })^{-}\star\mathbf{D}_{b}^{B} \tag{19}\]  
and  
\[\mathbf{\Lambda}=(\boldsymbol{\mu})^{+}\star\mathbf{D}_{z}^{F}+(\boldsymbol{ \mu})^{-}\star\mathbf{D}_{z}^{B}+\frac{1}{2}\sigma^{2}\star\mathbf{D}_{zz}, \tag{20}\]  
where the standard operations should be understood entry-wise. The finite difference matrices \(\mathbf{D}\), with sub- and superscripts indicating the taken derivative, are built using the standard full grid finite difference stencils; see any standard textbook such as [38] for a description. Note that, e.g., \(((\mathbf{s}^{F,n})^{+}\star\mathbf{D}_{b}^{F})\boldsymbol{\
u}^{n}\) is nothing else but \((\mathbf{D}_{b}^{F}\boldsymbol{\
u}^{n})\odot((\mathbf{s}^{F,n})^{+})\) where \(\odot\) denotes the entry-wise vector multiplication. By simple algebra, we obtain  
\[\underbrace{((\frac{1}{\Delta}+\rho)\mathbf{I}-\mathbf{A}^{n}-\mathbf{\Lambda })}_{\mathbf{B}}\mathbf{v}^{n+1}=\underbrace{\mathbf{u}^{n}+\frac{1}{\Delta} \mathbf{v}^{n}}_{\mathbf{r}^{n}=\mathbf{r}(\boldsymbol{\
u}^{n})} \tag{21}\]  
with identity matrix \(\mathbf{I}\in\mathbb{R}^{m\times m}\), i.e., we want to solve the linear system given by  
\[\mathbf{B}\boldsymbol{\
u}^{n+1}=\mathbf{r}^{n} \tag{22}\]  
with \(\mathbf{B}\in\mathbb{R}^{m\times m}\) and \(\mathbf{r}^{n}\in\mathbb{R}^{m}\). Note that \(\mathbf{\Lambda}\) does not depend on \(n\) and thus can be precomputed. As explained in Section 3.1, we use sparse grid finite difference operators operating on hierarchical coefficients. Since we require derivative approximations of the value function, we now denote \(\mathbf{v}\) as the vector storing hierarchical coefficients of the value function approximation. For the approximation of the utility function (5), we already have nodal values and thus \(\mathbf{u}\) now describes the vector containing nodal coefficients for the utility function.