mirror of https://github.com/TheAlgorithms/C
577 lines
37 KiB
HTML
577 lines
37 KiB
HTML
<!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.8"/>
|
|
<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 id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">Algorithms_in_C<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.9.8 -->
|
|
<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>
|
|
</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:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(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">
|
|
<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 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" target="_blank">QR decomposition</a> of a given matrix.
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <math.h></code><br />
|
|
<code>#include <stdio.h></code><br />
|
|
<code>#include <stdlib.h></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="244" height="126"><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="334" height="140"><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 id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:a90562ce8c3707401e9c5809dece68d6a" id="r_a90562ce8c3707401e9c5809dece68d6a"><td class="memItemLeft" align="right" valign="top">void </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 N)</td></tr>
|
|
<tr class="memdesc:a90562ce8c3707401e9c5809dece68d6a"><td class="mdescLeft"> </td><td class="mdescRight">function to display matrix on stdout <br /></td></tr>
|
|
<tr class="separator:a90562ce8c3707401e9c5809dece68d6a"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a3a584b79941a43d775f9d4ce446dbe05" id="r_a3a584b79941a43d775f9d4ce446dbe05"><td class="memItemLeft" align="right" valign="top">double </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="memdesc:a3a584b79941a43d775f9d4ce446dbe05"><td class="mdescLeft"> </td><td class="mdescRight">Compute dot product of two vectors of equal lengths. <br /></td></tr>
|
|
<tr class="separator:a3a584b79941a43d775f9d4ce446dbe05"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:abeec1f78a7a7e7251687e75340331212" id="r_abeec1f78a7a7e7251687e75340331212"><td class="memItemLeft" align="right" valign="top">double </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="memdesc:abeec1f78a7a7e7251687e75340331212"><td class="mdescLeft"> </td><td class="mdescRight">Compute magnitude of vector. <br /></td></tr>
|
|
<tr class="separator:abeec1f78a7a7e7251687e75340331212"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a2ed4977f38642dca8b10c16a823c740b" id="r_a2ed4977f38642dca8b10c16a823c740b"><td class="memItemLeft" align="right" valign="top">double * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#a2ed4977f38642dca8b10c16a823c740b">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="memdesc:a2ed4977f38642dca8b10c16a823c740b"><td class="mdescLeft"> </td><td class="mdescRight">Compute projection of vector \(\vec{a}\) on \(\vec{b}\) defined as. <br /></td></tr>
|
|
<tr class="separator:a2ed4977f38642dca8b10c16a823c740b"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a5ee39e7c8fce8a604dcf7009ce101c02" id="r_a5ee39e7c8fce8a604dcf7009ce101c02"><td class="memItemLeft" align="right" valign="top">double * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d68/qr__decompose_8h.html#a5ee39e7c8fce8a604dcf7009ce101c02">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="memdesc:a5ee39e7c8fce8a604dcf7009ce101c02"><td class="mdescLeft"> </td><td class="mdescRight">Compute vector subtraction. <br /></td></tr>
|
|
<tr class="separator:a5ee39e7c8fce8a604dcf7009ce101c02"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a45c7640d9d22c89c11beb1f567843c56" id="r_a45c7640d9d22c89c11beb1f567843c56"><td class="memItemLeft" align="right" valign="top">void </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 N)</td></tr>
|
|
<tr class="memdesc:a45c7640d9d22c89c11beb1f567843c56"><td class="mdescLeft"> </td><td class="mdescRight">Decompose matrix \(A\) using <a href="https://en.wikipedia.org/wiki/QR_decomposition" target="_blank">Gram-Schmidt process</a>. <br /></td></tr>
|
|
<tr class="separator:a45c7640d9d22c89c11beb1f567843c56"><td class="memSeparator" colspan="2"> </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" target="_blank">QR decomposition</a> of a given matrix. </p>
|
|
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kvedala" target="_blank">Krishna Vedala</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a90562ce8c3707401e9c5809dece68d6a" name="a90562ce8c3707401e9c5809dece68d6a"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a90562ce8c3707401e9c5809dece68d6a">◆ </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 ** </td>
|
|
<td class="paramname"><em>A</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>M</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>N</em> </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"><span class="lineno"> 25</span>{</div>
|
|
<div class="line"><span class="lineno"> 26</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> row = 0; row < M; row++)</div>
|
|
<div class="line"><span class="lineno"> 27</span> {</div>
|
|
<div class="line"><span class="lineno"> 28</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> col = 0; col < N; col++) printf(<span class="stringliteral">"% 9.3g\t"</span>, A[row][col]);</div>
|
|
<div class="line"><span class="lineno"> 29</span> putchar(<span class="charliteral">'\n'</span>);</div>
|
|
<div class="line"><span class="lineno"> 30</span> }</div>
|
|
<div class="line"><span class="lineno"> 31</span> putchar(<span class="charliteral">'\n'</span>);</div>
|
|
<div class="line"><span class="lineno"> 32</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a45c7640d9d22c89c11beb1f567843c56" name="a45c7640d9d22c89c11beb1f567843c56"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a45c7640d9d22c89c11beb1f567843c56">◆ </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 ** </td>
|
|
<td class="paramname"><em>A</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">double ** </td>
|
|
<td class="paramname"><em>Q</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">double ** </td>
|
|
<td class="paramname"><em>R</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>M</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>N</em> </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" target="_blank">Gram-Schmidt process</a>. </p>
|
|
<p class="formulaDsp">
|
|
\begin{eqnarray*}
|
|
\text{given that}\quad A &=&
|
|
*\left[\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_{N-1},\right]\\
|
|
\text{where}\quad\mathbf{a}_i &=&
|
|
*\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 &=& \mathbf{a}_i
|
|
*-\sum_{j=0}^{i-1}\text{proj}_{\mathbf{u}_j}\mathbf{a}_i\\
|
|
\mathbf{e}_i &=&\frac{\mathbf{u}_i}{\left|\mathbf{u}_i\right|}\\
|
|
Q &=& \begin{bmatrix}\mathbf{e}_0 & \mathbf{e}_1 & \mathbf{e}_2 & \dots &
|
|
*\mathbf{e}_{N-1}\end{bmatrix}\\
|
|
R &=& \begin{bmatrix}\langle\mathbf{e}_0\,,\mathbf{a}_0\rangle &
|
|
*\langle\mathbf{e}_1\,,\mathbf{a}_1\rangle &
|
|
*\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots \\
|
|
0 & \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle &
|
|
*\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\
|
|
0 & 0 & \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\
|
|
\vdots & \vdots & \vdots & \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"><span class="lineno"> 148</span>{</div>
|
|
<div class="line"><span class="lineno"> 149</span> <span class="keywordtype">double</span> *col_vector = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 150</span> <span class="keywordtype">double</span> *col_vector2 = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 151</span> <span class="keywordtype">double</span> *tmp_vector = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(M * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 152</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < N;</div>
|
|
<div class="line"><span class="lineno"> 153</span> i++) <span class="comment">/* for each column => R is a square matrix of NxN */</span></div>
|
|
<div class="line"><span class="lineno"> 154</span> {</div>
|
|
<div class="line"><span class="lineno"> 155</span> <span class="keywordtype">int</span> j;</div>
|
|
<div class="line"><span class="lineno"> 156</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 157</span><span class="comment">// parallelize on threads</span></div>
|
|
<div class="line"><span class="lineno"> 158</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 159</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 160</span> <span class="keywordflow">for</span> (j = 0; j < i; j++) <span class="comment">/* second dimension of column */</span></div>
|
|
<div class="line"><span class="lineno"> 161</span> R[i][j] = 0.; <span class="comment">/* make R upper triangular */</span></div>
|
|
<div class="line"><span class="lineno"> 162</span> </div>
|
|
<div class="line"><span class="lineno"> 163</span> <span class="comment">/* get corresponding Q vector */</span></div>
|
|
<div class="line"><span class="lineno"> 164</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 165</span><span class="comment">// parallelize on threads</span></div>
|
|
<div class="line"><span class="lineno"> 166</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 167</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 168</span> <span class="keywordflow">for</span> (j = 0; j < M; j++)</div>
|
|
<div class="line"><span class="lineno"> 169</span> {</div>
|
|
<div class="line"><span class="lineno"> 170</span> tmp_vector[j] = A[j][i]; <span class="comment">/* accumulator for uk */</span></div>
|
|
<div class="line"><span class="lineno"> 171</span> col_vector[j] = A[j][i];</div>
|
|
<div class="line"><span class="lineno"> 172</span> }</div>
|
|
<div class="line"><span class="lineno"> 173</span> <span class="keywordflow">for</span> (j = 0; j < i; j++)</div>
|
|
<div class="line"><span class="lineno"> 174</span> {</div>
|
|
<div class="line"><span class="lineno"> 175</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0; k < M; k++) col_vector2[k] = Q[k][j];</div>
|
|
<div class="line"><span class="lineno"> 176</span> <a class="code hl_function" href="../../d4/d68/qr__decompose_8h.html#a2ed4977f38642dca8b10c16a823c740b">vector_proj</a>(col_vector, col_vector2, col_vector2, M);</div>
|
|
<div class="line"><span class="lineno"> 177</span> <a class="code hl_function" href="../../d4/d68/qr__decompose_8h.html#a5ee39e7c8fce8a604dcf7009ce101c02">vector_sub</a>(tmp_vector, col_vector2, tmp_vector, M);</div>
|
|
<div class="line"><span class="lineno"> 178</span> }</div>
|
|
<div class="line"><span class="lineno"> 179</span> <span class="keywordtype">double</span> mag = <a class="code hl_function" href="../../d4/d68/qr__decompose_8h.html#abeec1f78a7a7e7251687e75340331212">vector_mag</a>(tmp_vector, M);</div>
|
|
<div class="line"><span class="lineno"> 180</span> </div>
|
|
<div class="line"><span class="lineno"> 181</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 182</span><span class="comment">// parallelize on threads</span></div>
|
|
<div class="line"><span class="lineno"> 183</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 184</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 185</span> <span class="keywordflow">for</span> (j = 0; j < M; j++) Q[j][i] = tmp_vector[j] / mag;</div>
|
|
<div class="line"><span class="lineno"> 186</span> </div>
|
|
<div class="line"><span class="lineno"> 187</span> <span class="comment">/* compute upper triangular values of R */</span></div>
|
|
<div class="line"><span class="lineno"> 188</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> kk = 0; kk < M; kk++) col_vector[kk] = Q[kk][i];</div>
|
|
<div class="line"><span class="lineno"> 189</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = i; k < N; k++)</div>
|
|
<div class="line"><span class="lineno"> 190</span> {</div>
|
|
<div class="line"><span class="lineno"> 191</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> kk = 0; kk < M; kk++) col_vector2[kk] = A[kk][k];</div>
|
|
<div class="line"><span class="lineno"> 192</span> R[i][k] = <a class="code hl_function" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(col_vector, col_vector2, M);</div>
|
|
<div class="line"><span class="lineno"> 193</span> }</div>
|
|
<div class="line"><span class="lineno"> 194</span> }</div>
|
|
<div class="line"><span class="lineno"> 195</span> </div>
|
|
<div class="line"><span class="lineno"> 196</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(col_vector);</div>
|
|
<div class="line"><span class="lineno"> 197</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(col_vector2);</div>
|
|
<div class="line"><span class="lineno"> 198</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(tmp_vector);</div>
|
|
<div class="line"><span class="lineno"> 199</span>}</div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition</b> malloc_dbg.h:18</div></div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition</b> malloc_dbg.h:26</div></div>
|
|
<div class="ttc" id="aqr__decompose_8h_html_a2ed4977f38642dca8b10c16a823c740b"><div class="ttname"><a href="../../d4/d68/qr__decompose_8h.html#a2ed4977f38642dca8b10c16a823c740b">vector_proj</a></div><div class="ttdeci">double * vector_proj(double *a, double *b, double *out, int L)</div><div class="ttdoc">Compute projection of vector on defined as.</div><div class="ttdef"><b>Definition</b> qr_decompose.h:76</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="ttdoc">Compute dot product of two vectors of equal lengths.</div><div class="ttdef"><b>Definition</b> qr_decompose.h:43</div></div>
|
|
<div class="ttc" id="aqr__decompose_8h_html_a5ee39e7c8fce8a604dcf7009ce101c02"><div class="ttname"><a href="../../d4/d68/qr__decompose_8h.html#a5ee39e7c8fce8a604dcf7009ce101c02">vector_sub</a></div><div class="ttdeci">double * vector_sub(double *a, double *b, double *out, int L)</div><div class="ttdoc">Compute vector subtraction.</div><div class="ttdef"><b>Definition</b> qr_decompose.h:101</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="ttdoc">Compute magnitude of vector.</div><div class="ttdef"><b>Definition</b> qr_decompose.h:64</div></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="386" height="152"><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" name="a3a584b79941a43d775f9d4ce446dbe05"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a3a584b79941a43d775f9d4ce446dbe05">◆ </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 * </td>
|
|
<td class="paramname"><em>a</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">double * </td>
|
|
<td class="paramname"><em>b</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>L</em> </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"><span class="lineno"> 44</span>{</div>
|
|
<div class="line"><span class="lineno"> 45</span> <span class="keywordtype">double</span> mag = 0.f;</div>
|
|
<div class="line"><span class="lineno"> 46</span> <span class="keywordtype">int</span> i;</div>
|
|
<div class="line"><span class="lineno"> 47</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 48</span><span class="comment">// parallelize on threads</span></div>
|
|
<div class="line"><span class="lineno"> 49</span><span class="preprocessor">#pragma omp parallel for reduction(+ : mag)</span></div>
|
|
<div class="line"><span class="lineno"> 50</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 51</span> <span class="keywordflow">for</span> (i = 0; i < <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>; i++) mag += a[i] * b[i];</div>
|
|
<div class="line"><span class="lineno"> 52</span> </div>
|
|
<div class="line"><span class="lineno"> 53</span> <span class="keywordflow">return</span> mag;</div>
|
|
<div class="line"><span class="lineno"> 54</span>}</div>
|
|
<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><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="abeec1f78a7a7e7251687e75340331212" name="abeec1f78a7a7e7251687e75340331212"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#abeec1f78a7a7e7251687e75340331212">◆ </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 * </td>
|
|
<td class="paramname"><em>vector</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>L</em> </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"><span class="lineno"> 65</span>{</div>
|
|
<div class="line"><span class="lineno"> 66</span> <span class="keywordtype">double</span> dot = <a class="code hl_function" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(vector, vector, <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>);</div>
|
|
<div class="line"><span class="lineno"> 67</span> <span class="keywordflow">return</span> sqrt(dot);</div>
|
|
<div class="line"><span class="lineno"> 68</span>}</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="231" height="36"><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="a2ed4977f38642dca8b10c16a823c740b" name="a2ed4977f38642dca8b10c16a823c740b"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a2ed4977f38642dca8b10c16a823c740b">◆ </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 * </td>
|
|
<td class="paramname"><em>a</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">double * </td>
|
|
<td class="paramname"><em>b</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">double * </td>
|
|
<td class="paramname"><em>out</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>L</em> </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"><span class="lineno"> 77</span>{</div>
|
|
<div class="line"><span class="lineno"> 78</span> <span class="keyword">const</span> <span class="keywordtype">double</span> num = <a class="code hl_function" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(a, b, <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>);</div>
|
|
<div class="line"><span class="lineno"> 79</span> <span class="keyword">const</span> <span class="keywordtype">double</span> deno = <a class="code hl_function" href="../../d4/d68/qr__decompose_8h.html#a3a584b79941a43d775f9d4ce446dbe05">vector_dot</a>(b, b, <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>);</div>
|
|
<div class="line"><span class="lineno"> 80</span> <span class="keywordflow">if</span> (deno == 0) <span class="comment">/*! check for division by zero */</span></div>
|
|
<div class="line"><span class="lineno"> 81</span> <span class="keywordflow">return</span> NULL;</div>
|
|
<div class="line"><span class="lineno"> 82</span> </div>
|
|
<div class="line"><span class="lineno"> 83</span> <span class="keyword">const</span> <span class="keywordtype">double</span> scalar = num / deno;</div>
|
|
<div class="line"><span class="lineno"> 84</span> <span class="keywordtype">int</span> i;</div>
|
|
<div class="line"><span class="lineno"> 85</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 86</span><span class="comment">// parallelize on threads</span></div>
|
|
<div class="line"><span class="lineno"> 87</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 88</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 89</span> <span class="keywordflow">for</span> (i = 0; i < <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>; i++) out[i] = scalar * b[i];</div>
|
|
<div class="line"><span class="lineno"> 90</span> </div>
|
|
<div class="line"><span class="lineno"> 91</span> <span class="keywordflow">return</span> out;</div>
|
|
<div class="line"><span class="lineno"> 92</span>}</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_a2ed4977f38642dca8b10c16a823c740b_cgraph.svg" width="227" height="36"><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="a5ee39e7c8fce8a604dcf7009ce101c02" name="a5ee39e7c8fce8a604dcf7009ce101c02"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a5ee39e7c8fce8a604dcf7009ce101c02">◆ </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 * </td>
|
|
<td class="paramname"><em>a</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">double * </td>
|
|
<td class="paramname"><em>b</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">double * </td>
|
|
<td class="paramname"><em>out</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>L</em> </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"><span class="lineno"> 106</span>{</div>
|
|
<div class="line"><span class="lineno"> 107</span> <span class="keywordtype">int</span> i;</div>
|
|
<div class="line"><span class="lineno"> 108</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 109</span><span class="comment">// parallelize on threads</span></div>
|
|
<div class="line"><span class="lineno"> 110</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 111</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 112</span> <span class="keywordflow">for</span> (i = 0; i < <a class="code hl_struct" href="../../df/db3/struct_l.html">L</a>; i++) out[i] = a[i] - b[i];</div>
|
|
<div class="line"><span class="lineno"> 113</span> </div>
|
|
<div class="line"><span class="lineno"> 114</span> <span class="keywordflow">return</span> out;</div>
|
|
<div class="line"><span class="lineno"> 115</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- 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="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|