9 Commits

Author SHA1 Message Date
5147389217 Merge branch 'main' into coryab/implement-problem-5 2023-09-10 13:05:56 +02:00
85e469f101 Stuff 2023-09-10 12:58:56 +02:00
439bcefcb4 Merge pull request #20 from FYS3150-G2-2023/9-solve-problem-9
9 solve problem 9
2023-09-10 12:57:06 +02:00
02302e1255 Merge pull request #19 from FYS3150-G2-2023/6-solve-problem-6
Finished exercise 6
2023-09-10 12:56:54 +02:00
ca774e434f Fix spelling 2023-09-10 12:51:46 +02:00
b4325ec185 Remove loose subsection 2023-09-10 12:50:18 +02:00
46d3a78767 Implement problem 5 and a bit more 2023-09-10 12:41:15 +02:00
Janita Willumsen
5cc45d0d02 Finish algo and FLOPs 2023-09-09 17:27:04 +02:00
Janita Willumsen
31eb457614 Fixed the initial condition of forward sweep 2023-09-09 17:26:30 +02:00
7 changed files with 61 additions and 6 deletions

BIN
latex/assignment_1.pdf Normal file

Binary file not shown.

View File

@@ -80,7 +80,7 @@
\begin{document} \begin{document}
\title{Project 1} % self-explanatory \title{Project 1} % self-explanatory
\author{Cory Balaton \& Janita Willumsen} % self-explanatory \author{Cory Alexander Balaton \& Janita Ovidie Sandtrøen Willumsen} % self-explanatory
\date{\today} % self-explanatory \date{\today} % self-explanatory
\noaffiliation % ignore this, but keep it. \noaffiliation % ignore this, but keep it.
@@ -107,4 +107,6 @@
\input{problems/problem9} \input{problems/problem9}
\input{problems/problem10}
\end{document} \end{document}

View File

@@ -40,5 +40,5 @@ Using the values that we found for $c_1$ and $c_2$, we get
\begin{align*} \begin{align*}
u(x) &= -e^{-10x} + (e^{-10} - 1) x + 1 \\ u(x) &= -e^{-10x} + (e^{-10} - 1) x + 1 \\
&= 1 - (1 - e^{-10}) - e^{-10x} &= 1 - (1 - e^{-10})x - e^{-10x}
\end{align*} \end{align*}

View File

@@ -1,6 +1,6 @@
\section*{Problem 5} \section*{Problem 5}
\subsection*{a)} \subsection*{a \& b)}
\subsection*{b)} $n = m - 2$ since when solving for $\vec{v}$, we are finding the solutions for all the points that are in between the boundaries and not the boundaries themselves. $\vec{v}^*$ on the other hand includes the boundary points.

View File

@@ -17,6 +17,7 @@ Following Thomas algorithm for gaussian elimination, we first perform a forward
\State $n \leftarrow$ length of $\vec{b}$ \State $n \leftarrow$ length of $\vec{b}$
\State $\vec{\hat{b}}$, $\vec{\hat{g}} \leftarrow$ vectors of length $n$. \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{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$} \For{$i = 2, 3, ..., n$}
\State $d \leftarrow \frac{a_{i}}{\hat{b}_{i-1}}$ \Comment{Calculating common expression} \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}$ \State $\hat{b}_{i} \leftarrow b_{i} - d \cdot c_{i-1}$
@@ -43,4 +44,4 @@ Following Thomas algorithm for gaussian elimination, we first perform a forward
Counting the number of FLOPs for the general algorithm by looking at one procedure at a time. Counting the number of FLOPs for the general algorithm by looking at one procedure at a time.
For every iteration of i in forward sweep we have 1 division, 2 multiplications, and 2 subtractions, resulting in $5(n-1)$ FLOPs. For every iteration of i in forward sweep we have 1 division, 2 multiplications, and 2 subtractions, resulting in $5(n-1)$ FLOPs.
For backward sweep we have 1 division, and for every iteration of i we have 1 subtraction, 1 multiplication, and 1 division, resulting in $3(n-1)+1$ FLOPs. For backward sweep we have 1 division, and for every iteration of i we have 1 subtraction, 1 multiplication, and 1 division, resulting in $3(n-1)+1$ FLOPs.
Total FLOPs for the general algorithm is $8(n-1)+1$. Total FLOPs for the general algorithm is $8(n-1)+1$.

View File

@@ -1,3 +1,55 @@
\section*{Problem 9} \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 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$.

View File