2020-06-28 18:07:29 +03:00
<!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
  < 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& 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& 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& 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 < 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 = "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  < / 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" >   < / td > < / tr >
< tr class = "memitem: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 = "separator:a3a584b79941a43d775f9d4ce446dbe05" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem: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 = "separator:abeec1f78a7a7e7251687e75340331212" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a82b20e027437df768d7e994cf4cae29f" > < td class = "memItemLeft" align = "right" valign = "top" > double *  < / 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" >   < / td > < / tr >
< tr class = "memitem:a6b6a0e75e75ff7919057dd275bb69145" > < td class = "memItemLeft" align = "right" valign = "top" > double *  < / 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" >   < / td > < / tr >
< tr class = "memitem: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 < 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" >   < / 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" > ◆ < / 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" > < a name = "l00025" > < / a > < span class = "lineno" > 25< / span >   {< / div >
< div class = "line" > < a name = "l00026" > < / a > < span class = "lineno" > 26< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > row = 0; row < M; row++)< / div >
< div class = "line" > < a name = "l00027" > < / a > < span class = "lineno" > 27< / span >   {< / div >
2020-06-28 18:30:37 +03:00
< div class = "line" > < a name = "l00028" > < / a > < span class = "lineno" > 28< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > col = 0; col < < a class = "code" href = "../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4" > N< / a > ; col++) printf(< span class = "stringliteral" > " % 9.3g\t" < / span > , A[row][col]);< / div >
< div class = "line" > < a name = "l00029" > < / a > < span class = "lineno" > 29< / span >   putchar(< span class = "charliteral" > ' \n' < / span > );< / div >
< div class = "line" > < a name = "l00030" > < / a > < span class = "lineno" > 30< / span >   }< / div >
< div class = "line" > < a name = "l00031" > < / a > < span class = "lineno" > 31< / span >   putchar(< span class = "charliteral" > ' \n' < / span > );< / div >
< div class = "line" > < a name = "l00032" > < / a > < span class = "lineno" > 32< / span >   }< / div >
2020-06-28 18:07:29 +03:00
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "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" > 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 >
2020-06-28 18:30:37 +03:00
< div class = "fragment" > < div class = "line" > < a name = "l00148" > < / a > < span class = "lineno" > 148< / span >   {< / div >
< div class = "line" > < a name = "l00149" > < / a > < span class = "lineno" > 149< / span >   < 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 >   < 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 >   < 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 >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < < 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 >   i++) < span class = "comment" > /* for each column => R is a square matrix of NxN */< / span > < / div >
< div class = "line" > < a name = "l00154" > < / a > < span class = "lineno" > 154< / span >   {< / div >
< div class = "line" > < a name = "l00155" > < / a > < span class = "lineno" > 155< / span >   < span class = "keywordtype" > int< / span > j;< / div >
< div class = "line" > < a name = "l00156" > < / a > < span class = "lineno" > 156< / span >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00157" > < / a > < span class = "lineno" > 157< / span >   < span class = "comment" > // parallelize on threads< / span > < / div >
< div class = "line" > < a name = "l00158" > < / a > < span class = "lineno" > 158< / span >   < span class = "preprocessor" > #pragma omp for< / span > < / div >
< div class = "line" > < a name = "l00159" > < / a > < span class = "lineno" > 159< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00160" > < / a > < 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" > < a name = "l00161" > < / a > < span class = "lineno" > 161< / span >   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 >   < / div >
< div class = "line" > < a name = "l00163" > < / a > < span class = "lineno" > 163< / span >   < span class = "comment" > /* get corresponding Q vector */< / span > < / div >
< div class = "line" > < a name = "l00164" > < / a > < span class = "lineno" > 164< / span >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00165" > < / a > < span class = "lineno" > 165< / span >   < span class = "comment" > // parallelize on threads< / span > < / div >
< div class = "line" > < a name = "l00166" > < / a > < span class = "lineno" > 166< / span >   < span class = "preprocessor" > #pragma omp for< / span > < / div >
< div class = "line" > < a name = "l00167" > < / a > < span class = "lineno" > 167< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00168" > < / a > < span class = "lineno" > 168< / span >   < span class = "keywordflow" > for< / span > (j = 0; j < M; j++)< / div >
< div class = "line" > < a name = "l00169" > < / a > < span class = "lineno" > 169< / span >   {< / div >
< div class = "line" > < a name = "l00170" > < / a > < span class = "lineno" > 170< / span >   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 >   col_vector[j] = A[j][i];< / div >
< div class = "line" > < a name = "l00172" > < / a > < span class = "lineno" > 172< / span >   }< / div >
< div class = "line" > < a name = "l00173" > < / a > < span class = "lineno" > 173< / span >   < span class = "keywordflow" > for< / span > (j = 0; j < i; j++)< / div >
< div class = "line" > < a name = "l00174" > < / a > < span class = "lineno" > 174< / span >   {< / div >
< div class = "line" > < a name = "l00175" > < / a > < 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" > < a name = "l00176" > < / a > < span class = "lineno" > 176< / span >   < 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 >   < 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 >   }< / div >
< div class = "line" > < a name = "l00179" > < / a > < span class = "lineno" > 179< / span >   < 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 >   < / div >
< div class = "line" > < a name = "l00181" > < / a > < span class = "lineno" > 181< / span >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00182" > < / a > < span class = "lineno" > 182< / span >   < span class = "comment" > // parallelize on threads< / span > < / div >
< div class = "line" > < a name = "l00183" > < / a > < span class = "lineno" > 183< / span >   < span class = "preprocessor" > #pragma omp for< / span > < / div >
< div class = "line" > < a name = "l00184" > < / a > < span class = "lineno" > 184< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00185" > < / a > < 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" > < a name = "l00186" > < / a > < span class = "lineno" > 186< / span >   < / div >
< div class = "line" > < a name = "l00187" > < / a > < span class = "lineno" > 187< / span >   < span class = "comment" > /* compute upper triangular values of R */< / span > < / div >
< div class = "line" > < a name = "l00188" > < / a > < 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" > < a name = "l00189" > < / a > < span class = "lineno" > 189< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > k = i; k < < 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 >   {< / div >
< div class = "line" > < a name = "l00191" > < / a > < 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" > < a name = "l00192" > < / a > < span class = "lineno" > 192< / span >   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 >   }< / div >
< div class = "line" > < a name = "l00194" > < / a > < span class = "lineno" > 194< / span >   }< / div >
< div class = "line" > < a name = "l00195" > < / a > < span class = "lineno" > 195< / span >   < / div >
< div class = "line" > < a name = "l00196" > < / a > < span class = "lineno" > 196< / span >   free(col_vector);< / div >
< div class = "line" > < a name = "l00197" > < / a > < span class = "lineno" > 197< / span >   free(col_vector2);< / div >
< div class = "line" > < a name = "l00198" > < / a > < span class = "lineno" > 198< / span >   free(tmp_vector);< / div >
< div class = "line" > < a name = "l00199" > < / a > < span class = "lineno" > 199< / span >   }< / div >
2020-06-28 18:07:29 +03:00
< / 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" > ◆ < / 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 >
2020-06-28 18:30:37 +03:00
< div class = "fragment" > < div class = "line" > < a name = "l00044" > < / a > < span class = "lineno" > 44< / span >   {< / div >
< div class = "line" > < a name = "l00045" > < / a > < span class = "lineno" > 45< / span >   < span class = "keywordtype" > double< / span > mag = 0.f;< / div >
< div class = "line" > < a name = "l00046" > < / a > < span class = "lineno" > 46< / span >   < span class = "keywordtype" > int< / span > i;< / div >
< div class = "line" > < a name = "l00047" > < / a > < span class = "lineno" > 47< / span >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00048" > < / a > < span class = "lineno" > 48< / span >   < span class = "comment" > // parallelize on threads< / span > < / div >
< div class = "line" > < a name = "l00049" > < / a > < span class = "lineno" > 49< / span >   < span class = "preprocessor" > #pragma omp parallel for reduction(+ : mag)< / span > < / div >
< div class = "line" > < a name = "l00050" > < / a > < span class = "lineno" > 50< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00051" > < / a > < span class = "lineno" > 51< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < < 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 >   < / div >
< div class = "line" > < a name = "l00053" > < / a > < span class = "lineno" > 53< / span >   < span class = "keywordflow" > return< / span > mag;< / div >
< div class = "line" > < a name = "l00054" > < / a > < span class = "lineno" > 54< / span >   }< / div >
2020-06-28 18:07:29 +03:00
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "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 >
2020-06-28 18:30:37 +03:00
< div class = "fragment" > < div class = "line" > < a name = "l00065" > < / a > < span class = "lineno" > 65< / span >   {< / div >
< div class = "line" > < a name = "l00066" > < / a > < span class = "lineno" > 66< / span >   < 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 >   < span class = "keywordflow" > return< / span > sqrt(dot);< / div >
< div class = "line" > < a name = "l00068" > < / a > < span class = "lineno" > 68< / span >   }< / div >
2020-06-28 18:07:29 +03:00
< / 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" > ◆ < / 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 >
2020-06-28 18:30:37 +03:00
< div class = "fragment" > < div class = "line" > < a name = "l00077" > < / a > < span class = "lineno" > 77< / span >   {< / div >
< div class = "line" > < a name = "l00078" > < / a > < span class = "lineno" > 78< / span >   < 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 >   < 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 >   < 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 >   < span class = "keywordflow" > return< / span > NULL;< / div >
< div class = "line" > < a name = "l00082" > < / a > < span class = "lineno" > 82< / span >   < / div >
< div class = "line" > < a name = "l00083" > < / a > < span class = "lineno" > 83< / span >   < 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 >   < span class = "keywordtype" > int< / span > i;< / div >
< div class = "line" > < a name = "l00085" > < / a > < span class = "lineno" > 85< / span >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00086" > < / a > < span class = "lineno" > 86< / span >   < span class = "comment" > // parallelize on threads< / span > < / div >
< div class = "line" > < a name = "l00087" > < / a > < span class = "lineno" > 87< / span >   < span class = "preprocessor" > #pragma omp for< / span > < / div >
< div class = "line" > < a name = "l00088" > < / a > < span class = "lineno" > 88< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00089" > < / a > < span class = "lineno" > 89< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < < 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 >   < / div >
< div class = "line" > < a name = "l00091" > < / a > < span class = "lineno" > 91< / span >   < span class = "keywordflow" > return< / span > out;< / div >
< div class = "line" > < a name = "l00092" > < / a > < span class = "lineno" > 92< / span >   }< / div >
2020-06-28 18:07:29 +03:00
< / 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" > ◆ < / 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 >
2020-06-28 18:30:37 +03:00
< div class = "fragment" > < div class = "line" > < a name = "l00106" > < / a > < span class = "lineno" > 106< / span >   {< / div >
< div class = "line" > < a name = "l00107" > < / a > < span class = "lineno" > 107< / span >   < span class = "keywordtype" > int< / span > i;< / div >
< div class = "line" > < a name = "l00108" > < / a > < span class = "lineno" > 108< / span >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00109" > < / a > < span class = "lineno" > 109< / span >   < span class = "comment" > // parallelize on threads< / span > < / div >
< div class = "line" > < a name = "l00110" > < / a > < span class = "lineno" > 110< / span >   < span class = "preprocessor" > #pragma omp for< / span > < / div >
< div class = "line" > < a name = "l00111" > < / a > < span class = "lineno" > 111< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00112" > < / a > < span class = "lineno" > 112< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < < 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 >   < / div >
< div class = "line" > < a name = "l00114" > < / a > < span class = "lineno" > 114< / span >   < span class = "keywordflow" > return< / span > out;< / div >
< div class = "line" > < a name = "l00115" > < / a > < span class = "lineno" > 115< / span >   }< / div >
2020-06-28 18:07:29 +03:00
< / 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 >
2020-06-28 18:30:37 +03:00
< 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 >
2020-06-28 18:07:29 +03:00
<!-- 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 >
2020-06-28 18:30:37 +03:00
< li class = "footer" > Generated by
2020-06-28 18:07:29 +03:00
< 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 >