=============== Applying Pivots [TOC] =============== In general the LU factorization requires pivoting. The pivot vector ---- LATEX --------------------------------------------------------------------- p = (p_0, \dots, p_k) -------------------------------------------------------------------------------- represents a $k \times k$ permutation matrix $P$ such that ---- LATEX --------------------------------------------------------------------- P A = L U -------------------------------------------------------------------------------- In this exercise you are supposed to implement a function `dlaswp` to apply $P$ and $P^{-1}$ to a matrix $A$: - perform the operation $B \leftarrow P A$ or - the operation $B \leftarrow P^{-1}A$. Furthermore the function should be implemented such that only a sub-range of $p$ is used. This depends on two integer bounds $k_0$ and $k_1$: - if $k_0 < k_1$ it applies the permutation represented by $p_{k_0},\dots,p_{k_1}$ and - otherwise the permutation represented by $p_{k_1},\dots,p_{k_0}$. Algorithm ========= The function receives a matrix $A$ with $n$ columns, a pivot vector $p$ and the two indices $k_0$ and $k_1$. The number of rows in $A$ and the length of $p$ are not explicitly specified. The function implements the following algorithm: - for $k = k_0, \dots, k_1$ - if $k \neq p_k$ - interchange in $A$ rows with index $k$ and $p_k$ Skeleton for simple Example =========================== :import: session13/simple_dlaswp_ex.c [fold] Exercise ======== - Make yourself familiar with the structure of the program. Compile and run it: - For testing the *col major case* compile it with ---- SHELL(path=session13) ------------------------------------------------- gcc -Wall -std=c11 -o simple_dlaswp_ex simple_dlaswp_ex.c ---------------------------------------------------------------------------- - For testing the *row major case* compile it with ---- SHELL(path=session13) ------------------------------------------------- gcc -Wall -std=c11 -o simple_dlaswp_ex -DCOLMAJOR=0 simple_dlaswp_ex.c ---------------------------------------------------------------------------- - What should the program print once function `dlaswp` is implemented? - Implement function `dlaswp` and test it.