### Update inverse problems exercise

parent 417df820
 %% Cell type:markdown id: tags: # Exercises: inverse problems The *Volterra operator* \$V\$ is defined by \$\$V f(x) = \int_{x_0}^x f(x) \,dx.\$\$ A simple discrete approximation is \$\$(V f)_i = h \sum_{j=0}^i f_j,\$\$ where \$f_j = f(x_j)\$ are the values of \$f\$ at equidistant sampling points \$(x_j)_{j=1}^{N-1}\$ with distance \$h = x_1 - x_0\$. As a matrix, this can simply be written as \$\$V = h \begin{pmatrix} 1 & 0 & 0 & 0 & \ldots & 0 \\ 1 & 1 & 0 & 0 & \ldots & 0 \\ 1 & 1 & 1 & 0 & \ldots & 0 \\ \vdots & & & \ddots & & \\ 1 & 1 & 1 & 1 & \ldots & 1 \end{pmatrix}\$\$ - Implement the Volterra operator with a parameter `h :: Double` as an instance of the `Operator` type class from the lecture, but with the `Arr` type alias replaced by ```haskell type Arr r = Array r DIM1 Double ``` Though it is possible to do this using a matrix formulation and e.g. `mmultS`, this unneccessarily inefficient. A better possibility is to note the connection between the Volterra operator and Haskell's `scanl` function. Moreover, there is an implementation of `scanl` for unboxed `Vector`s from `Data.Vector.Unboxed` (*not* HMatrix's `Numeric.Container`) as well as conversion functions `toUnboxed` and `fromUnboxed` for Repa `U` arrays to and from these `Vector`s. Use these to implement the operator. - Implement the Volterra operator with parameter `h :: Double` and its adjoint. Though it is possible to do this using a matrix formulation and e.g. `mmultS`, this unneccessarily inefficient. A better possibility is to note the connection between the Volterra operator and Haskell's `scanl` function. Moreover, there is an implementation of `scanl` for unboxed `Vector`s from `Data.Vector.Unboxed` as well as O(1) conversion functions `toUnboxed` and `fromUnboxed` for Repa `U` arrays to and from these `Vector`s. Use these to implement the operator. *Note*: The adjoint (i.e. transpose) of the operator can be found most easily by noting the similarity between the Volterra matrix above and its transpose: the adjoint simply proceeds in the opposite direction. - Use the regularized CG implementation from the lecture to compute regularized *derivatives* of the functions \$\$\begin{align} f_1(x) &= e^{-x^2} \\ f_2(x) &= \text{sgn}(x) = \begin{cases} -1 & x < 0 \\ 1 & x \geq 0 \end{cases} \end{align}\$\$ sampled at 200 points between -2 and 2 and distorted by random noise between -0.1 and 0.1. The CG tolerance should be set suffieciently low (e.g. 1e-6). - Plot the results together with the noisy functions and, in the case of \$f_1\$, the analytical derivative. %% Cell type:code id: tags: ``` haskell ``` ... ...