In our case when We use IEEE Standard 754, mantissa is 53 bits long with first bit omitted as it is always equal to '1', so We technicaly work with 52 bits mantissa which makes the machine epsilion equal to: $2^{-52}=2.220446\mathrm{e}{-16}$
Since macheps is connected to IEEE754 standard it is always equal to the same number, which means that We can safely compare results from different machines without worrying about their individual errors.
Code above shifts macheps one bit to the right each iteration (by dividing by 2), it ends when We run out of mantissa bits which renders us unable to save smaller number. Due to underflow the value of macheps becomes 0 and therefore 1.0 > (macheps / 2) > 1.0 will become false.
We will denote rows as '$w_i$' where 'i' is number of the row.
\subsubsection{Zeroing first column}
We start transforming the system by "zeroing" elements in first column excluding first row element. We do it by multiplying first row by $l_{i1}$, where:
Then We swap this row with k-th row. Since the matrix We use is assumed to be nonsingular then $|{a_{ik}^{k}}| \neq0$ will be always true. After that We continue with the Gaussian elimination method.
Then We need to compare the results of iterations plotting norm of the solution error versus the iteration number \textbf{k}, untill We get accuracy better than $10^{-10}$.
Itertaive methods differ from the Gauss elimination method since they are iterative, which means that our solution will improve with each iteration. Building on that We can cnclude that the number of iterations will depend on what accuracy We want to achieve. Since We are using iterative method We don't have the guarantee of how many iterations will be neeeded before We reach the solution,
If We assume that diagonal entries of matrix \textbf{A} are nonzero, then matrix \textbf{D} is nonsingular therefore We can propose such an iterative method:
Thanks to this We can do those computations in paraller, totally or partially if We are using a computer that enables a parallelization of the computations.
Since matrix \textbf{L} is subdiagonal, provided that We organse the calculation of elements of the vector $x^{(i_1)}$ in a proper way, it does not hurt that $x^{(i_1)}$ is on the right side of the equation.
In order to organise the calculation in the correct way We:
As opposed to Jacobi's method, Gauss-Seidel method computations must be performed sequentially. Every subsequent scalar equations uses results from the computation of the previous equations.
\paragraph{Converging}
Gauss-Seidel method is convergent if the matrix \textbf{A} is strongly row or column diagonnaly dominant. If the matrix is symmetric, the method is also convergent if the matrix \textbf{A} is positive definite. This method is also usually faster convergent compared to Jacobi's method.
Where $\delta$ is an assumed tolerance, (in our case $10^{-10}$). What We are really interested in though is whether the solution of the system of equation has required accuracy. If We want to check that We can additionaly check (higher level, more computationally demanding test):
Where $\delta_2$ is an assumed tolerance. If this test is not passed then We can diminish the value of $\delta_2$ and continue with the iterations. Value of $\delta_2$ can not be too small since We are limited by the numerical errors.
For system of equations We got in this task We got following results:
\\
Without the change in demanded tolerance:
\[ x =\left(\begin{array}{cc}
-0.076776098668341 \\
2.105784262642568 \\
0.395344797635474 \\
0.397776619764909
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=1.154375287358407e-10\]
We managed to do this in \textbf{38} iterations of our loop, and the demanded tolerance did not change. (This required small change in code where We ommited the part of code responsible for changing demandedTolerance if $\|\mathbf{A}x-b \| > \delta_2)$ )
With the change in demanded tolerance:
\[ x =\left(\begin{array}{cc}
-0.076776098668341 \\
2.105784262642568 \\
0.395344797635474 \\
0.397776619764909
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=5.770361548895147e-11\]
We got this result in \textbf{37} iterations and demanded tolerance was equal to $2*10^{-10}$
Compared to matlab function
\[ x_{matlab}=\left(\begin{array}{cc}
-0.076776098662498 \\
2.105784262636790 \\
0.395344797637659 \\
0.397776619767240 \\
\end{array}\right)
\]
Matlab error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=4.070144838902081e-15\]
For data from task 2a We got: \\
Without change in demanded tolerance:
\[ x_a =\left(\begin{array}{cc}
-0.930024655108186 \\
-1.223407298660663 \\
-1.273530574212508 \\
-1.230517757317628 \\
-1.151356031082747 \\
-1.056883669273682 \\
-0.952628310081466 \\
-0.834334594312996 \\
-0.683708806198363 \\
-0.450125157620744 \\
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=6.955194519943778e-11\]
We managed to do this in \textbf{59} iterations of our loop, and the demanded tolerance did not change.
With change in demanded tolerance:
\[ x_a =\left(\begin{array}{cc}
-0.930024655104470 \\
-1.223407298653515 \\
-1.273530574202540 \\
-1.230517757305602 \\
-1.151356031069692 \\
-1.056883669260597 \\
-0.952628310069469 \\
-0.834334594303006 \\
-0.683708806191233 \\
-0.450125157617020 \\
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=1.699812218689508e-10\]
We managed to do this in \textbf{57} iterations of our loop, and the demanded tolerance changed to $4*10^{-10}$
Compared to matlab $ A \ b $ function
\[ x_{matlab}=\left(\begin{array}{cc}
-0.930024655110760 \\
-1.223407298665612 \\
-1.273530574219411 \\
-1.230517757325956 \\
-1.151356031091789 \\
-1.056883669282743 \\
-0.952628310089775 \\
-0.834334594319914 \\
-0.683708806203301 \\
-0.450125157623323 \\
\end{array}\right)
\]
Matlab error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=3.662053438817790e-15\]
For Matrix and Vector from task 2b) error of
\[\| x^{(i+1)}- x^{(i)}\|\]
grew to infinity, therefore We could never achieve demanded tolerance, therefore the program executed infinite loop.
\subsubsection{Minimizing the demanded error}
We tried to minimize the demanded error using this steps:
\begin{enumerate}
\item We copied error from matlab function and pasted it into demanded tolerance.
\item If We did not get infinite loop We copied the newly acquired error and pasted it into demanded tolerance.
\item If We got inifinite loop We used the previous error as "minimal" demanded error.
\end{enumerate}
\paragraph{For original system of equations:}
We managed to get results with error as low as $1.776356839400250e-15$ with demanded tolerance = $3.202372833989376e-15$ for lower values program went into infinite loop.
Results for demanded tolerance = $3.202372833989376e-15$
For given matrix:
\[ x =\left(\begin{array}{cc}
-0.076776098662498 \\
2.105784262636790 \\
0.395344797637659 \\
0.397776619767240
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=3.108624468950438e-15\]
We got this result in \textbf{53} iterations and demanded tolerance did not change.
\paragraph{For task 2a) system of equations:}
We managed to get results with error as low as
\[3.108624468950438e-15\] with demanded tolerance:
\[3.202372833989376e-15\]
for lower values program went into infinite loop.
For demanded tolerance = $3.202372833989376e-15$:
Results for 2a) system of equation
\[ x_a =\left(\begin{array}{cc}
-0.930024655110760 \\
-1.223407298665613 \\
-1.273530574219411 \\
-1.230517757325955 \\
-1.151356031091788 \\
-1.056883669282743 \\
-0.952628310089775 \\
-0.834334594319914 \\
-0.683708806203301 \\
-0.450125157623323
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=3.108624468950438e-15\]
We managed to do this in \textbf{84} iterations of our loop, and the demanded tolerance did not change.
We managed to achieve slightly better (as in, the error was smaller) results than Matlab custom function.
\paragraph{Table}
\begin{center}
\resizebox{\textwidth}{!}{
\begin{tabular}{||c c c c c c||}
\hline
system of equations & method & demanded tolerance & final demanded tolerance & error & iterations \\
For system of equations We got in this task We got following results:
\\
Without the change in demanded tolerance:
\[ x =\left(\begin{array}{cc}
-0.076776098668341 \\
2.105784262642568 \\
0.395344797635474 \\
0.397776619764909
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=1.154375287358407e-10\]
We managed to do this in \textbf{38} iterations of our loop, and the demanded tolerance did not change. (This required small change in code where We ommited the part of code responsible for changing demandedTolerance if $\|\mathbf{A}x-b \| > \delta_2)$ )
With the change in demanded tolerance:
\[ x =\left(\begin{array}{cc}
-0.076776098668341 \\
2.105784262642568 \\
0.395344797635474 \\
0.397776619764909
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=5.770361548895147e-11\]
We got this result in \textbf{37} iterations and demanded tolerance was equal to $2*10^{-10}$
Compared to matlab function
\[ x_{matlab}=\left(\begin{array}{cc}
-0.076776098662498 \\
2.105784262636790 \\
0.395344797637659 \\
0.397776619767240 \\
\end{array}\right)
\]
Matlab error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=4.070144838902081e-15\]
For data from task 2a We got: \\
Without change in demanded tolerance:
\[ x_a =\left(\begin{array}{cc}
-0.930024655108186 \\
-1.223407298660663 \\
-1.273530574212508 \\
-1.230517757317628 \\
-1.151356031082747 \\
-1.056883669273682 \\
-0.952628310081466 \\
-0.834334594312996 \\
-0.683708806198363 \\
-0.450125157620744 \\
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=6.955194519943778e-11\]
We managed to do this in \textbf{59} iterations of our loop, and the demanded tolerance did not change.
With change in demanded tolerance:
\[ x_a =\left(\begin{array}{cc}
-0.930024655104470 \\
-1.223407298653515 \\
-1.273530574202540 \\
-1.230517757305602 \\
-1.151356031069692 \\
-1.056883669260597 \\
-0.952628310069469 \\
-0.834334594303006 \\
-0.683708806191233 \\
-0.450125157617020 \\
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=1.699812218689508e-10\]
We managed to do this in \textbf{57} iterations of our loop, and the demanded tolerance changed to $4*10^{-10}$
Compared to matlab $ A \ b $ function
\[ x_{matlab}=\left(\begin{array}{cc}
-0.930024655110760 \\
-1.223407298665612 \\
-1.273530574219411 \\
-1.230517757325956 \\
-1.151356031091789 \\
-1.056883669282743 \\
-0.952628310089775 \\
-0.834334594319914 \\
-0.683708806203301 \\
-0.450125157623323 \\
\end{array}\right)
\]
Matlab error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=3.662053438817790e-15\]
For Matrix and Vector from task 2b) error of
\[\| x^{(i+1)}- x^{(i)}\|\]
grew to infinity, therefore We could never achieve demanded tolerance, therefore the program executed infinite loop.
\subsubsection{Minimizing the demanded error}
We tried to minimize the demanded error using this steps:
\begin{enumerate}
\item We copied error from matlab function and pasted it into demanded tolerance.
\item If We did not get infinite loop We copied the newly acquired error and pasted it into demanded tolerance.
\item If We got inifinite loop We used the previous error as "minimal" demanded error.
\end{enumerate}
\paragraph{For original system of equations:}
We managed to get results with error as low as $1.776356839400250e-15$ with demanded tolerance = $3.202372833989376e-15$ for lower values program went into infinite loop.
Results for demanded tolerance = $3.202372833989376e-15$
For given matrix:
\[ x =\left(\begin{array}{cc}
-0.076776098662498 \\
2.105784262636790 \\
0.395344797637659 \\
0.397776619767240
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=3.108624468950438e-15\]
We got this result in \textbf{53} iterations and demanded tolerance did not change.
\paragraph{For task 2a) system of equations:}
We managed to get results with error as low as
\[3.108624468950438e-15\] with demanded tolerance:
\[3.202372833989376e-15\]
for lower values program went into infinite loop.
For demanded tolerance = $3.202372833989376e-15$:
Results for 2a) system of equation
\[ x_a =\left(\begin{array}{cc}
-0.930024655110760 \\
-1.223407298665613 \\
-1.273530574219411 \\
-1.230517757325955 \\
-1.151356031091788 \\
-1.056883669282743 \\
-0.952628310089775 \\
-0.834334594319914 \\
-0.683708806203301 \\
-0.450125157623323
\end{array}\right)
\]
Error:
\[ r =\|\mathbf{A}\mathbf{x}-\mathbf{b}\|=3.108624468950438e-15\]
We managed to do this in \textbf{84} iterations of our loop, and the demanded tolerance did not change.
We managed to achieve slightly better (as in, the error was smaller) results than Matlab custom function.
\paragraph{Table}
\begin{center}
\resizebox{\textwidth}{!}{
\begin{tabular}{||c c c c c c||}
\hline
system of equations & method & demanded tolerance & final demanded tolerance & error & iterations \\