From 31eb457614aed3b85602bc9fa8096b06b587edab Mon Sep 17 00:00:00 2001 From: Janita Willumsen Date: Sat, 9 Sep 2023 17:26:30 +0200 Subject: [PATCH 1/4] Fixed the initial condition of forward sweep --- latex/problems/problem6.tex | 1 + 1 file changed, 1 insertion(+) diff --git a/latex/problems/problem6.tex b/latex/problems/problem6.tex index 0a6725c..36efa4f 100644 --- a/latex/problems/problem6.tex +++ b/latex/problems/problem6.tex @@ -17,6 +17,7 @@ Following Thomas algorithm for gaussian elimination, we first perform a forward \State $n \leftarrow$ length of $\vec{b}$ \State $\vec{\hat{b}}$, $\vec{\hat{g}} \leftarrow$ vectors of length $n$. \State $\hat{b}_{1} \leftarrow b_{1}$ \Comment{Handle first element in main diagonal outside loop} + \State $\hat{g}_{1} \leftarrow g_{1}$ \For{$i = 2, 3, ..., n$} \State $d \leftarrow \frac{a_{i}}{\hat{b}_{i-1}}$ \Comment{Calculating common expression} \State $\hat{b}_{i} \leftarrow b_{i} - d \cdot c_{i-1}$ From 5cc45d0d02865d0a7d97ad7a88f3021621591e97 Mon Sep 17 00:00:00 2001 From: Janita Willumsen Date: Sat, 9 Sep 2023 17:27:04 +0200 Subject: [PATCH 2/4] Finish algo and FLOPs --- latex/problems/problem9.tex | 57 ++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/latex/problems/problem9.tex b/latex/problems/problem9.tex index e5bd862..5b93eae 100644 --- a/latex/problems/problem9.tex +++ b/latex/problems/problem9.tex @@ -1,3 +1,58 @@ \section*{Problem 9} -% Show the algorithm, then calculate FLOPs, then link to relevant files +\subsection*{a)} +% Specialize algorithm +The special algorithm does not require the values of all $a_{i}$, $b_{i}$, $c_{i}$. +We find the values of $\hat{b}_{i}$ from simplifying the general case +\begin{align*} + \hat{b}_{i} &= b_{i} - \frac{a_{i} \cdot c_{i-1}}{\hat{b}_{i-1}} \\ + \hat{b}_{i} &= 2 - \frac{1}{\hat{b}_{i-1}} +\end{align*} +Calculating the first values to see a pattern +\begin{align*} + \hat{b}_{1} &= 2 \\ + \hat{b}_{2} &= 2 - \frac{1}{2} = \frac{3}{2} \\ + \hat{b}_{3} &= 2 - \frac{1}{\frac{3}{2}} = \frac{4}{3} \\ + \hat{b}_{4} &= 2 - \frac{1}{\frac{4}{3}} = \frac{5}{4} \\ + \vdots & \\ + \hat{b}_{i} &= \frac{i+1}{i} && \text{for $i = 1, 2, ..., n$} +\end{align*} + + +\begin{algorithm}[H] + \caption{Special algorithm}\label{algo:special} + \begin{algorithmic} + \Procedure{Forward sweep}{$\vec{b}$} + \State $n \leftarrow$ length of $\vec{b}$ + \State $\vec{\hat{b}}$, $\vec{\hat{g}} \leftarrow$ vectors of length $n$. + \State $\hat{b}_{1} \leftarrow 2$ \Comment{Handle first element in main diagonal outside loop} + \State $\hat{g}_{1} \leftarrow g_{1}$ + \For{$i = 2, 3, ..., n$} + \State $\hat{b}_{i} \leftarrow \frac{i+1}{i}$ + \State $\hat{g}_{i} \leftarrow g_{i} + \frac{\hat{g}_{i-1}}{\hat{b}_{i-1}}$ + \EndFor + \Return $\vec{\hat{b}}$, $\vec{\hat{g}}$ + \EndProcedure + + \Procedure{Backward sweep}{$\vec{\hat{b}}$, $\vec{\hat{g}}$} + \State $n \leftarrow$ length of $\vec{\hat{b}}$ + \State $\vec{v} \leftarrow$ vector of length $n$. + \State $v_{n} \leftarrow \frac{\hat{g}_{n}}{\hat{b}_{n}}$ + \For{$i = n-1, n-2, ..., 1$} + \State $v_{i} \leftarrow \frac{\hat{g}_{i} + v_{i+1}}{\hat{b}_{i}}$ + \EndFor + \Return $\vec{v}$ + \EndProcedure + \end{algorithmic} +\end{algorithm} + + +\subsection*{b)} +% Find FLOPs +For every iteration of i in forward sweep we have 2 division, and 2 additions, resulting in $4(n-1)$ FLOPs. +For backward sweep we have 1 division, and for every iteration of i we have 1 addition, and 1 division, resulting in $2(n-1)+1$ FLOPs. +Total FLOPs for the special algorithm is $6(n-1)+1$. + + +\subsection*{)} +% Code From b4325ec18530cd636f3960129467618d9738dcb5 Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 10 Sep 2023 12:50:18 +0200 Subject: [PATCH 3/4] Remove loose subsection --- latex/problems/problem9.tex | 3 --- 1 file changed, 3 deletions(-) diff --git a/latex/problems/problem9.tex b/latex/problems/problem9.tex index 5b93eae..23beec4 100644 --- a/latex/problems/problem9.tex +++ b/latex/problems/problem9.tex @@ -53,6 +53,3 @@ For every iteration of i in forward sweep we have 2 division, and 2 additions, r For backward sweep we have 1 division, and for every iteration of i we have 1 addition, and 1 division, resulting in $2(n-1)+1$ FLOPs. Total FLOPs for the special algorithm is $6(n-1)+1$. - -\subsection*{)} -% Code From ca774e434fe80890b3072e9ffd11dc1382e36204 Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 10 Sep 2023 12:51:46 +0200 Subject: [PATCH 4/4] Fix spelling --- latex/problems/problem9.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/latex/problems/problem9.tex b/latex/problems/problem9.tex index 23beec4..5bbd5ea 100644 --- a/latex/problems/problem9.tex +++ b/latex/problems/problem9.tex @@ -49,7 +49,7 @@ Calculating the first values to see a pattern \subsection*{b)} % Find FLOPs -For every iteration of i in forward sweep we have 2 division, and 2 additions, resulting in $4(n-1)$ FLOPs. +For every iteration of i in forward sweep we have 2 divisions, and 2 additions, resulting in $4(n-1)$ FLOPs. For backward sweep we have 1 division, and for every iteration of i we have 1 addition, and 1 division, resulting in $2(n-1)+1$ FLOPs. Total FLOPs for the special algorithm is $6(n-1)+1$.