Compare commits
No commits in common. "coryab/create-code-structure" and "main" have entirely different histories.
coryab/cre
...
main
12
Makefile
12
Makefile
@ -1,12 +0,0 @@
|
||||
MAKE=make
|
||||
|
||||
.PHONY: code latex docs
|
||||
|
||||
code:
|
||||
$(MAKE) -C src
|
||||
|
||||
latex:
|
||||
$(MAKE) -C latex
|
||||
|
||||
docs:
|
||||
$(MAKE) -C src doxygen
|
||||
73
README.md
73
README.md
@ -4,82 +4,27 @@
|
||||
|
||||
- [Project](https://anderkve.github.io/FYS3150/book/projects/project2.html)
|
||||
|
||||
## Requirements
|
||||
## Compile and run
|
||||
|
||||
To compile the C++ programs, you need to have these packages installed:
|
||||
|
||||
- Armadillo
|
||||
- Openmp
|
||||
|
||||
To run the Python scripts, you need to have these packages:
|
||||
|
||||
- numpy
|
||||
- matplotlib
|
||||
- pandas
|
||||
- seaborn
|
||||
|
||||
## Compile and run C++ programs
|
||||
|
||||
Compiling and linking is done using Make, make sure you are in the root directory.
|
||||
|
||||
There are two alternative ways to compile the code. The first alternative is to change
|
||||
directory to `src/` and compile
|
||||
Compiling and linking is done using Make, make sure you are in the root folder. To create executable files, run shell commands
|
||||
|
||||
```shell
|
||||
cd src && make
|
||||
cd src/
|
||||
make
|
||||
```
|
||||
|
||||
The second alternative does not involve changing directory to `src/`, use
|
||||
make in the projects root directory
|
||||
To run `script-name`
|
||||
|
||||
```shell
|
||||
make code
|
||||
```
|
||||
|
||||
You can run any of the compiled programs by changing directory to `src/`, then
|
||||
|
||||
```shell
|
||||
./test_suite
|
||||
./main
|
||||
```
|
||||
|
||||
Remove object files and executables from `src/`
|
||||
```shell
|
||||
make clean
|
||||
./main
|
||||
```
|
||||
|
||||
|
||||
## Generate plots
|
||||
|
||||
To generate plots, you can do
|
||||
To generate plots, the Python scripts is run using
|
||||
|
||||
```shell
|
||||
python3 plot.py
|
||||
python3 <script-name>
|
||||
```
|
||||
|
||||
and the plots will be saved inside [latex/images](latex/images).
|
||||
|
||||
|
||||
## Generate documentation
|
||||
|
||||
For this project, we have used Doxygen to generate some nice and readable
|
||||
documentation for the C++ code.
|
||||
|
||||
If you want to generate the documentation you can do
|
||||
|
||||
```shell
|
||||
make docs
|
||||
```
|
||||
|
||||
in the project root, and the documentation will be made into the `docs/`
|
||||
directory.
|
||||
|
||||
## Generate project document
|
||||
|
||||
If you want to recompile the Pdf file, you can do
|
||||
|
||||
```shell
|
||||
make latex
|
||||
```
|
||||
|
||||
and a Pdf file will be produced inside the `latex/` directory.
|
||||
The plots will be saved inside [latex/images](../blob/main/latex/images).
|
||||
|
||||
@ -76,19 +76,17 @@ $(function() {
|
||||
<dt>File <a class="el" href="jacobi_8cpp.html">jacobi.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000001"></a>The eigenvalues fail the test. When comparing them to arma::eigsym there is one value that is way off when testing with a 6x6 matrix. </dd>
|
||||
<dt>File <a class="el" href="jacobi_8hpp.html">jacobi.hpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000006"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="main_8cpp.html">main.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000002"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="matrix_8cpp.html">matrix.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000003"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="matrix_8hpp.html">matrix.hpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000007"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="test__suite_8cpp.html">test_suite.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000004"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="utils_8cpp.html">utils.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000005"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="matrix_8cpp.html">matrix.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000002"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="matrix_8hpp.html">matrix.hpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000006"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="test__suite_8cpp.html">test_suite.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000003"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="utils_8cpp.html">utils.cpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000004"></a>No known bugs </dd>
|
||||
<dt>File <a class="el" href="utils_8hpp.html">utils.hpp</a> </dt>
|
||||
<dd><a class="anchor" id="_bug000008"></a>No known bugs </dd>
|
||||
<dd><a class="anchor" id="_bug000007"></a>No known bugs </dd>
|
||||
</dl>
|
||||
</div></div><!-- contents -->
|
||||
</div><!-- PageDoc -->
|
||||
|
||||
@ -79,10 +79,9 @@ $(function() {
|
||||
<tr id="row_0_1_" class="even"><td class="entry"><span style="width:32px;display:inline-block;"> </span><a href="matrix_8hpp_source.html"><span class="icondoc"></span></a><a class="el" href="matrix_8hpp.html" target="_self">matrix.hpp</a></td><td class="desc">Function prototypes for creating tridiagonal matrices </td></tr>
|
||||
<tr id="row_0_2_" class="odd"><td class="entry"><span style="width:32px;display:inline-block;"> </span><a href="utils_8hpp_source.html"><span class="icondoc"></span></a><a class="el" href="utils_8hpp.html" target="_self">utils.hpp</a></td><td class="desc">Function prototypes and macros that are useful </td></tr>
|
||||
<tr id="row_1_" class="even"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="jacobi_8cpp.html" target="_self">jacobi.cpp</a></td><td class="desc">Implementation of the jacobi rotation method </td></tr>
|
||||
<tr id="row_2_" class="odd"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="main_8cpp.html" target="_self">main.cpp</a></td><td class="desc">Main program for Project 2 </td></tr>
|
||||
<tr id="row_3_" class="even"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="matrix_8cpp.html" target="_self">matrix.cpp</a></td><td class="desc">Function prototypes for creating tridiagonal matrices </td></tr>
|
||||
<tr id="row_4_" class="odd"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="test__suite_8cpp.html" target="_self">test_suite.cpp</a></td><td class="desc">Test suite for project 2 </td></tr>
|
||||
<tr id="row_5_" class="even"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="utils_8cpp.html" target="_self">utils.cpp</a></td><td class="desc">Implementation of the utils </td></tr>
|
||||
<tr id="row_2_" class="odd"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="matrix_8cpp.html" target="_self">matrix.cpp</a></td><td class="desc">Function prototypes for creating tridiagonal matrices </td></tr>
|
||||
<tr id="row_3_" class="even"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="test__suite_8cpp.html" target="_self">test_suite.cpp</a></td><td class="desc">Test suite for project 2 </td></tr>
|
||||
<tr id="row_4_" class="odd"><td class="entry"><span style="width:16px;display:inline-block;"> </span><span class="icondoc"></span><a class="el" href="utils_8cpp.html" target="_self">utils.cpp</a></td><td class="desc">Implementation of the utils </td></tr>
|
||||
</table>
|
||||
</div><!-- directory -->
|
||||
</div><!-- contents -->
|
||||
|
||||
@ -77,9 +77,7 @@ $(function() {
|
||||
|
||||
<p>Implementation of the jacobi rotation method.
|
||||
<a href="#details">More...</a></p>
|
||||
<div class="textblock"><code>#include <algorithm></code><br />
|
||||
<code>#include <cmath></code><br />
|
||||
<code>#include <utility></code><br />
|
||||
<div class="textblock"><code>#include <cmath></code><br />
|
||||
<code>#include "<a class="el" href="utils_8hpp_source.html">utils.hpp</a>"</code><br />
|
||||
<code>#include "<a class="el" href="jacobi_8hpp_source.html">jacobi.hpp</a>"</code><br />
|
||||
<code>#include "<a class="el" href="matrix_8hpp_source.html">matrix.hpp</a>"</code><br />
|
||||
@ -157,9 +155,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Solves the eigenvalue problem using the jacobi rotation method. </p>
|
||||
<p>jacobi_eigensolver Initializes matrices A_m and R before going into the main loop.</p>
|
||||
<p>For each iteration of the loop, it finds the largest absolute off-diagonal value of A_m, and then calls jacobi_rotate. The loop stops when the largest off-diagonal is less than the tolerance (eps) or if the maximum number of iterations has been reached.</p>
|
||||
<p>The last thing this function does is to sort the eigenvalues and the corresponding eigenvectors in ascending order.</p>
|
||||
<p>Description</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">A</td><td>The initial matrix to be solved </td></tr>
|
||||
@ -215,7 +211,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Computes a single rotation. </p>
|
||||
<p>jacobi_rotate computes a single rotation for Jacobi's rotation algorithm. It starts by calculating tau, t (tan), c (cos), s (sin) and then updates A and R at rows/columsn k and l.</p>
|
||||
<p>Description</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">A</td><td>Matrix A<sup> (m) </sup> </td></tr>
|
||||
|
||||
@ -99,7 +99,7 @@ Functions</h2></td></tr>
|
||||
<dl class="section author"><dt>Author</dt><dd>Cory Alexander Balaton (coryab) </dd>
|
||||
<dd>
|
||||
Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000006">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000005">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a5a8da00df38bec1046249e8589a8aad0" name="a5a8da00df38bec1046249e8589a8aad0"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a5a8da00df38bec1046249e8589a8aad0">◆ </a></span>jacobi_eigensolver()</h2>
|
||||
@ -158,9 +158,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Solves the eigenvalue problem using the jacobi rotation method. </p>
|
||||
<p>jacobi_eigensolver Initializes matrices A_m and R before going into the main loop.</p>
|
||||
<p>For each iteration of the loop, it finds the largest absolute off-diagonal value of A_m, and then calls jacobi_rotate. The loop stops when the largest off-diagonal is less than the tolerance (eps) or if the maximum number of iterations has been reached.</p>
|
||||
<p>The last thing this function does is to sort the eigenvalues and the corresponding eigenvectors in ascending order.</p>
|
||||
<p>Description</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">A</td><td>The initial matrix to be solved </td></tr>
|
||||
@ -216,7 +214,7 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Computes a single rotation. </p>
|
||||
<p>jacobi_rotate computes a single rotation for Jacobi's rotation algorithm. It starts by calculating tau, t (tan), c (cos), s (sin) and then updates A and R at rows/columsn k and l.</p>
|
||||
<p>Description</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">A</td><td>Matrix A<sup> (m) </sup> </td></tr>
|
||||
|
||||
@ -82,19 +82,19 @@ $(function() {
|
||||
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span> </div>
|
||||
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span><span class="preprocessor">#include <armadillo></span></div>
|
||||
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span> </div>
|
||||
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span><span class="keywordtype">void</span> <a class="code hl_function" href="jacobi_8hpp.html#a49809414937a1491ff04ec3dc780982a">jacobi_rotate</a>(arma::mat& A, arma::mat& R, <span class="keywordtype">int</span> k, <span class="keywordtype">int</span> l);</div>
|
||||
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> </div>
|
||||
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span><span class="keywordtype">void</span> <a class="code hl_function" href="jacobi_8hpp.html#a5a8da00df38bec1046249e8589a8aad0">jacobi_eigensolver</a>(<span class="keyword">const</span> arma::mat& A, </div>
|
||||
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> <span class="keywordtype">double</span> eps, </div>
|
||||
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> arma::vec& eigenvalues, </div>
|
||||
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> arma::mat& eigenvectors, </div>
|
||||
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> <span class="keyword">const</span> <span class="keywordtype">int</span> maxiter, </div>
|
||||
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> <span class="keywordtype">int</span>& iterations, </div>
|
||||
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> <span class="keywordtype">bool</span>& converged);</div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> </div>
|
||||
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="ttc" id="ajacobi_8hpp_html_a49809414937a1491ff04ec3dc780982a"><div class="ttname"><a href="jacobi_8hpp.html#a49809414937a1491ff04ec3dc780982a">jacobi_rotate</a></div><div class="ttdeci">void jacobi_rotate(arma::mat &A, arma::mat &R, int k, int l)</div><div class="ttdoc">Computes a single rotation.</div><div class="ttdef"><b>Definition:</b> jacobi.cpp:17</div></div>
|
||||
<div class="ttc" id="ajacobi_8hpp_html_a5a8da00df38bec1046249e8589a8aad0"><div class="ttname"><a href="jacobi_8hpp.html#a5a8da00df38bec1046249e8589a8aad0">jacobi_eigensolver</a></div><div class="ttdeci">void jacobi_eigensolver(const arma::mat &A, double eps, arma::vec &eigenvalues, arma::mat &eigenvectors, const int maxiter, int &iterations, bool &converged)</div><div class="ttdoc">Solves the eigenvalue problem using the jacobi rotation method.</div><div class="ttdef"><b>Definition:</b> jacobi.cpp:56</div></div>
|
||||
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span><span class="keywordtype">void</span> <a class="code hl_function" href="jacobi_8hpp.html#a49809414937a1491ff04ec3dc780982a">jacobi_rotate</a>(arma::mat& A, arma::mat& R, <span class="keywordtype">int</span> k, <span class="keywordtype">int</span> l);</div>
|
||||
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> </div>
|
||||
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span><span class="keywordtype">void</span> <a class="code hl_function" href="jacobi_8hpp.html#a5a8da00df38bec1046249e8589a8aad0">jacobi_eigensolver</a>(<span class="keyword">const</span> arma::mat& A, </div>
|
||||
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> <span class="keywordtype">double</span> eps, </div>
|
||||
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> arma::vec& eigenvalues, </div>
|
||||
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> arma::mat& eigenvectors, </div>
|
||||
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> <span class="keyword">const</span> <span class="keywordtype">int</span> maxiter, </div>
|
||||
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> <span class="keywordtype">int</span>& iterations, </div>
|
||||
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> <span class="keywordtype">bool</span>& converged);</div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> </div>
|
||||
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="ttc" id="ajacobi_8hpp_html_a49809414937a1491ff04ec3dc780982a"><div class="ttname"><a href="jacobi_8hpp.html#a49809414937a1491ff04ec3dc780982a">jacobi_rotate</a></div><div class="ttdeci">void jacobi_rotate(arma::mat &A, arma::mat &R, int k, int l)</div><div class="ttdoc">Computes a single rotation.</div><div class="ttdef"><b>Definition:</b> jacobi.cpp:15</div></div>
|
||||
<div class="ttc" id="ajacobi_8hpp_html_a5a8da00df38bec1046249e8589a8aad0"><div class="ttname"><a href="jacobi_8hpp.html#a5a8da00df38bec1046249e8589a8aad0">jacobi_eigensolver</a></div><div class="ttdeci">void jacobi_eigensolver(const arma::mat &A, double eps, arma::vec &eigenvalues, arma::mat &eigenvectors, const int maxiter, int &iterations, bool &converged)</div><div class="ttdoc">Solves the eigenvalue problem using the jacobi rotation method.</div><div class="ttdef"><b>Definition:</b> jacobi.cpp:54</div></div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
|
||||
@ -1,118 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.9.6"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>FYS3150: Project 2: main.cpp File Reference</title>
|
||||
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
<script type="text/javascript" src="dynsections.js"></script>
|
||||
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="search/searchdata.js"></script>
|
||||
<script type="text/javascript" src="search/search.js"></script>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
<div id="titlearea">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr id="projectrow">
|
||||
<td id="projectalign">
|
||||
<div id="projectname">FYS3150: Project 2
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.9.6 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "search/",'.html');
|
||||
/* @license-end */
|
||||
</script>
|
||||
<script type="text/javascript" src="menudata.js"></script>
|
||||
<script type="text/javascript" src="menu.js"></script>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(function() {
|
||||
initMenu('',true,false,'search.php','Search');
|
||||
$(document).ready(function() { init_search(); });
|
||||
});
|
||||
/* @license-end */
|
||||
</script>
|
||||
<div id="main-nav"></div>
|
||||
<!-- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
onmouseover="return searchBox.OnSearchSelectShow()"
|
||||
onmouseout="return searchBox.OnSearchSelectHide()"
|
||||
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||||
</div>
|
||||
|
||||
<!-- iframe showing the search results (closed by default) -->
|
||||
<div id="MSearchResultsWindow">
|
||||
<div id="MSearchResults">
|
||||
<div class="SRPage">
|
||||
<div id="SRIndex">
|
||||
<div id="SRResults"></div>
|
||||
<div class="SRStatus" id="Loading">Loading...</div>
|
||||
<div class="SRStatus" id="Searching">Searching...</div>
|
||||
<div class="SRStatus" id="NoMatches">No Matches</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!-- top -->
|
||||
<div class="header">
|
||||
<div class="summary">
|
||||
<a href="#func-members">Functions</a> </div>
|
||||
<div class="headertitle"><div class="title">main.cpp File Reference</div></div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
|
||||
<p>Main program for Project 2.
|
||||
<a href="#details">More...</a></p>
|
||||
<div class="textblock"><code>#include <cassert></code><br />
|
||||
<code>#include <cmath></code><br />
|
||||
<code>#include <ctime></code><br />
|
||||
<code>#include <iostream></code><br />
|
||||
<code>#include <omp.h></code><br />
|
||||
<code>#include <ostream></code><br />
|
||||
<code>#include "<a class="el" href="utils_8hpp_source.html">utils.hpp</a>"</code><br />
|
||||
<code>#include "<a class="el" href="matrix_8hpp_source.html">matrix.hpp</a>"</code><br />
|
||||
<code>#include "<a class="el" href="jacobi_8hpp_source.html">jacobi.hpp</a>"</code><br />
|
||||
</div><table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
||||
Functions</h2></td></tr>
|
||||
<tr class="memitem:a53cac9c8c53af2f5786024fc55ca3864"><td class="memItemLeft" align="right" valign="top"><a id="a53cac9c8c53af2f5786024fc55ca3864" name="a53cac9c8c53af2f5786024fc55ca3864"></a>
|
||||
void </td><td class="memItemRight" valign="bottom"><b>write_transformation_dense</b> (int N)</td></tr>
|
||||
<tr class="separator:a53cac9c8c53af2f5786024fc55ca3864"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:acbb39b9c7880e8c390ff599f30a44388"><td class="memItemLeft" align="right" valign="top"><a id="acbb39b9c7880e8c390ff599f30a44388" name="acbb39b9c7880e8c390ff599f30a44388"></a>
|
||||
void </td><td class="memItemRight" valign="bottom"><b>write_transformation_tridiag</b> (int N)</td></tr>
|
||||
<tr class="separator:acbb39b9c7880e8c390ff599f30a44388"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a60bac2011e71020815da55a734cb3e89"><td class="memItemLeft" align="right" valign="top"><a id="a60bac2011e71020815da55a734cb3e89" name="a60bac2011e71020815da55a734cb3e89"></a>
|
||||
void </td><td class="memItemRight" valign="bottom"><b>write_eigenvec</b> (int N)</td></tr>
|
||||
<tr class="separator:a60bac2011e71020815da55a734cb3e89"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top"><a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
||||
int </td><td class="memItemRight" valign="bottom"><b>main</b> ()</td></tr>
|
||||
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Main program for Project 2. </p>
|
||||
<p>The program performs the Jacobi rotation method. The size of the matrix, and number of transformations performed are written to file. Eigenvector corresponding to the 3 smallest eigenvalues for matrices of size 6x6 and 100x100 are written to file.</p>
|
||||
<dl class="section author"><dt>Author</dt><dd>Cory Alexander Balaton (coryab) </dd>
|
||||
<dd>
|
||||
Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000002">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
</div></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6
|
||||
</small></address>
|
||||
</body>
|
||||
</html>
|
||||
@ -99,7 +99,7 @@ Functions</h2></td></tr>
|
||||
<dl class="section author"><dt>Author</dt><dd>Cory Alexander Balaton (coryab) </dd>
|
||||
<dd>
|
||||
Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000003">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000002">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a564688c96a8e4282e995a0663545d627" name="a564688c96a8e4282e995a0663545d627"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a564688c96a8e4282e995a0663545d627">◆ </a></span>create_symmetric_tridiagonal()</h2>
|
||||
@ -134,7 +134,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Create a symmetric tridiagonal matrix. </p>
|
||||
<p>create_symmetric_tridiagonal creates a symmetric tridiagonal matrix by calling create_tridiagonal with the same signature for the off-diagonals.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">n</td><td>The dimensions of the tridiagonal matrix </td></tr>
|
||||
@ -180,7 +179,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Create a tridiagonal matrix. </p>
|
||||
<p>create_tridiagonal creates a tridiagonal matrix by first creating a matrix, filled with zeros, of size NxN where N is the size of the main diagonal matrix. Then it will fill all the values from the vector parameters into the matrix and return it.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">a</td><td>Vector for the lower diagonal of size N-1 </td></tr>
|
||||
@ -232,7 +230,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Create a tridiagonal matrix. </p>
|
||||
<p>This is an overload that takes doubles for the diagonals instead of vectors. It will create 3 vectors that are filled with the signature provided in the arguments, and then call create_tridiagonal with the vectors as the arguments.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">n</td><td>The dimensions of the tridiagonal matrix </td></tr>
|
||||
@ -279,7 +276,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Find the off-diagonal element with the largest absolute value. </p>
|
||||
<p>max_offdiag_symmetric find the element with the largest absolute value that isn't in the diagonal. Since this function assumes that the matrix that is given is symmetrical, we only need to loop through the upper diagonals of the matrix.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">A</td><td>Symmetric matrix </td></tr>
|
||||
|
||||
@ -82,7 +82,6 @@ $(function() {
|
||||
<p>Function prototypes for creating tridiagonal matrices.
|
||||
<a href="#details">More...</a></p>
|
||||
<div class="textblock"><code>#include <armadillo></code><br />
|
||||
<code>#include <omp.h></code><br />
|
||||
</div>
|
||||
<p><a href="matrix_8hpp_source.html">Go to the source code of this file.</a></p>
|
||||
<table class="memberdecls">
|
||||
@ -106,7 +105,7 @@ Functions</h2></td></tr>
|
||||
<dl class="section author"><dt>Author</dt><dd>Cory Alexander Balaton (coryab) </dd>
|
||||
<dd>
|
||||
Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000007">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000006">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a564688c96a8e4282e995a0663545d627" name="a564688c96a8e4282e995a0663545d627"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a564688c96a8e4282e995a0663545d627">◆ </a></span>create_symmetric_tridiagonal()</h2>
|
||||
@ -141,7 +140,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Create a symmetric tridiagonal matrix. </p>
|
||||
<p>create_symmetric_tridiagonal creates a symmetric tridiagonal matrix by calling create_tridiagonal with the same signature for the off-diagonals.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">n</td><td>The dimensions of the tridiagonal matrix </td></tr>
|
||||
@ -187,7 +185,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Create a tridiagonal matrix. </p>
|
||||
<p>create_tridiagonal creates a tridiagonal matrix by first creating a matrix, filled with zeros, of size NxN where N is the size of the main diagonal matrix. Then it will fill all the values from the vector parameters into the matrix and return it.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">a</td><td>Vector for the lower diagonal of size N-1 </td></tr>
|
||||
@ -239,7 +236,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Create a tridiagonal matrix. </p>
|
||||
<p>This is an overload that takes doubles for the diagonals instead of vectors. It will create 3 vectors that are filled with the signature provided in the arguments, and then call create_tridiagonal with the vectors as the arguments.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">n</td><td>The dimensions of the tridiagonal matrix </td></tr>
|
||||
@ -286,7 +282,6 @@ Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>Find the off-diagonal element with the largest absolute value. </p>
|
||||
<p>max_offdiag_symmetric find the element with the largest absolute value that isn't in the diagonal. Since this function assumes that the matrix that is given is symmetrical, we only need to loop through the upper diagonals of the matrix.</p>
|
||||
<dl class="params"><dt>Parameters</dt><dd>
|
||||
<table class="params">
|
||||
<tr><td class="paramname">A</td><td>Symmetric matrix </td></tr>
|
||||
|
||||
@ -81,23 +81,22 @@ $(function() {
|
||||
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span><span class="preprocessor">#define __MATRIX__</span></div>
|
||||
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span> </div>
|
||||
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="preprocessor">#include <armadillo></span></div>
|
||||
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="preprocessor">#include <omp.h></span></div>
|
||||
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span> </div>
|
||||
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span>arma::mat <a class="code hl_function" href="matrix_8hpp.html#aa524feaf9f44790470df4cb99bb714af">create_tridiagonal</a>(</div>
|
||||
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> <span class="keyword">const</span> arma::vec& a, </div>
|
||||
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> <span class="keyword">const</span> arma::vec& d, </div>
|
||||
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> <span class="keyword">const</span> arma::vec& e);</div>
|
||||
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> </div>
|
||||
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span>arma::mat <a class="code hl_function" href="matrix_8hpp.html#aa524feaf9f44790470df4cb99bb714af">create_tridiagonal</a>(<span class="keywordtype">int</span> n, <span class="keywordtype">double</span> a, <span class="keywordtype">double</span> d, <span class="keywordtype">double</span> e);</div>
|
||||
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> </div>
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span>arma::mat <a class="code hl_function" href="matrix_8hpp.html#a564688c96a8e4282e995a0663545d627">create_symmetric_tridiagonal</a>(<span class="keywordtype">int</span> n, <span class="keywordtype">double</span> a, <span class="keywordtype">double</span> d);</div>
|
||||
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> </div>
|
||||
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span><span class="keywordtype">double</span> <a class="code hl_function" href="matrix_8hpp.html#af42e501cbf71bec9c77ececc22723df9">max_offdiag_symmetric</a>(arma::mat& A, <span class="keywordtype">int</span>& k, <span class="keywordtype">int</span>& l);</div>
|
||||
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> </div>
|
||||
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="ttc" id="amatrix_8hpp_html_a564688c96a8e4282e995a0663545d627"><div class="ttname"><a href="matrix_8hpp.html#a564688c96a8e4282e995a0663545d627">create_symmetric_tridiagonal</a></div><div class="ttdeci">arma::mat create_symmetric_tridiagonal(int n, double a, double d)</div><div class="ttdoc">Create a symmetric tridiagonal matrix.</div><div class="ttdef"><b>Definition:</b> matrix.cpp:45</div></div>
|
||||
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span> </div>
|
||||
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span>arma::mat <a class="code hl_function" href="matrix_8hpp.html#aa524feaf9f44790470df4cb99bb714af">create_tridiagonal</a>(</div>
|
||||
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> <span class="keyword">const</span> arma::vec& a, </div>
|
||||
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> <span class="keyword">const</span> arma::vec& d, </div>
|
||||
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> <span class="keyword">const</span> arma::vec& e);</div>
|
||||
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> </div>
|
||||
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span>arma::mat <a class="code hl_function" href="matrix_8hpp.html#aa524feaf9f44790470df4cb99bb714af">create_tridiagonal</a>(<span class="keywordtype">int</span> n, <span class="keywordtype">double</span> a, <span class="keywordtype">double</span> d, <span class="keywordtype">double</span> e);</div>
|
||||
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> </div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span>arma::mat <a class="code hl_function" href="matrix_8hpp.html#a564688c96a8e4282e995a0663545d627">create_symmetric_tridiagonal</a>(<span class="keywordtype">int</span> n, <span class="keywordtype">double</span> a, <span class="keywordtype">double</span> d);</div>
|
||||
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> </div>
|
||||
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span><span class="keywordtype">double</span> <a class="code hl_function" href="matrix_8hpp.html#af42e501cbf71bec9c77ececc22723df9">max_offdiag_symmetric</a>(arma::mat& A, <span class="keywordtype">int</span>& k, <span class="keywordtype">int</span>& l);</div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> </div>
|
||||
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="ttc" id="amatrix_8hpp_html_a564688c96a8e4282e995a0663545d627"><div class="ttname"><a href="matrix_8hpp.html#a564688c96a8e4282e995a0663545d627">create_symmetric_tridiagonal</a></div><div class="ttdeci">arma::mat create_symmetric_tridiagonal(int n, double a, double d)</div><div class="ttdoc">Create a symmetric tridiagonal matrix.</div><div class="ttdef"><b>Definition:</b> matrix.cpp:44</div></div>
|
||||
<div class="ttc" id="amatrix_8hpp_html_aa524feaf9f44790470df4cb99bb714af"><div class="ttname"><a href="matrix_8hpp.html#aa524feaf9f44790470df4cb99bb714af">create_tridiagonal</a></div><div class="ttdeci">arma::mat create_tridiagonal(const arma::vec &a, const arma::vec &d, const arma::vec &e)</div><div class="ttdoc">Create a tridiagonal matrix.</div><div class="ttdef"><b>Definition:</b> matrix.cpp:12</div></div>
|
||||
<div class="ttc" id="amatrix_8hpp_html_af42e501cbf71bec9c77ececc22723df9"><div class="ttname"><a href="matrix_8hpp.html#af42e501cbf71bec9c77ececc22723df9">max_offdiag_symmetric</a></div><div class="ttdeci">double max_offdiag_symmetric(arma::mat &A, int &k, int &l)</div><div class="ttdoc">Find the off-diagonal element with the largest absolute value.</div><div class="ttdef"><b>Definition:</b> matrix.cpp:50</div></div>
|
||||
<div class="ttc" id="amatrix_8hpp_html_af42e501cbf71bec9c77ececc22723df9"><div class="ttname"><a href="matrix_8hpp.html#af42e501cbf71bec9c77ececc22723df9">max_offdiag_symmetric</a></div><div class="ttdeci">double max_offdiag_symmetric(arma::mat &A, int &k, int &l)</div><div class="ttdoc">Find the off-diagonal element with the largest absolute value.</div><div class="ttdef"><b>Definition:</b> matrix.cpp:49</div></div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
var searchData=
|
||||
[
|
||||
['main_2ecpp_0',['main.cpp',['../main_8cpp.html',1,'']]],
|
||||
['matrix_2ecpp_1',['matrix.cpp',['../matrix_8cpp.html',1,'']]],
|
||||
['matrix_2ehpp_2',['matrix.hpp',['../matrix_8hpp.html',1,'']]],
|
||||
['max_5foffdiag_5fsymmetric_3',['max_offdiag_symmetric',['../matrix_8cpp.html#af42e501cbf71bec9c77ececc22723df9',1,'max_offdiag_symmetric(arma::mat &A, int &k, int &l): matrix.cpp'],['../matrix_8hpp.html#af42e501cbf71bec9c77ececc22723df9',1,'max_offdiag_symmetric(arma::mat &A, int &k, int &l): matrix.cpp']]]
|
||||
['matrix_2ecpp_0',['matrix.cpp',['../matrix_8cpp.html',1,'']]],
|
||||
['matrix_2ehpp_1',['matrix.hpp',['../matrix_8hpp.html',1,'']]],
|
||||
['max_5foffdiag_5fsymmetric_2',['max_offdiag_symmetric',['../matrix_8cpp.html#af42e501cbf71bec9c77ececc22723df9',1,'max_offdiag_symmetric(arma::mat &A, int &k, int &l): matrix.cpp'],['../matrix_8hpp.html#af42e501cbf71bec9c77ececc22723df9',1,'max_offdiag_symmetric(arma::mat &A, int &k, int &l): matrix.cpp']]]
|
||||
];
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
var searchData=
|
||||
[
|
||||
['main_2ecpp_0',['main.cpp',['../main_8cpp.html',1,'']]],
|
||||
['matrix_2ecpp_1',['matrix.cpp',['../matrix_8cpp.html',1,'']]],
|
||||
['matrix_2ehpp_2',['matrix.hpp',['../matrix_8hpp.html',1,'']]]
|
||||
['matrix_2ecpp_0',['matrix.cpp',['../matrix_8cpp.html',1,'']]],
|
||||
['matrix_2ehpp_1',['matrix.hpp',['../matrix_8hpp.html',1,'']]]
|
||||
];
|
||||
|
||||
@ -105,7 +105,7 @@ int </td><td class="memItemRight" valign="bottom"><b>main</b> ()</td></tr>
|
||||
<dl class="section author"><dt>Author</dt><dd>Cory Alexander Balaton (coryab) </dd>
|
||||
<dd>
|
||||
Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000004">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000003">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
</div></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
|
||||
@ -93,7 +93,7 @@ Functions</h2></td></tr>
|
||||
<dl class="section author"><dt>Author</dt><dd>Cory Alexander Balaton (coryab) </dd>
|
||||
<dd>
|
||||
Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000005">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000004">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a58565270b643b24e3132f38c653e0199" name="a58565270b643b24e3132f38c653e0199"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#a58565270b643b24e3132f38c653e0199">◆ </a></span>scientific_format() <span class="overload">[1/2]</span></h2>
|
||||
|
||||
@ -85,7 +85,6 @@ $(function() {
|
||||
<div class="textblock"><code>#include <string></code><br />
|
||||
<code>#include <vector></code><br />
|
||||
<code>#include <iomanip></code><br />
|
||||
<code>#include <sstream></code><br />
|
||||
</div>
|
||||
<p><a href="utils_8hpp_source.html">Go to the source code of this file.</a></p>
|
||||
<table class="memberdecls">
|
||||
@ -110,7 +109,7 @@ Functions</h2></td></tr>
|
||||
<dl class="section author"><dt>Author</dt><dd>Cory Alexander Balaton (coryab) </dd>
|
||||
<dd>
|
||||
Janita Ovidie Sandtrøen Willumsen (janitaws) </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000008">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
<dl class="bug"><dt><b><a class="el" href="bug.html#_bug000007">Bug:</a></b></dt><dd>No known bugs </dd></dl>
|
||||
</div><h2 class="groupheader">Macro Definition Documentation</h2>
|
||||
<a id="aecc1f7a8a2493b9e021e5bff76a00a5b" name="aecc1f7a8a2493b9e021e5bff76a00a5b"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#aecc1f7a8a2493b9e021e5bff76a00a5b">◆ </a></span>DEBUG</h2>
|
||||
|
||||
@ -83,22 +83,21 @@ $(function() {
|
||||
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="preprocessor">#include <string></span></div>
|
||||
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="preprocessor">#include <vector></span></div>
|
||||
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="preprocessor">#include <iomanip></span></div>
|
||||
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="preprocessor">#include <sstream></span></div>
|
||||
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span> </div>
|
||||
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span><span class="preprocessor">#ifdef DBG</span></div>
|
||||
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span><span class="preprocessor"> #define DEBUG(msg) std::cout << __FILE__ << " "</span> << __LINE__ << ": " \</div>
|
||||
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> << msg << std::endl</div>
|
||||
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span><span class="preprocessor">#else</span></div>
|
||||
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"><a class="line" href="utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b"> 31</a></span><span class="preprocessor"> #define DEBUG(msg)</span></div>
|
||||
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> </div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span>std::string <a class="code hl_function" href="utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384">scientific_format</a>(<span class="keywordtype">double</span> d, <span class="keywordtype">int</span> width=20, <span class="keywordtype">int</span> prec=10);</div>
|
||||
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> </div>
|
||||
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span>std::string <a class="code hl_function" href="utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384">scientific_format</a>(<span class="keyword">const</span> std::vector<double>& v, </div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> <span class="keywordtype">int</span> width=20, </div>
|
||||
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <span class="keywordtype">int</span> prec=10);</div>
|
||||
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> </div>
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span> </div>
|
||||
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span><span class="preprocessor">#ifdef DBG</span></div>
|
||||
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span><span class="preprocessor"> #define DEBUG(msg) std::cout << __FILE__ << " "</span> << __LINE__ << ": " \</div>
|
||||
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> << msg << std::endl</div>
|
||||
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span><span class="preprocessor">#else</span></div>
|
||||
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"><a class="line" href="utils_8hpp.html#aecc1f7a8a2493b9e021e5bff76a00a5b"> 30</a></span><span class="preprocessor"> #define DEBUG(msg)</span></div>
|
||||
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> </div>
|
||||
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span>std::string <a class="code hl_function" href="utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384">scientific_format</a>(<span class="keywordtype">double</span> d, <span class="keywordtype">int</span> width=20, <span class="keywordtype">int</span> prec=10);</div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> </div>
|
||||
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span>std::string <a class="code hl_function" href="utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384">scientific_format</a>(<span class="keyword">const</span> std::vector<double>& v, </div>
|
||||
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> <span class="keywordtype">int</span> width=20, </div>
|
||||
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> <span class="keywordtype">int</span> prec=10);</div>
|
||||
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> </div>
|
||||
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span><span class="preprocessor">#endif</span></div>
|
||||
<div class="ttc" id="autils_8hpp_html_adfb618b2fdff47ef30a4a2b62c04f384"><div class="ttname"><a href="utils_8hpp.html#adfb618b2fdff47ef30a4a2b62c04f384">scientific_format</a></div><div class="ttdeci">std::string scientific_format(double d, int width=20, int prec=10)</div><div class="ttdoc">Turns a double into a string written in scientific format.</div><div class="ttdef"><b>Definition:</b> utils.cpp:10</div></div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
|
||||
@ -12,9 +12,7 @@
|
||||
|
||||
/** @brief Computes a single rotation.
|
||||
*
|
||||
* jacobi_rotate computes a single rotation for Jacobi's rotation algorithm.
|
||||
* It starts by calculating tau, t (tan), c (cos), s (sin) and then
|
||||
* updates A and R at rows/columsn k and l.
|
||||
* Description
|
||||
*
|
||||
* @param A Matrix A<sup> (m) </sup>
|
||||
* @param R The rotation matrix R<sup> (m) </sup>
|
||||
@ -27,16 +25,7 @@ void jacobi_rotate(arma::mat& A, arma::mat& R, int k, int l);
|
||||
|
||||
/** @brief Solves the eigenvalue problem using the jacobi rotation method.
|
||||
*
|
||||
* jacobi_eigensolver Initializes matrices A_m and R before going into the
|
||||
* main loop.
|
||||
*
|
||||
* For each iteration of the loop, it finds the largest absolute off-diagonal
|
||||
* value of A_m, and then calls jacobi_rotate. The loop stops when the largest
|
||||
* off-diagonal is less than the tolerance (eps) or if the maximum number of
|
||||
* iterations has been reached.
|
||||
*
|
||||
* The last thing this function does is to sort the eigenvalues and the
|
||||
* corresponding eigenvectors in ascending order.
|
||||
* Description
|
||||
*
|
||||
* @param A The initial matrix to be solved
|
||||
* @param eps Tolerance
|
||||
|
||||
@ -11,14 +11,8 @@
|
||||
#define __MATRIX__
|
||||
|
||||
#include <armadillo>
|
||||
#include <omp.h>
|
||||
|
||||
/** @brief Create a tridiagonal matrix.
|
||||
*
|
||||
* create_tridiagonal creates a tridiagonal matrix by first creating a matrix,
|
||||
* filled with zeros, of size NxN where N is the size of the main diagonal
|
||||
* matrix. Then it will fill all the values from the vector parameters into
|
||||
* the matrix and return it.
|
||||
*
|
||||
* @param a Vector for the lower diagonal of size N-1
|
||||
* @param d Vector for the main diagonal of size N
|
||||
@ -32,11 +26,6 @@ arma::mat create_tridiagonal(
|
||||
const arma::vec& e);
|
||||
|
||||
/** @brief Create a tridiagonal matrix.
|
||||
*
|
||||
* This is an overload that takes doubles for the diagonals instead of
|
||||
* vectors. It will create 3 vectors that are filled with the signature
|
||||
* provided in the arguments, and then call create_tridiagonal with the
|
||||
* vectors as the arguments.
|
||||
*
|
||||
* @param n The dimensions of the tridiagonal matrix
|
||||
* @param a The signature for the lower diagonal
|
||||
@ -48,9 +37,6 @@ arma::mat create_tridiagonal(
|
||||
arma::mat create_tridiagonal(int n, double a, double d, double e);
|
||||
|
||||
/** @brief Create a symmetric tridiagonal matrix.
|
||||
*
|
||||
* create_symmetric_tridiagonal creates a symmetric tridiagonal matrix by
|
||||
* calling create_tridiagonal with the same signature for the off-diagonals.
|
||||
*
|
||||
* @param n The dimensions of the tridiagonal matrix
|
||||
* @param a The signature for the off diagonals
|
||||
@ -61,11 +47,6 @@ arma::mat create_tridiagonal(int n, double a, double d, double e);
|
||||
arma::mat create_symmetric_tridiagonal(int n, double a, double d);
|
||||
|
||||
/** @brief Find the off-diagonal element with the largest absolute value.
|
||||
*
|
||||
* max_offdiag_symmetric find the element with the largest absolute value
|
||||
* that isn't in the diagonal. Since this function assumes that the matrix
|
||||
* that is given is symmetrical, we only need to loop through the upper
|
||||
* diagonals of the matrix.
|
||||
*
|
||||
* @param A Symmetric matrix
|
||||
* @param k Variable to store the row of the return value
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
/** @def DEBUG(msg)
|
||||
* @brief Writes a debug message
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
|
||||
.PHONY: latex
|
||||
|
||||
latex:
|
||||
pdflatex assignment-2.tex
|
||||
Binary file not shown.
@ -91,15 +91,15 @@
|
||||
|
||||
\input{problems/problem-1}
|
||||
|
||||
\input{problems/problem-2}
|
||||
% \input{problems/problem-2}
|
||||
|
||||
\input{problems/problem-3}
|
||||
% \input{problems/problem-3}
|
||||
|
||||
\input{problems/problem-4}
|
||||
% \input{problems/problem-4}
|
||||
|
||||
\input{problems/problem-5}
|
||||
% \input{problems/problem-5}
|
||||
|
||||
\input{problems/problem-6}
|
||||
% \input{problems/problem-6}
|
||||
|
||||
|
||||
\end{document}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
x,Vector 1,Vector 2,Vector 3,Analytic 1,Analytic 2,Analytic 3
|
||||
0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00
|
||||
9.0909090909e-02,1.2013116562e-01,2.3053001908e-01,3.2225269916e-01,1.2013116588e-01,2.3053001915e-01,3.2225270128e-01
|
||||
1.8181818182e-01,2.3053002022e-01,3.8786838557e-01,4.2206128116e-01,2.3053001915e-01,3.8786838606e-01,4.2206128095e-01
|
||||
2.7272727273e-01,3.2225270064e-01,4.2206128186e-01,2.3053002150e-01,3.2225270128e-01,4.2206128095e-01,2.3053001915e-01
|
||||
3.6363636364e-01,3.8786838571e-01,3.2225270018e-01,-1.2013116730e-01,3.8786838606e-01,3.2225270128e-01,-1.2013116588e-01
|
||||
4.5454545455e-01,4.2206128199e-01,1.2013116659e-01,-3.8786838753e-01,4.2206128095e-01,1.2013116588e-01,-3.8786838606e-01
|
||||
5.4545454545e-01,4.2206128029e-01,-1.2013116676e-01,-3.8786838497e-01,4.2206128095e-01,-1.2013116588e-01,-3.8786838606e-01
|
||||
6.3636363636e-01,3.8786838601e-01,-3.2225270035e-01,-1.2013116452e-01,3.8786838606e-01,-3.2225270128e-01,-1.2013116588e-01
|
||||
7.2727272727e-01,3.2225270138e-01,-4.2206128196e-01,2.3053001725e-01,3.2225270128e-01,-4.2206128095e-01,2.3053001915e-01
|
||||
8.1818181818e-01,2.3053001839e-01,-3.8786838569e-01,4.2206128036e-01,2.3053001915e-01,-3.8786838606e-01,4.2206128095e-01
|
||||
9.0909090909e-01,1.2013116693e-01,-2.3053001912e-01,3.2225270306e-01,1.2013116588e-01,-2.3053001915e-01,3.2225270128e-01
|
||||
1.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00
|
||||
|
@ -1,103 +0,0 @@
|
||||
x,Vector 1,Vector 2,Vector 3,Analytic 1,Analytic 2,Analytic 3
|
||||
0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00
|
||||
9.9009900990e-03,4.3763580486e-03,-8.7484808732e-03,-1.3112140868e-02,4.3763573469e-03,-8.7484808507e-03,-1.3112140764e-02
|
||||
1.9801980198e-02,8.7484805374e-03,-1.7463118426e-02,-2.6110190173e-02,8.7484808507e-03,-1.7463115529e-02,-2.6110188805e-02
|
||||
2.9702970297e-02,1.3112137258e-02,-2.6110188342e-02,-3.8881042300e-02,1.3112140764e-02,-2.6110188805e-02,-3.8881044154e-02
|
||||
3.9603960396e-02,1.7463113948e-02,-3.4656251014e-02,-5.1313582739e-02,1.7463115529e-02,-3.4656246833e-02,-5.1313583715e-02
|
||||
4.9504950495e-02,2.1797194330e-02,-4.3068225457e-02,-6.3299631766e-02,2.1797195856e-02,-4.3068226575e-02,-6.3299628182e-02
|
||||
5.9405940594e-02,2.6110192331e-02,-5.1313581763e-02,-7.4734880361e-02,2.6110188805e-02,-5.1313583715e-02,-7.4734883337e-02
|
||||
6.9306930693e-02,3.0397918929e-02,-5.9360418816e-02,-8.5519850123e-02,3.0397921832e-02,-5.9360418568e-02,-8.5519847548e-02
|
||||
7.9207920792e-02,3.4656246898e-02,-6.7177598362e-02,-9.5560679417e-02,3.4656246833e-02,-6.7177599493e-02,-9.5560677562e-02
|
||||
8.9108910891e-02,3.8881042315e-02,-7.4734886241e-02,-1.0477000717e-01,3.8881044154e-02,-7.4734883337e-02,-1.0477000506e-01
|
||||
9.9009900990e-02,4.3068230096e-02,-8.2003031501e-02,-1.1306769719e-01,4.3068226575e-02,-8.2003032435e-02,-1.1306769690e-01
|
||||
1.0891089109e-01,4.7213744503e-02,-8.8953927224e-02,-1.2038155127e-01,4.7213743269e-02,-8.8953927731e-02,-1.2038155232e-01
|
||||
1.1881188119e-01,5.1313588425e-02,-9.5560676214e-02,-1.2664793098e-01,5.1313583715e-02,-9.5560677562e-02,-1.2664793125e-01
|
||||
1.2871287129e-01,5.5363780001e-02,-1.0179771917e-01,-1.3181231002e-01,5.5363781583e-02,-1.0179772170e-01,-1.3181230802e-01
|
||||
1.3861386139e-01,5.9360419789e-02,-1.0764092918e-01,-1.3582974462e-01,5.9360418568e-02,-1.0764093022e-01,-1.3582974582e-01
|
||||
1.4851485149e-01,6.3299627984e-02,-1.1306769819e-01,-1.3866528556e-01,6.3299628182e-02,-1.1306769690e-01,-1.3866528771e-01
|
||||
1.5841584158e-01,6.7177601217e-02,-1.1805702763e-01,-1.4029426114e-01,6.7177599493e-02,-1.1805702662e-01,-1.4029426076e-01
|
||||
1.6831683168e-01,7.0990579025e-02,-1.2258961789e-01,-1.4070249027e-01,7.0990580816e-02,-1.2258961664e-01,-1.4070249079e-01
|
||||
1.7821782178e-01,7.4734880844e-02,-1.2664793546e-01,-1.3988642874e-01,7.4734883337e-02,-1.2664793125e-01,-1.3988642566e-01
|
||||
1.8811881188e-01,7.8406882603e-02,-1.3021626991e-01,-1.3785316434e-01,7.8406884685e-02,-1.3021626962e-01,-1.3785316621e-01
|
||||
1.9801980198e-01,8.2003032834e-02,-1.3328082864e-01,-1.3462040439e-01,8.2003032435e-02,-1.3328082653e-01,-1.3462040445e-01
|
||||
2.0792079208e-01,8.5519846919e-02,-1.3582974378e-01,-1.3021627110e-01,8.5519847548e-02,-1.3582974582e-01,-1.3021626962e-01
|
||||
2.1782178218e-01,8.8953926852e-02,-1.3785316224e-01,-1.2467908375e-01,8.8953927731e-02,-1.3785316621e-01,-1.2467908343e-01
|
||||
2.2772277228e-01,9.2301946409e-02,-1.3934326062e-01,-1.1805702523e-01,9.2301950735e-02,-1.3934325949e-01,-1.1805702662e-01
|
||||
2.3762376238e-01,9.5560676953e-02,-1.4029425672e-01,-1.1040771966e-01,9.5560677562e-02,-1.4029426076e-01,-1.1040771973e-01
|
||||
2.4752475248e-01,9.8726957572e-02,-1.4070249295e-01,-1.0179772068e-01,9.8726955606e-02,-1.4070249079e-01,-1.0179772170e-01
|
||||
2.5742574257e-01,1.0179772036e-01,-1.4056637044e-01,-9.2301949636e-02,1.0179772170e-01,-1.4056637021e-01,-9.2301950735e-02
|
||||
2.6732673267e-01,1.0477000527e-01,-1.3988642578e-01,-8.2003032107e-02,1.0477000506e-01,-1.3988642566e-01,-8.2003032435e-02
|
||||
2.7722772277e-01,1.0764093290e-01,-1.3866528965e-01,-7.0990578930e-02,1.0764093022e-01,-1.3866528771e-01,-7.0990580816e-02
|
||||
2.8712871287e-01,1.1040771987e-01,-1.3690767831e-01,-5.9360423847e-02,1.1040771973e-01,-1.3690768069e-01,-5.9360418568e-02
|
||||
2.9702970297e-01,1.1306770152e-01,-1.3462040609e-01,-4.7213742425e-02,1.1306769690e-01,-1.3462040445e-01,-4.7213743269e-02
|
||||
3.0693069307e-01,1.1561828862e-01,-1.3181230529e-01,-3.4656247048e-02,1.1561828837e-01,-1.3181230802e-01,-3.4656246833e-02
|
||||
3.1683168317e-01,1.1805702504e-01,-1.2849425366e-01,-2.1797195258e-02,1.1805702662e-01,-1.2849425538e-01,-2.1797195856e-02
|
||||
3.2673267327e-01,1.2038155014e-01,-1.2467908448e-01,-8.7484830929e-03,1.2038155232e-01,-1.2467908343e-01,-8.7484808507e-03
|
||||
3.3663366337e-01,1.2258961573e-01,-1.2038155323e-01,4.3763575797e-03,1.2258961664e-01,-1.2038155232e-01,4.3763573469e-03
|
||||
3.4653465347e-01,1.2467908410e-01,-1.1561829169e-01,1.7463115474e-02,1.2467908343e-01,-1.1561828837e-01,1.7463115529e-02
|
||||
3.5643564356e-01,1.2664793338e-01,-1.1040771926e-01,3.0397924158e-02,1.2664793125e-01,-1.1040771973e-01,3.0397921832e-02
|
||||
3.6633663366e-01,1.2849425248e-01,-1.0477000407e-01,4.3068226361e-02,1.2849425538e-01,-1.0477000506e-01,4.3068226575e-02
|
||||
3.7623762376e-01,1.3021626897e-01,-9.8726953501e-02,5.5363781149e-02,1.3021626962e-01,-9.8726955606e-02,5.5363781583e-02
|
||||
3.8613861386e-01,1.3181230641e-01,-9.2301949069e-02,6.7177599971e-02,1.3181230802e-01,-9.2301950735e-02,6.7177599493e-02
|
||||
3.9603960396e-01,1.3328082420e-01,-8.5519846476e-02,7.8406881225e-02,1.3328082653e-01,-8.5519847548e-02,7.8406884685e-02
|
||||
4.0594059406e-01,1.3462040441e-01,-7.8406886916e-02,8.8953928507e-02,1.3462040445e-01,-7.8406884685e-02,8.8953927731e-02
|
||||
4.1584158416e-01,1.3582974237e-01,-7.0990582377e-02,9.8726952665e-02,1.3582974582e-01,-7.0990580816e-02,9.8726955606e-02
|
||||
4.2574257426e-01,1.3690768207e-01,-6.3299628825e-02,1.0764092847e-01,1.3690768069e-01,-6.3299628182e-02,1.0764093022e-01
|
||||
4.3564356436e-01,1.3785316922e-01,-5.5363784270e-02,1.1561828790e-01,1.3785316621e-01,-5.5363781583e-02,1.1561828837e-01
|
||||
4.4554455446e-01,1.3866529183e-01,-4.7213741970e-02,1.2258961490e-01,1.3866528771e-01,-4.7213743269e-02,1.2258961664e-01
|
||||
4.5544554455e-01,1.3934325896e-01,-3.8881046285e-02,1.2849425510e-01,1.3934325949e-01,-3.8881044154e-02,1.2849425538e-01
|
||||
4.6534653465e-01,1.3988642934e-01,-3.0397919107e-02,1.3328083063e-01,1.3988642566e-01,-3.0397921832e-02,1.3328082653e-01
|
||||
4.7524752475e-01,1.4029425867e-01,-2.1797194223e-02,1.3690767978e-01,1.4029426076e-01,-2.1797195856e-02,1.3690768069e-01
|
||||
4.8514851485e-01,1.4056637371e-01,-1.3112142627e-02,1.3934326030e-01,1.4056637021e-01,-1.3112140764e-02,1.3934325949e-01
|
||||
4.9504950495e-01,1.4070249059e-01,-4.3763545931e-03,1.4056637087e-01,1.4070249079e-01,-4.3763573469e-03,1.4056637021e-01
|
||||
5.0495049505e-01,1.4070249237e-01,4.3763553240e-03,1.4056636855e-01,1.4070249079e-01,4.3763573469e-03,1.4056637021e-01
|
||||
5.1485148515e-01,1.4056636701e-01,1.3112141424e-02,1.3934326274e-01,1.4056637021e-01,1.3112140764e-02,1.3934325949e-01
|
||||
5.2475247525e-01,1.4029426479e-01,2.1797196040e-02,1.3690767734e-01,1.4029426076e-01,2.1797195856e-02,1.3690768069e-01
|
||||
5.3465346535e-01,1.3988642418e-01,3.0397922181e-02,1.3328082645e-01,1.3988642566e-01,3.0397921832e-02,1.3328082653e-01
|
||||
5.4455445545e-01,1.3934325818e-01,3.8881045170e-02,1.2849425588e-01,1.3934325949e-01,3.8881044154e-02,1.2849425538e-01
|
||||
5.5445544554e-01,1.3866528548e-01,4.7213739894e-02,1.2258961529e-01,1.3866528771e-01,4.7213743269e-02,1.2258961664e-01
|
||||
5.6435643564e-01,1.3785316347e-01,5.5363782200e-02,1.1561828838e-01,1.3785316621e-01,5.5363781583e-02,1.1561828837e-01
|
||||
5.7425742574e-01,1.3690767808e-01,6.3299625555e-02,1.0764093012e-01,1.3690768069e-01,6.3299628182e-02,1.0764093022e-01
|
||||
5.8415841584e-01,1.3582975080e-01,7.0990579118e-02,9.8726956974e-02,1.3582974582e-01,7.0990580816e-02,9.8726955606e-02
|
||||
5.9405940594e-01,1.3462040473e-01,7.8406883764e-02,8.8953931156e-02,1.3462040445e-01,7.8406884685e-02,8.8953927731e-02
|
||||
6.0396039604e-01,1.3328082628e-01,8.5519847508e-02,7.8406882521e-02,1.3328082653e-01,8.5519847548e-02,7.8406884685e-02
|
||||
6.1386138614e-01,1.3181231043e-01,9.2301955750e-02,6.7177597738e-02,1.3181230802e-01,9.2301950735e-02,6.7177599493e-02
|
||||
6.2376237624e-01,1.3021627254e-01,9.8726959125e-02,5.5363781584e-02,1.3021626962e-01,9.8726955606e-02,5.5363781583e-02
|
||||
6.3366336634e-01,1.2849425843e-01,1.0477000685e-01,4.3068225262e-02,1.2849425538e-01,1.0477000506e-01,4.3068226575e-02
|
||||
6.4356435644e-01,1.2664792968e-01,1.1040772008e-01,3.0397923775e-02,1.2664793125e-01,1.1040771973e-01,3.0397921832e-02
|
||||
6.5346534653e-01,1.2467908233e-01,1.1561828667e-01,1.7463112100e-02,1.2467908343e-01,1.1561828837e-01,1.7463115529e-02
|
||||
6.6336633663e-01,1.2258961618e-01,1.2038154892e-01,4.3763558959e-03,1.2258961664e-01,1.2038155232e-01,4.3763573469e-03
|
||||
6.7326732673e-01,1.2038155509e-01,1.2467908434e-01,-8.7484791158e-03,1.2038155232e-01,1.2467908343e-01,-8.7484808507e-03
|
||||
6.8316831683e-01,1.1805702847e-01,1.2849425619e-01,-2.1797195967e-02,1.1805702662e-01,1.2849425538e-01,-2.1797195856e-02
|
||||
6.9306930693e-01,1.1561828622e-01,1.3181230822e-01,-3.4656246425e-02,1.1561828837e-01,1.3181230802e-01,-3.4656246833e-02
|
||||
7.0297029703e-01,1.1306768997e-01,1.3462040633e-01,-4.7213742058e-02,1.1306769690e-01,1.3462040445e-01,-4.7213743269e-02
|
||||
7.1287128713e-01,1.1040771799e-01,1.3690767691e-01,-5.9360418526e-02,1.1040771973e-01,1.3690768069e-01,-5.9360418568e-02
|
||||
7.2277227723e-01,1.0764092776e-01,1.3866528979e-01,-7.0990581227e-02,1.0764093022e-01,1.3866528771e-01,-7.0990580816e-02
|
||||
7.3267326733e-01,1.0477000620e-01,1.3988642119e-01,-8.2003033815e-02,1.0477000506e-01,1.3988642566e-01,-8.2003032435e-02
|
||||
7.4257425743e-01,1.0179772152e-01,1.4056636623e-01,-9.2301952893e-02,1.0179772170e-01,1.4056637021e-01,-9.2301950735e-02
|
||||
7.5247524752e-01,9.8726952848e-02,1.4070249392e-01,-1.0179771955e-01,9.8726955606e-02,1.4070249079e-01,-1.0179772170e-01
|
||||
7.6237623762e-01,9.5560678408e-02,1.4029425948e-01,-1.1040772236e-01,9.5560677562e-02,1.4029426076e-01,-1.1040771973e-01
|
||||
7.7227722772e-01,9.2301954838e-02,1.3934326416e-01,-1.1805702951e-01,9.2301950735e-02,1.3934325949e-01,-1.1805702662e-01
|
||||
7.8217821782e-01,8.8953928903e-02,1.3785316849e-01,-1.2467908256e-01,8.8953927731e-02,1.3785316621e-01,-1.2467908343e-01
|
||||
7.9207920792e-01,8.5519848124e-02,1.3582974727e-01,-1.3021626851e-01,8.5519847548e-02,1.3582974582e-01,-1.3021626962e-01
|
||||
8.0198019802e-01,8.2003030909e-02,1.3328082828e-01,-1.3462040327e-01,8.2003032435e-02,1.3328082653e-01,-1.3462040445e-01
|
||||
8.1188118812e-01,7.8406885186e-02,1.3021626587e-01,-1.3785316474e-01,7.8406884685e-02,1.3021626962e-01,-1.3785316621e-01
|
||||
8.2178217822e-01,7.4734885540e-02,1.2664793089e-01,-1.3988642777e-01,7.4734883337e-02,1.2664793125e-01,-1.3988642566e-01
|
||||
8.3168316832e-01,7.0990582072e-02,1.2258961409e-01,-1.4070248742e-01,7.0990580816e-02,1.2258961664e-01,-1.4070249079e-01
|
||||
8.4158415842e-01,6.7177598843e-02,1.1805702585e-01,-1.4029426160e-01,6.7177599493e-02,1.1805702662e-01,-1.4029426076e-01
|
||||
8.5148514851e-01,6.3299627125e-02,1.1306769708e-01,-1.3866528902e-01,6.3299628182e-02,1.1306769690e-01,-1.3866528771e-01
|
||||
8.6138613861e-01,5.9360415245e-02,1.0764093150e-01,-1.3582974369e-01,5.9360418568e-02,1.0764093022e-01,-1.3582974582e-01
|
||||
8.7128712871e-01,5.5363784218e-02,1.0179772269e-01,-1.3181231038e-01,5.5363781583e-02,1.0179772170e-01,-1.3181230802e-01
|
||||
8.8118811881e-01,5.1313579361e-02,9.5560678437e-02,-1.2664793139e-01,5.1313583715e-02,9.5560677562e-02,-1.2664793125e-01
|
||||
8.9108910891e-01,4.7213741091e-02,8.8953928103e-02,-1.2038155214e-01,4.7213743269e-02,8.8953927731e-02,-1.2038155232e-01
|
||||
9.0099009901e-01,4.3068225595e-02,8.2003031564e-02,-1.1306769867e-01,4.3068226575e-02,8.2003032435e-02,-1.1306769690e-01
|
||||
9.1089108911e-01,3.8881045999e-02,7.4734883659e-02,-1.0477000196e-01,3.8881044154e-02,7.4734883337e-02,-1.0477000506e-01
|
||||
9.2079207921e-01,3.4656245355e-02,6.7177597583e-02,-9.5560676903e-02,3.4656246833e-02,6.7177599493e-02,-9.5560677562e-02
|
||||
9.3069306931e-01,3.0397926577e-02,5.9360420731e-02,-8.5519850964e-02,3.0397921832e-02,5.9360418568e-02,-8.5519847548e-02
|
||||
9.4059405941e-01,2.6110186824e-02,5.1313584318e-02,-7.4734880388e-02,2.6110188805e-02,5.1313583715e-02,-7.4734883337e-02
|
||||
9.5049504950e-01,2.1797196485e-02,4.3068226072e-02,-6.3299628759e-02,2.1797195856e-02,4.3068226575e-02,-6.3299628182e-02
|
||||
9.6039603960e-01,1.7463116664e-02,3.4656247119e-02,-5.1313584252e-02,1.7463115529e-02,3.4656246833e-02,-5.1313583715e-02
|
||||
9.7029702970e-01,1.3112143651e-02,2.6110184365e-02,-3.8881045879e-02,1.3112140764e-02,2.6110188805e-02,-3.8881044154e-02
|
||||
9.8019801980e-01,8.7484791764e-03,1.7463117510e-02,-2.6110190428e-02,8.7484808507e-03,1.7463115529e-02,-2.6110188805e-02
|
||||
9.9009900990e-01,4.3763588619e-03,8.7484790494e-03,-1.3112138188e-02,4.3763573469e-03,8.7484808507e-03,-1.3112140764e-02
|
||||
1.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00,0.0000000000e+00
|
||||
|
@ -1,97 +0,0 @@
|
||||
N,T
|
||||
5,32
|
||||
6,51
|
||||
7,68
|
||||
8,103
|
||||
9,127
|
||||
10,160
|
||||
11,199
|
||||
12,248
|
||||
13,281
|
||||
14,346
|
||||
15,406
|
||||
16,459
|
||||
17,530
|
||||
18,593
|
||||
19,659
|
||||
20,742
|
||||
21,839
|
||||
22,892
|
||||
23,982
|
||||
24,1087
|
||||
25,1168
|
||||
26,1264
|
||||
27,1385
|
||||
28,1463
|
||||
29,1615
|
||||
30,1715
|
||||
31,1850
|
||||
32,1971
|
||||
33,2106
|
||||
34,2211
|
||||
35,2384
|
||||
36,2501
|
||||
37,2674
|
||||
38,2836
|
||||
39,3007
|
||||
40,3118
|
||||
41,3262
|
||||
42,3476
|
||||
43,3616
|
||||
44,3836
|
||||
45,3987
|
||||
46,4219
|
||||
47,4360
|
||||
48,4593
|
||||
49,4747
|
||||
50,4957
|
||||
51,5185
|
||||
52,5344
|
||||
53,5602
|
||||
54,5790
|
||||
55,6069
|
||||
56,6271
|
||||
57,6473
|
||||
58,6764
|
||||
59,6957
|
||||
60,7235
|
||||
61,7514
|
||||
62,7675
|
||||
63,7985
|
||||
64,8242
|
||||
65,8534
|
||||
66,8718
|
||||
67,8997
|
||||
68,9330
|
||||
69,9602
|
||||
70,9930
|
||||
71,10181
|
||||
72,10451
|
||||
73,10812
|
||||
74,11076
|
||||
75,11364
|
||||
76,11719
|
||||
77,12054
|
||||
78,12368
|
||||
79,12654
|
||||
80,13032
|
||||
81,13392
|
||||
82,13736
|
||||
83,14043
|
||||
84,14408
|
||||
85,14682
|
||||
86,15134
|
||||
87,15503
|
||||
88,15850
|
||||
89,16246
|
||||
90,16565
|
||||
91,16993
|
||||
92,17336
|
||||
93,17636
|
||||
94,18073
|
||||
95,18461
|
||||
96,18968
|
||||
97,19335
|
||||
98,19709
|
||||
99,20207
|
||||
100,20593
|
||||
|
@ -1,97 +0,0 @@
|
||||
N,T
|
||||
5,35
|
||||
6,41
|
||||
7,78
|
||||
8,104
|
||||
9,135
|
||||
10,177
|
||||
11,222
|
||||
12,264
|
||||
13,305
|
||||
14,335
|
||||
15,417
|
||||
16,460
|
||||
17,537
|
||||
18,606
|
||||
19,688
|
||||
20,756
|
||||
21,840
|
||||
22,917
|
||||
23,1017
|
||||
24,1095
|
||||
25,1207
|
||||
26,1298
|
||||
27,1420
|
||||
28,1492
|
||||
29,1629
|
||||
30,1766
|
||||
31,1869
|
||||
32,1965
|
||||
33,2132
|
||||
34,2275
|
||||
35,2403
|
||||
36,2570
|
||||
37,2670
|
||||
38,2794
|
||||
39,2962
|
||||
40,3169
|
||||
41,3284
|
||||
42,3469
|
||||
43,3619
|
||||
44,3840
|
||||
45,3977
|
||||
46,4161
|
||||
47,4406
|
||||
48,4523
|
||||
49,4710
|
||||
50,4919
|
||||
51,5207
|
||||
52,5336
|
||||
53,5582
|
||||
54,5801
|
||||
55,5997
|
||||
56,6248
|
||||
57,6465
|
||||
58,6694
|
||||
59,6911
|
||||
60,7078
|
||||
61,7355
|
||||
62,7618
|
||||
63,7880
|
||||
64,8170
|
||||
65,8407
|
||||
66,8651
|
||||
67,8899
|
||||
68,9139
|
||||
69,9478
|
||||
70,9786
|
||||
71,10059
|
||||
72,10325
|
||||
73,10608
|
||||
74,10887
|
||||
75,11223
|
||||
76,11514
|
||||
77,11794
|
||||
78,12120
|
||||
79,12420
|
||||
80,12738
|
||||
81,13111
|
||||
82,13402
|
||||
83,13772
|
||||
84,14018
|
||||
85,14393
|
||||
86,14820
|
||||
87,15096
|
||||
88,15451
|
||||
89,15866
|
||||
90,16243
|
||||
91,16688
|
||||
92,16864
|
||||
93,17359
|
||||
94,17701
|
||||
95,18027
|
||||
96,18473
|
||||
97,18810
|
||||
98,19231
|
||||
99,19573
|
||||
100,19992
|
||||
|
@ -12,5 +12,5 @@ Scaling will result in a dimensionless variable $\hat{x} = \frac{1}{L}$.
|
||||
\end{align*}
|
||||
Now we insert the expression into the original equation
|
||||
\begin{align*}
|
||||
\frac{d u(\hat{x})}{d\hat{x}^{2}} &= - \frac{F L^{2}}{\gamma} u(\hat{x}). \\
|
||||
\end{align*}
|
||||
\frac{d u(\hat{x})}{d\hat{x}^{2}} &= - \frac{F L^{2}}{\gamma} u(\hat{x}) \\
|
||||
\end{align*}
|
||||
@ -1,6 +1,2 @@
|
||||
\section*{Problem 2}
|
||||
|
||||
The functions that set up the tridiagonal matrices can be found in
|
||||
\textbf{matrix.hpp} and \textbf{matrix.cpp} in the Github repo.
|
||||
|
||||
The test for this can be found in \textbf{test\_suite.cpp}.
|
||||
|
||||
@ -1,10 +1 @@
|
||||
\section*{Problem 3}
|
||||
|
||||
\subsection*{a)}
|
||||
|
||||
The function to find the largest off-diagonal can be found in
|
||||
\textbf{matrix.hpp} and \textbf{matrix.cpp}.
|
||||
|
||||
\subsection*{b)}
|
||||
|
||||
The test for (a) can be found in \textbf{test\_suite.cpp}.
|
||||
\section*{Problem 3}
|
||||
@ -1,10 +1 @@
|
||||
\section*{Problem 4}
|
||||
|
||||
\subsection*{a)}
|
||||
|
||||
The code for Jacobi's rotation algorithm can be found in \textbf{jacobi.hpp}
|
||||
and \textbf{jacobi.cpp}.
|
||||
|
||||
\subsection*{b)}
|
||||
|
||||
The test for (a) can be found in \textbf{test\_suite.cpp}.
|
||||
\section*{Problem 4}
|
||||
@ -1,20 +1 @@
|
||||
\section*{Problem 5}
|
||||
|
||||
\subsection*{a)}
|
||||
We used the Jacobi's rotation method to solve $\boldsymbol{A} \vec{v} = \lambda \vec{v}$, for $\boldsymbol{A}_{(N \cross N)}$ with $N \in [5, 100]$,
|
||||
and increased the matrix size by $3$ rows and columns for every new matrix generated. The number of similarity transformations performed for a tridiagonal matrix
|
||||
of is presented in Figure \ref{fig:transform}. We chose to run the program using dense matrices of same size as the tridiagonal matrices, to compare the scaling data.
|
||||
What we see is that the number of similarity transformations necessary to solve the system is proportional to the matrix size.
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
\includegraphics[width=0.8\textwidth]{images/transform.pdf}
|
||||
\caption{Similarity transformations performed as a function of matrix size (N), data is presented in a logarithmic scale.}
|
||||
\label{fig:transform}
|
||||
\end{figure}
|
||||
|
||||
\subsection*{b)}
|
||||
For both the tridiagonal and dense matrices we are checking off-diagonal elements above the main diagonal, since these are symmetric matrices.
|
||||
The max value is found at index $(k,l)$ and for every rotation of the matrix, we update the remaining elements along row $k$ and $l$. This can lead to an increased
|
||||
value of off-diagonal elements, that previously were close to zero, and extra rotations has to be performed due to these elements. Which suggest that the
|
||||
number of similarity transformations perfomed on a matrix does not depend on its initial number of non-zero elements, making the Jacobi's rotation algorithm as
|
||||
computationally expensive for both dense and tridiagonal matrices of size $N \cross N$.
|
||||
\section*{Problem 5}
|
||||
@ -1,21 +1 @@
|
||||
\section*{Problem 6}
|
||||
|
||||
\subsection*{a)}
|
||||
The plot in Figure \ref{fig:eigenvector_10} is showing the discretization of $\hat{x}$ with $n=10$.
|
||||
The eigenvectors and corresponding analytical eigenvectors have a complete overlap suggesting the implementation of the algorithm is correct.
|
||||
We have included the boundary points for each vector to show a complete solution.
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
\includegraphics[width=0.8\textwidth]{images/eigenvector_10.pdf}
|
||||
\caption{The plot is showing the elements of eigenvector $\vec{v}_{1}, \vec{v}_{2}, \vec{v}_{3}$, corresponding to the three lowest eigenvalues of matrix $\boldsymbol{A} (10 \cross 10)$, against the position $\hat{x}$. The analytical eigenvectors $\vec{v}^{(1)}, \vec{v}^{(2)}, \vec{v}^{(3)}$ are also included in the plot.}
|
||||
\label{fig:eigenvector_10}
|
||||
\end{figure}
|
||||
|
||||
\subsection*{b)}
|
||||
For the discretization with $n=100$ the solution is visually close to a continuous curve, with a complete overlap of the analytical eigenvectors, presented in Figure \ref{fig:eigenvector_100}.
|
||||
\begin{figure}
|
||||
\centering
|
||||
\includegraphics[width=0.8\textwidth]{images/eigenvector_100.pdf}
|
||||
\caption{The plot is showing the elements of eigenvector $\vec{v}_{1}, \vec{v}_{2}, \vec{v}_{3}$, corresponding to the three lowest eigenvalues of matrix $\boldsymbol{A} (100 \cross 100)$, against the position $\hat{x}$. The analytical eigenvectors $\vec{v}^{(1)}, \vec{v}^{(2)}, \vec{v}^{(3)}$ are also included in the plot.}
|
||||
\label{fig:eigenvector_100}
|
||||
\end{figure}
|
||||
\section*{Problem 6}
|
||||
37
src/Makefile
37
src/Makefile
@ -1,42 +1,19 @@
|
||||
CC=g++
|
||||
|
||||
LIBSRCS=utils.cpp matrix.cpp jacobi.cpp
|
||||
LIBOBJS=$(LIBSRCS:.cpp=.o)
|
||||
|
||||
INCLUDE=../include
|
||||
|
||||
CFLAGS=-larmadillo -llapack -std=c++11
|
||||
OPENMP=-fopenmp
|
||||
CC=g++
|
||||
|
||||
# Add a debug flag when compiling (For the DEBUG macro in utils.hpp)
|
||||
DEBUG ?= 0
|
||||
ifeq ($(DEBUG), 1)
|
||||
DBGFLAG=-DDBG
|
||||
else
|
||||
DBGFLAG=
|
||||
endif
|
||||
CCFLAGS=-larmadillo -llapack -std=c++11
|
||||
|
||||
DEBUG=-DDBG
|
||||
|
||||
.PHONY: doxygen clean
|
||||
.PHONY: clean
|
||||
|
||||
all: test_suite main
|
||||
test_suite: test_suite.o matrix.o jacobi.o
|
||||
$(CC) $^ -o $@ $(CCFLAGS) $(DEBUG)
|
||||
|
||||
# Rules for executables
|
||||
main: main.o $(LIBOBJS)
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
test_suite: test_suite.o $(LIBOBJS)
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(DBGFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
# Rule for object files
|
||||
%.o: %.cpp
|
||||
$(CC) -c $^ -o $@ $(DBGFLAG) -I$(INCLUDE) $(OPENMP)
|
||||
|
||||
# Make documentation
|
||||
doxygen:
|
||||
doxygen
|
||||
$(CC) -c $^ -o $@ -I $(INCLUDE) $(DEBUG)
|
||||
|
||||
clean:
|
||||
rm *.o
|
||||
rm test_suite
|
||||
rm main
|
||||
|
||||
@ -72,7 +72,7 @@ void jacobi_eigensolver(const arma::mat& A,
|
||||
|
||||
// Use a do while so that max_offdiag gets a value before doing a comparison
|
||||
do {
|
||||
max_offdiag = max_offdiag_symmetric(A_m, k, l);
|
||||
max_offdiag = max_offdiag_symmetric(A_m, k, l);
|
||||
jacobi_rotate(A_m, R, k, l);
|
||||
|
||||
} while (max_offdiag >= eps && ++iterations < maxiter);
|
||||
|
||||
175
src/main.cpp
175
src/main.cpp
@ -1,175 +0,0 @@
|
||||
/** @file main.cpp
|
||||
* @brief Main program for Project 2
|
||||
*
|
||||
* The program performs the Jacobi rotation method.
|
||||
* The size of the matrix, and number of transformations
|
||||
* performed are written to file.
|
||||
* Eigenvector corresponding to the 3 smallest eigenvalues
|
||||
* for matrices of size 10x10 and 100x100 are written to file.
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
* @author Janita Ovidie Sandtrøen Willumsen (janitaws)
|
||||
* @bug No known bugs
|
||||
*/
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <omp.h>
|
||||
#include <ostream>
|
||||
|
||||
#include "utils.hpp"
|
||||
#include "matrix.hpp"
|
||||
#include "jacobi.hpp"
|
||||
|
||||
|
||||
void write_transformation_dense(int N)
|
||||
{
|
||||
std::ofstream ofile;
|
||||
|
||||
ofile.open("../latex/output/transform_dense.csv");
|
||||
ofile << "N,T" << std::endl;
|
||||
|
||||
// Increase size of matrix, start at 5 to avoid logic_error of N=4
|
||||
#pragma omp parallel for ordered schedule(static, 1)
|
||||
for (int i = 5; i <= N; i++) {
|
||||
arma::mat A = arma::mat(i, i).randn();
|
||||
A = arma::symmatu(A);
|
||||
arma::vec eigval;
|
||||
arma::mat eigvec;
|
||||
|
||||
int iters;
|
||||
bool converged;
|
||||
|
||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||
|
||||
// Write size, and number of iterations to file
|
||||
#pragma omp ordered
|
||||
{
|
||||
ofile << i << "," << iters << std::endl;
|
||||
}
|
||||
}
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
|
||||
void write_transformation_tridiag(int N)
|
||||
{
|
||||
std::ofstream ofile;
|
||||
|
||||
double h;
|
||||
double a, d;
|
||||
|
||||
ofile.open("../latex/output/transform_tridiag.csv");
|
||||
// Write header line to file
|
||||
ofile << "N,T" << std::endl;
|
||||
|
||||
// Increase size of matrix, start at 5 to avoid logic_error of N=4
|
||||
#pragma omp parallel for ordered schedule(static, 1)
|
||||
for (int i = 5; i <= N; i++) {
|
||||
h = 1. / (double) (i+1);
|
||||
a = -1. / (h*h), d = 2. / (h*h);
|
||||
|
||||
arma::mat A = create_symmetric_tridiagonal(i, a, d);
|
||||
arma::vec eigval;
|
||||
arma::mat eigvec;
|
||||
|
||||
int iters;
|
||||
bool converged;
|
||||
|
||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||
|
||||
// Write size, and number of iterations to file
|
||||
#pragma omp ordered
|
||||
{
|
||||
ofile << i << "," << iters << std::endl;
|
||||
}
|
||||
}
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
|
||||
void write_eigenvec(int N)
|
||||
{
|
||||
double h = 1. / (double) (N+1);
|
||||
double a = -1. / (h*h);
|
||||
double d = 2. / (h*h);
|
||||
double x = 0.;
|
||||
|
||||
// Create tridiagonal matrix
|
||||
arma::mat A = create_symmetric_tridiagonal(N, a, d);
|
||||
arma::mat analytic = arma::mat(N, N);
|
||||
arma::vec eigval;
|
||||
arma::mat eigvec;
|
||||
|
||||
int iters;
|
||||
bool converged;
|
||||
|
||||
// Solve using Jacobi rotation method
|
||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||
|
||||
// Build analytic eigenvectors
|
||||
arma::vec v, analytic_vec = arma::vec(N);
|
||||
for (int i=0; i < N; i++) {
|
||||
v = eigvec.col(i);
|
||||
|
||||
for (int j=0; j < N; j++) {
|
||||
analytic_vec(j) = std::sin(((j+1.)*(i+1.)*M_PI) / (N+1.));
|
||||
}
|
||||
|
||||
analytic_vec = arma::normalise(analytic_vec);
|
||||
|
||||
// Flip the sign of the analytic vector if they are different
|
||||
if (analytic_vec(0)*v(0) < 0.) {
|
||||
analytic_vec *= -1;
|
||||
}
|
||||
analytic.col(i) = analytic_vec;
|
||||
}
|
||||
|
||||
std::ofstream ofile;
|
||||
// Create file based on matrix size, and write header line to file
|
||||
ofile.open("../latex/output/eigenvector_" + std::to_string(N) + ".csv");
|
||||
ofile << "x,"
|
||||
<< "Vector 1,Vector 2,Vector 3,"
|
||||
<< "Analytic 1,Analytic 2,Analytic 3" << std::endl;
|
||||
|
||||
// Add boundary value for x=0
|
||||
ofile << scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << std::endl;
|
||||
|
||||
// Add x-value and element i of each eigenvector to same line
|
||||
for (int i = 0; i < N; i++) {
|
||||
x += h;
|
||||
ofile << scientific_format(x, 16)<< ","
|
||||
<< scientific_format(eigvec(i,0), 16) << ","
|
||||
<< scientific_format(eigvec(i,1), 16) << ","
|
||||
<< scientific_format(eigvec(i,2), 16) << ","
|
||||
<< scientific_format(analytic(i,0), 16) << ","
|
||||
<< scientific_format(analytic(i,1), 16) << ","
|
||||
<< scientific_format(analytic(i,2), 16) << std::endl;
|
||||
}
|
||||
// Add boundary value for x=1
|
||||
ofile << scientific_format(1., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << ","
|
||||
<< scientific_format(0., 16) << std::endl;
|
||||
ofile.close();
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
write_transformation_tridiag(100);
|
||||
write_transformation_dense(100);
|
||||
write_eigenvec(10);
|
||||
write_eigenvec(100);
|
||||
return 0;
|
||||
}
|
||||
@ -20,7 +20,6 @@ arma::mat create_tridiagonal(
|
||||
A(0, 0) = d(0);
|
||||
A(0, 1) = e(0);
|
||||
|
||||
#pragma omp parallel for if(n > 50)
|
||||
for (int i = 1; i < n-1; i++) {
|
||||
A(i, i-1) = a(i-1);
|
||||
A(i, i) = d(i);
|
||||
|
||||
51
src/plot.py
51
src/plot.py
@ -1,51 +0,0 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
import seaborn as sns
|
||||
|
||||
sns.set_theme()
|
||||
plt.rcParams['text.usetex'] = True
|
||||
|
||||
|
||||
def plot_transformations(save: bool=False) -> None:
|
||||
# Load data
|
||||
tridiag = pd.read_csv("../latex/output/transform_tridiag.csv", header=0)
|
||||
dense = pd.read_csv("../latex/output/transform_dense.csv", header=0)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.loglog(dense['N'], dense['T'], '--', label='Dense')
|
||||
ax.loglog(tridiag['N'], tridiag['T'], label='Tridiagonal')
|
||||
ax.set_xlabel('N')
|
||||
ax.set_ylabel('Similarity transformations')
|
||||
ax.legend()
|
||||
|
||||
# Save to file
|
||||
if save is True:
|
||||
fig.savefig("../latex/images/transform.pdf")
|
||||
|
||||
|
||||
def plot_eigenvectors(N: int, save: bool=False) -> None:
|
||||
# Load data based on matrix size
|
||||
path = f"../latex/output/eigenvector_{N}.csv"
|
||||
eigvec = pd.read_csv(path, header=0)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.plot(eigvec['x'], eigvec['Vector 1'], label=r'$\vec{v}_{1}$')
|
||||
ax.plot(eigvec['x'], eigvec['Vector 2'], label=r'$\vec{v}_{2}$')
|
||||
ax.plot(eigvec['x'], eigvec['Vector 3'], label=r'$\vec{v}_{3}$')
|
||||
ax.plot(eigvec['x'], eigvec['Analytic 1'], '--', label=r'$\vec{v}^{(1)}$')
|
||||
ax.plot(eigvec['x'], eigvec['Analytic 2'], '--', label=r'$\vec{v}^{(2)}$')
|
||||
ax.plot(eigvec['x'], eigvec['Analytic 3'], '--', label=r'$\vec{v}^{(3)}$')
|
||||
ax.set_xlabel(r'Element $\hat{x}_{i}$')
|
||||
ax.set_ylabel(r'Element $v_{i}$')
|
||||
ax.legend(loc='upper left')
|
||||
|
||||
# Save to file
|
||||
if save is True:
|
||||
fig.savefig(f"../latex/images/eigenvector_{N}.pdf")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
plot_transformations(True)
|
||||
plot_eigenvectors(10, True)
|
||||
plot_eigenvectors(100, True)
|
||||
Loading…
Reference in New Issue
Block a user