TheAlgorithms-C/d4/d68/qr__decompose_8h.html

545 lines
37 KiB
HTML
Raw Normal View History

<!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">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: numerical_methods/qr_decompose.h 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="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.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>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.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 style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C
&#160;<span id="projectnumber">1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @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:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('d4/d68/qr__decompose_8h.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- 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">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">qr_decompose.h File Reference</div> </div>
</div><!--header-->
<div class="contents">
<p>Library functions to compute <a href="https://en.wikipedia.org/wiki/QR_decomposition">QR decomposition</a> of a given matrix.
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;math.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for qr_decompose.h:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d04/qr__decompose_8h__incl.svg" width="248" height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><div class="textblock"><div class="dynheader">
This graph shows which files directly or indirectly include this file:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dc/d5f/qr__decompose_8h__dep__incl.svg" width="336" height="142"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
<p><a href="../../d4/d68/qr__decompose_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a90562ce8c3707401e9c5809dece68d6a"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a">print_matrix</a> (double **A, int M, int <a class="el" href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>)</td></tr>
<tr class="separator:a90562ce8c3707401e9c5809dece68d6a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3a584b79941a43d775f9d4ce446dbe05"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a> (double *a, double *b, int <a class="el" href="../../df/db3/struct_l.html">L</a>)</td></tr>
<tr class="separator:a3a584b79941a43d775f9d4ce446dbe05"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:abeec1f78a7a7e7251687e75340331212"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#abeec1f78a7a7e7251687e75340331212">vector_mag</a> (double *vector, int <a class="el" href="../../df/db3/struct_l.html">L</a>)</td></tr>
<tr class="separator:abeec1f78a7a7e7251687e75340331212"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a82b20e027437df768d7e994cf4cae29f"><td class="memItemLeft" align="right" valign="top">double *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#a82b20e027437df768d7e994cf4cae29f">vector_proj</a> (double *a, double *b, double *out, int <a class="el" href="../../df/db3/struct_l.html">L</a>)</td></tr>
<tr class="separator:a82b20e027437df768d7e994cf4cae29f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6b6a0e75e75ff7919057dd275bb69145"><td class="memItemLeft" align="right" valign="top">double *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#a6b6a0e75e75ff7919057dd275bb69145">vector_sub</a> (double *a, double *b, double *out, int <a class="el" href="../../df/db3/struct_l.html">L</a>)</td></tr>
<tr class="separator:a6b6a0e75e75ff7919057dd275bb69145"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a45c7640d9d22c89c11beb1f567843c56"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#a45c7640d9d22c89c11beb1f567843c56">qr_decompose</a> (double **A, double **Q, double **R, int M, int <a class="el" href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>)</td></tr>
<tr class="separator:a45c7640d9d22c89c11beb1f567843c56"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Library functions to compute <a href="https://en.wikipedia.org/wiki/QR_decomposition">QR decomposition</a> of a given matrix. </p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kvedala">Krishna Vedala</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a90562ce8c3707401e9c5809dece68d6a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a90562ce8c3707401e9c5809dece68d6a">&#9670;&nbsp;</a></span>print_matrix()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void print_matrix </td>
<td>(</td>
<td class="paramtype">double **&#160;</td>
<td class="paramname"><em>A</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>M</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>N</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>function to display matrix on stdout </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">A</td><td>matrix to print </td></tr>
<tr><td class="paramname">M</td><td>number of rows of matrix </td></tr>
<tr><td class="paramname">N</td><td>number of columns of matrix </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;{</div>
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> row = 0; row &lt; M; row++)</div>
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160; {</div>
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> col = 0; col &lt; <a class="code" href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>; col++) printf(<span class="stringliteral">&quot;% 9.3g\t&quot;</span>, A[row][col]);</div>
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160; putchar(<span class="charliteral">&#39;\n&#39;</span>);</div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160; }</div>
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160; putchar(<span class="charliteral">&#39;\n&#39;</span>);</div>
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="a45c7640d9d22c89c11beb1f567843c56"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a45c7640d9d22c89c11beb1f567843c56">&#9670;&nbsp;</a></span>qr_decompose()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void qr_decompose </td>
<td>(</td>
<td class="paramtype">double **&#160;</td>
<td class="paramname"><em>A</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double **&#160;</td>
<td class="paramname"><em>Q</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double **&#160;</td>
<td class="paramname"><em>R</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>M</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>N</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Decompose matrix \(A\) using <a href="https://en.wikipedia.org/wiki/QR_decomposition">Gram-Schmidt process</a>.</p>
<p class="formulaDsp">
\begin{eqnarray*} \text{given that}\quad A &amp;=&amp; *\left[\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_{N-1},\right]\\ \text{where}\quad\mathbf{a}_i &amp;=&amp; *\left[a_{0i},a_{1i},a_{2i},\ldots,a_{(M-1)i}\right]^T\quad\ldots\mbox{(column *vectors)}\\ \text{then}\quad\mathbf{u}_i &amp;=&amp; \mathbf{a}_i *-\sum_{j=0}^{i-1}\text{proj}_{\mathbf{u}_j}\mathbf{a}_i\\ \mathbf{e}_i &amp;=&amp;\frac{\mathbf{u}_i}{\left|\mathbf{u}_i\right|}\\ Q &amp;=&amp; \begin{bmatrix}\mathbf{e}_0 &amp; \mathbf{e}_1 &amp; \mathbf{e}_2 &amp; \dots &amp; *\mathbf{e}_{N-1}\end{bmatrix}\\ R &amp;=&amp; \begin{bmatrix}\langle\mathbf{e}_0\,,\mathbf{a}_0\rangle &amp; *\langle\mathbf{e}_1\,,\mathbf{a}_1\rangle &amp; *\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle &amp; \dots \\ 0 &amp; \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle &amp; *\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle &amp; \dots\\ 0 &amp; 0 &amp; \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle &amp; \dots\\ \vdots &amp; \vdots &amp; \vdots &amp; \ddots \end{bmatrix}\\ \end{eqnarray*}
</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">A</td><td>input matrix to decompose </td></tr>
<tr><td class="paramname">Q</td><td>output decomposed matrix </td></tr>
<tr><td class="paramname">R</td><td>output decomposed matrix </td></tr>
<tr><td class="paramname">M</td><td>number of rows of matrix A </td></tr>
<tr><td class="paramname">N</td><td>number of columns of matrix A </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160;{</div>
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160; <span class="keywordtype">double</span> *col_vector = (<span class="keywordtype">double</span> *)malloc(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>&#160; <span class="keywordtype">double</span> *col_vector2 = (<span class="keywordtype">double</span> *)malloc(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>&#160; <span class="keywordtype">double</span> *tmp_vector = (<span class="keywordtype">double</span> *)malloc(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>;</div>
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>&#160; i++) <span class="comment">/* for each column =&gt; R is a square matrix of NxN */</span></div>
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>&#160; {</div>
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span>&#160; <span class="keywordtype">int</span> j;</div>
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span>&#160;<span class="preprocessor">#ifdef _OPENMP</span></div>
<div class="line"><a name="l00157"></a><span class="lineno"> 157</span>&#160;<span class="comment">// parallelize on threads</span></div>
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span>&#160;<span class="preprocessor">#pragma omp for</span></div>
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>&#160; <span class="keywordflow">for</span> (j = 0; j &lt; i; j++) <span class="comment">/* second dimension of column */</span></div>
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span>&#160; R[i][j] = 0.; <span class="comment">/* make R upper triangular */</span></div>
<div class="line"><a name="l00162"></a><span class="lineno"> 162</span>&#160; </div>
<div class="line"><a name="l00163"></a><span class="lineno"> 163</span>&#160; <span class="comment">/* get corresponding Q vector */</span></div>
<div class="line"><a name="l00164"></a><span class="lineno"> 164</span>&#160;<span class="preprocessor">#ifdef _OPENMP</span></div>
<div class="line"><a name="l00165"></a><span class="lineno"> 165</span>&#160;<span class="comment">// parallelize on threads</span></div>
<div class="line"><a name="l00166"></a><span class="lineno"> 166</span>&#160;<span class="preprocessor">#pragma omp for</span></div>
<div class="line"><a name="l00167"></a><span class="lineno"> 167</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00168"></a><span class="lineno"> 168</span>&#160; <span class="keywordflow">for</span> (j = 0; j &lt; M; j++)</div>
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>&#160; {</div>
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span>&#160; tmp_vector[j] = A[j][i]; <span class="comment">/* accumulator for uk */</span></div>
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>&#160; col_vector[j] = A[j][i];</div>
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>&#160; }</div>
<div class="line"><a name="l00173"></a><span class="lineno"> 173</span>&#160; <span class="keywordflow">for</span> (j = 0; j &lt; i; j++)</div>
<div class="line"><a name="l00174"></a><span class="lineno"> 174</span>&#160; {</div>
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0; k &lt; M; k++) col_vector2[k] = Q[k][j];</div>
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>&#160; <a class="code" href="../../d4/d68/qr__decompose_8h.html#a82b20e027437df768d7e994cf4cae29f">vector_proj</a>(col_vector, col_vector2, col_vector2, M);</div>
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>&#160; <a class="code" href="../../d4/d68/qr__decompose_8h.html#a6b6a0e75e75ff7919057dd275bb69145">vector_sub</a>(tmp_vector, col_vector2, tmp_vector, M);</div>
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>&#160; }</div>
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>&#160; <span class="keywordtype">double</span> mag = <a class="code" href="../../d4/d68/qr__decompose_8h.html#abeec1f78a7a7e7251687e75340331212">vector_mag</a>(tmp_vector, M);</div>
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>&#160; </div>
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>&#160;<span class="preprocessor">#ifdef _OPENMP</span></div>
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>&#160;<span class="comment">// parallelize on threads</span></div>
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160;<span class="preprocessor">#pragma omp for</span></div>
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>&#160; <span class="keywordflow">for</span> (j = 0; j &lt; M; j++) Q[j][i] = tmp_vector[j] / mag;</div>
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>&#160; </div>
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>&#160; <span class="comment">/* compute upper triangular values of R */</span></div>
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> kk = 0; kk &lt; M; kk++) col_vector[kk] = Q[kk][i];</div>
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = i; k &lt; <a class="code" href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>; k++)</div>
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>&#160; {</div>
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> kk = 0; kk &lt; M; kk++) col_vector2[kk] = A[kk][k];</div>
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>&#160; R[i][k] = <a class="code" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(col_vector, col_vector2, M);</div>
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>&#160; }</div>
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>&#160; }</div>
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>&#160; </div>
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>&#160; free(col_vector);</div>
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>&#160; free(col_vector2);</div>
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span>&#160; free(tmp_vector);</div>
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>&#160;}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d68/qr__decompose_8h_a45c7640d9d22c89c11beb1f567843c56_cgraph.svg" width="387" height="156"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="a3a584b79941a43d775f9d4ce446dbe05"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3a584b79941a43d775f9d4ce446dbe05">&#9670;&nbsp;</a></span>vector_dot()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double vector_dot </td>
<td>(</td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>a</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>b</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>L</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Compute dot product of two vectors of equal lengths</p>
<p>If \(\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\) and \(\vec{b}=\left[b_0,b_1,b_1,...,b_L\right]\) then \(\vec{a}\cdot\vec{b}=\displaystyle\sum_{i=0}^L a_i\times b_i\)</p>
<dl class="section return"><dt>Returns</dt><dd>\(\vec{a}\cdot\vec{b}\) </dd></dl>
<div class="fragment"><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160;{</div>
<div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160; <span class="keywordtype">double</span> mag = 0.f;</div>
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160; <span class="keywordtype">int</span> i;</div>
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160;<span class="preprocessor">#ifdef _OPENMP</span></div>
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;<span class="comment">// parallelize on threads</span></div>
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160;<span class="preprocessor">#pragma omp parallel for reduction(+ : mag)</span></div>
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="../../df/db3/struct_l.html">L</a>; i++) mag += a[i] * b[i];</div>
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160; </div>
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; <span class="keywordflow">return</span> mag;</div>
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
<a id="abeec1f78a7a7e7251687e75340331212"></a>
<h2 class="memtitle"><span class="permalink"><a href="#abeec1f78a7a7e7251687e75340331212">&#9670;&nbsp;</a></span>vector_mag()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double vector_mag </td>
<td>(</td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>vector</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>L</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Compute magnitude of vector.</p>
<p>If \(\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\) then \(\left|\vec{a}\right|=\sqrt{\displaystyle\sum_{i=0}^L a_i^2}\)</p>
<dl class="section return"><dt>Returns</dt><dd>\(\left|\vec{a}\right|\) </dd></dl>
<div class="fragment"><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160;{</div>
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; <span class="keywordtype">double</span> dot = <a class="code" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(vector, vector, <a class="code" href="../../df/db3/struct_l.html">L</a>);</div>
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; <span class="keywordflow">return</span> sqrt(dot);</div>
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160;}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d68/qr__decompose_8h_abeec1f78a7a7e7251687e75340331212_cgraph.svg" width="232" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="a82b20e027437df768d7e994cf4cae29f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a82b20e027437df768d7e994cf4cae29f">&#9670;&nbsp;</a></span>vector_proj()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double* vector_proj </td>
<td>(</td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>a</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>b</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>out</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>L</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Compute projection of vector \(\vec{a}\) on \(\vec{b}\) defined as </p><p class="formulaDsp">
\[\text{proj}_\vec{b}\vec{a}=\frac{\vec{a}\cdot\vec{b}}{\left|\vec{b}\right|^2}\vec{b}\]
</p>
<dl class="section return"><dt>Returns</dt><dd>NULL if error, otherwise pointer to output </dd></dl>
<p>check for division by zero</p>
<div class="fragment"><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160;{</div>
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160; <span class="keyword">const</span> <span class="keywordtype">double</span> num = <a class="code" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(a, b, <a class="code" href="../../df/db3/struct_l.html">L</a>);</div>
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160; <span class="keyword">const</span> <span class="keywordtype">double</span> deno = <a class="code" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(b, b, <a class="code" href="../../df/db3/struct_l.html">L</a>);</div>
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160; <span class="keywordflow">if</span> (deno == 0) <span class="comment">/*! check for division by zero */</span></div>
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160; <span class="keywordflow">return</span> NULL;</div>
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160; </div>
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160; <span class="keyword">const</span> <span class="keywordtype">double</span> scalar = num / deno;</div>
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160; <span class="keywordtype">int</span> i;</div>
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160;<span class="preprocessor">#ifdef _OPENMP</span></div>
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>&#160;<span class="comment">// parallelize on threads</span></div>
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>&#160;<span class="preprocessor">#pragma omp for</span></div>
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160; <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="../../df/db3/struct_l.html">L</a>; i++) out[i] = scalar * b[i];</div>
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160; </div>
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160; <span class="keywordflow">return</span> out;</div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160;}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/d68/qr__decompose_8h_a82b20e027437df768d7e994cf4cae29f_cgraph.svg" width="228" height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="a6b6a0e75e75ff7919057dd275bb69145"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6b6a0e75e75ff7919057dd275bb69145">&#9670;&nbsp;</a></span>vector_sub()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double* vector_sub </td>
<td>(</td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>a</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>b</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double *&#160;</td>
<td class="paramname"><em>out</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>L</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Compute vector subtraction</p>
<p>\(\vec{c}=\vec{a}-\vec{b}\)</p>
<dl class="section return"><dt>Returns</dt><dd>pointer to output vector </dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">a</td><td>minuend </td></tr>
<tr><td class="paramname">b</td><td>subtrahend </td></tr>
<tr><td class="paramname">out</td><td>resultant vector </td></tr>
<tr><td class="paramname"><a class="el" href="../../df/db3/struct_l.html">L</a></td><td>length of vectors </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160;{</div>
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160; <span class="keywordtype">int</span> i;</div>
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160;<span class="preprocessor">#ifdef _OPENMP</span></div>
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160;<span class="comment">// parallelize on threads</span></div>
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160;<span class="preprocessor">#pragma omp for</span></div>
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>&#160; <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="../../df/db3/struct_l.html">L</a>; i++) out[i] = a[i] - b[i];</div>
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; </div>
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160; <span class="keywordflow">return</span> out;</div>
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160;}</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="astruct_l_html"><div class="ttname"><a href="../../df/db3/struct_l.html">L</a></div><div class="ttdef"><b>Definition:</b> list.h:8</div></div>
<div class="ttc" id="aqr__decompose_8h_html_abeec1f78a7a7e7251687e75340331212"><div class="ttname"><a href="../../d4/d68/qr__decompose_8h.html#abeec1f78a7a7e7251687e75340331212">vector_mag</a></div><div class="ttdeci">double vector_mag(double *vector, int L)</div><div class="ttdef"><b>Definition:</b> qr_decompose.h:64</div></div>
<div class="ttc" id="aqr__decompose_8h_html_a82b20e027437df768d7e994cf4cae29f"><div class="ttname"><a href="../../d4/d68/qr__decompose_8h.html#a82b20e027437df768d7e994cf4cae29f">vector_proj</a></div><div class="ttdeci">double * vector_proj(double *a, double *b, double *out, int L)</div><div class="ttdef"><b>Definition:</b> qr_decompose.h:76</div></div>
<div class="ttc" id="aproblem__13_2sol1_8c_html_a0240ac851181b84ac374872dc5434ee4"><div class="ttname"><a href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a></div><div class="ttdeci">#define N</div><div class="ttdef"><b>Definition:</b> sol1.c:109</div></div>
<div class="ttc" id="aqr__decompose_8h_html_a3a584b79941a43d775f9d4ce446dbe05"><div class="ttname"><a href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a></div><div class="ttdeci">double vector_dot(double *a, double *b, int L)</div><div class="ttdef"><b>Definition:</b> qr_decompose.h:43</div></div>
<div class="ttc" id="aqr__decompose_8h_html_a6b6a0e75e75ff7919057dd275bb69145"><div class="ttname"><a href="../../d4/d68/qr__decompose_8h.html#a6b6a0e75e75ff7919057dd275bb69145">vector_sub</a></div><div class="ttdeci">double * vector_sub(double *a, double *b, double *out, int L)</div><div class="ttdef"><b>Definition:</b> qr_decompose.h:101</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_9c6faab82c22511b50177aa2e38e2780.html">numerical_methods</a></li><li class="navelem"><a class="el" href="../../d4/d68/qr__decompose_8h.html">qr_decompose.h</a></li>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.8.18 </li>
</ul>
</div>
</body>
</html>