2020-06-28 23:07:29 +08: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_eigen_values.c 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('d7/d50/qr__eigen__values_8c.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 = "#define-members" > Macros< / a > |
< a href = "#func-members" > Functions< / a > < / div >
< div class = "headertitle" >
< div class = "title" > qr_eigen_values.c File Reference< / div > < / div >
< / div > <!-- header -->
< div class = "contents" >
< p > Compute real eigen values and eigen vectors of a symmetric matrix using < a href = "https://en.wikipedia.org/wiki/QR_decomposition" > QR decomposition< / a > method.
< a href = "#details" > More...< / a > < / p >
2020-06-28 23:30:37 +08:00
< div class = "textblock" > < code > #include < assert.h> < / code > < br / >
2020-06-28 23:07:29 +08:00
< code > #include < math.h> < / code > < br / >
< code > #include < stdio.h> < / code > < br / >
< code > #include < stdlib.h> < / code > < br / >
< code > #include < time.h> < / code > < br / >
2020-06-28 23:30:37 +08:00
< code > #include " < a class = "el" href = "../../d4/d68/qr__decompose_8h_source.html" > qr_decompose.h< / a > " < / code > < br / >
2020-06-28 23:07:29 +08:00
< / div > < div class = "textblock" > < div class = "dynheader" >
Include dependency graph for qr_eigen_values.c:< / div >
< div class = "dyncontent" >
2020-06-28 23:30:37 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d4/d15/qr__eigen__values_8c__incl.svg" width = "459" height = "202" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2020-06-28 23:07:29 +08:00
< / div >
< / div >
< / div > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "define-members" > < / a >
Macros< / h2 > < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memitem:aee57a411f07599034f5ceb8cc7d65b40" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "aee57a411f07599034f5ceb8cc7d65b40" > < / a >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#aee57a411f07599034f5ceb8cc7d65b40" > LIMS< / a >       9< / td > < / tr >
< tr class = "memdesc:aee57a411f07599034f5ceb8cc7d65b40" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > limit of range of matrix values < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:aee57a411f07599034f5ceb8cc7d65b40" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memitem:a002b2f4894492820fe708b1b7e7c5e70" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a002b2f4894492820fe708b1b7e7c5e70" > < / a >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#a002b2f4894492820fe708b1b7e7c5e70" > EPSILON< / a >       1e-10< / td > < / tr >
< tr class = "memdesc:a002b2f4894492820fe708b1b7e7c5e70" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > accuracy tolerance limit < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a002b2f4894492820fe708b1b7e7c5e70" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "func-members" > < / a >
Functions< / h2 > < / td > < / tr >
< tr class = "memitem:a7d96c5e4ae1bd6d29791bcc23a4cb2b0" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#a7d96c5e4ae1bd6d29791bcc23a4cb2b0" > create_matrix< / a > (double **A, int < a class = "el" href = "../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4" > N< / a > )< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a7d96c5e4ae1bd6d29791bcc23a4cb2b0" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > create a square matrix of given size with random elements < a href = "../../d7/d50/qr__eigen__values_8c.html#a7d96c5e4ae1bd6d29791bcc23a4cb2b0" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a7d96c5e4ae1bd6d29791bcc23a4cb2b0" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a741477692f001a805b0fea942c9dc2b9" > < td class = "memItemLeft" align = "right" valign = "top" > double **  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#a741477692f001a805b0fea942c9dc2b9" > mat_mul< / a > (double **A, double **B, double **OUT, int R1, int C1, int R2, int C2)< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a741477692f001a805b0fea942c9dc2b9" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Perform multiplication of two matrices. < a href = "../../d7/d50/qr__eigen__values_8c.html#a741477692f001a805b0fea942c9dc2b9" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a741477692f001a805b0fea942c9dc2b9" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a0d8ed79786d17df48396b333c09d05bb" > < td class = "memItemLeft" align = "right" valign = "top" > double  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#a0d8ed79786d17df48396b333c09d05bb" > eigen_values< / a > (double **A, double *eigen_vals, int mat_size, char debug_print)< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a0d8ed79786d17df48396b333c09d05bb" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Compute eigen values using iterative shifted QR decomposition algorithm as follows: < a href = "../../d7/d50/qr__eigen__values_8c.html#a0d8ed79786d17df48396b333c09d05bb" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a0d8ed79786d17df48396b333c09d05bb" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a1440a7779ac56f47a3f355ce4a8c7da0" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0" > test1< / a > ()< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a1440a7779ac56f47a3f355ce4a8c7da0" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > test function to compute eigen values of a 2x2 matrix < a href = "../../d7/d50/qr__eigen__values_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a1440a7779ac56f47a3f355ce4a8c7da0" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a0283886819c7c140a023582b7269e2d0" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#a0283886819c7c140a023582b7269e2d0" > test2< / a > ()< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a0283886819c7c140a023582b7269e2d0" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > test function to compute eigen values of a 2x2 matrix < a href = "../../d7/d50/qr__eigen__values_8c.html#a0283886819c7c140a023582b7269e2d0" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a0283886819c7c140a023582b7269e2d0" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memitem:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a3c04138a5bfe5d72780bb7e82a18e627" > < / a >
int  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d7/d50/qr__eigen__values_8c.html#a3c04138a5bfe5d72780bb7e82a18e627" > main< / a > (int argc, char **argv)< / td > < / tr >
< tr class = "memdesc:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > main function < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table >
< a name = "details" id = "details" > < / a > < h2 class = "groupheader" > Detailed Description< / h2 >
< div class = "textblock" > < p > Compute real eigen values and eigen vectors of a symmetric matrix using < a href = "https://en.wikipedia.org/wiki/QR_decomposition" > QR decomposition< / a > method. < / p >
< dl class = "section author" > < dt > Author< / dt > < dd > < a href = "https://github.com/kvedala" > Krishna Vedala< / a > < / dd > < / dl >
2020-06-29 04:40:24 +08:00
< / div > < h2 class = "groupheader" > Function Documentation< / h2 >
2020-06-28 23:07:29 +08:00
< a id = "a7d96c5e4ae1bd6d29791bcc23a4cb2b0" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a7d96c5e4ae1bd6d29791bcc23a4cb2b0" > ◆ < / a > < / span > create_matrix()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void create_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 > N< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< p > create a square matrix of given size with random elements < / p >
< dl class = "params" > < dt > Parameters< / dt > < dd >
2020-06-28 23:07:29 +08:00
< table class = "params" >
< tr > < td class = "paramdir" > [out]< / td > < td class = "paramname" > A< / td > < td > matrix to create (must be pre-allocated in memory) < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > N< / td > < td > matrix size < / td > < / tr >
< / table >
< / dd >
< / dl >
2020-06-29 04:40:24 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00028" > < / a > < span class = "lineno" > 28< / span >   {< / div >
< div class = "line" > < a name = "l00029" > < / a > < span class = "lineno" > 29< / span >   < span class = "keywordtype" > int< / span > i, j, tmp, lim2 = < a class = "code" href = "../../d7/d50/qr__eigen__values_8c.html#aee57a411f07599034f5ceb8cc7d65b40" > LIMS< / a > > > 1;< / 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 >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00032" > < / a > < span class = "lineno" > 32< / span >   < span class = "preprocessor" > #pragma omp for< / span > < / div >
< div class = "line" > < a name = "l00033" > < / a > < span class = "lineno" > 33< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00034" > < / a > < span class = "lineno" > 34< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < < a class = "code" href = "../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4" > N< / a > ; i++)< / div >
< div class = "line" > < a name = "l00035" > < / a > < span class = "lineno" > 35< / span >   {< / div >
< div class = "line" > < a name = "l00036" > < / a > < span class = "lineno" > 36< / span >   A[i][i] = (rand() % < a class = "code" href = "../../d7/d50/qr__eigen__values_8c.html#aee57a411f07599034f5ceb8cc7d65b40" > LIMS< / a > ) - lim2;< / div >
< div class = "line" > < a name = "l00037" > < / a > < span class = "lineno" > 37< / span >   < span class = "keywordflow" > for< / span > (j = i + 1; j < < a class = "code" href = "../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4" > N< / a > ; j++)< / div >
< div class = "line" > < a name = "l00038" > < / a > < span class = "lineno" > 38< / span >   {< / div >
< div class = "line" > < a name = "l00039" > < / a > < span class = "lineno" > 39< / span >   tmp = (rand() % < a class = "code" href = "../../d7/d50/qr__eigen__values_8c.html#aee57a411f07599034f5ceb8cc7d65b40" > LIMS< / a > ) - lim2;< / div >
< div class = "line" > < a name = "l00040" > < / a > < span class = "lineno" > 40< / span >   A[i][j] = tmp;< / div >
< div class = "line" > < a name = "l00041" > < / a > < span class = "lineno" > 41< / span >   A[j][i] = tmp;< / div >
< div class = "line" > < a name = "l00042" > < / a > < span class = "lineno" > 42< / span >   }< / div >
< div class = "line" > < a name = "l00043" > < / a > < span class = "lineno" > 43< / span >   }< / div >
< div class = "line" > < a name = "l00044" > < / a > < span class = "lineno" > 44< / span >   }< / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "a0d8ed79786d17df48396b333c09d05bb" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a0d8ed79786d17df48396b333c09d05bb" > ◆ < / a > < / span > eigen_values()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > double eigen_values < / 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 > eigen_vals< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > mat_size< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > char  < / td >
< td class = "paramname" > < em > debug_print< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< p > Compute eigen values using iterative shifted QR decomposition algorithm as follows: < / p >
< ol type = "1" >
2020-06-28 23:07:29 +08:00
< li > Use last diagonal element of A as eigen value approximation \(c\)< / li >
< li > Shift diagonals of matrix \(A' = A - cI\)< / li >
< li > Decompose matrix \(A' =QR\)< / li >
< li > Compute next approximation \(A' _1 = RQ \)< / li >
< li > Shift diagonals back \(A_1 = A' _1 + cI\)< / li >
< li > Termination condition check: last element below diagonal is almost 0< ol type = "a" >
< li > If not 0, go back to step 1 with the new approximation \(A_1\)< / li >
< li > If 0, continue to step 7< / li >
< / ol >
< / li >
< li > Save last known \(c\) as the eigen value.< / li >
< li > Are all eigen values found?< ol type = "a" >
< li > If not, remove last row and column of \(A_1\) and go back to step 1.< / li >
< li > If yes, stop.< / li >
< / ol >
< / li >
< / ol >
< dl class = "section note" > < dt > Note< / dt > < dd > The matrix \(A\) gets modified< / dd > < / dl >
< dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in,out]< / td > < td class = "paramname" > A< / td > < td > matrix to compute eigen values for < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr > < td class = "paramdir" > [out]< / td > < td class = "paramname" > eigen_vals< / td > < td > resultant vector containing computed eigen values < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > mat_size< / td > < td > matrix size < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > debug_print< / td > < td > 1 to print intermediate Q & R matrices, 0 for not to < / td > < / tr >
< / table >
< / dd >
< / dl >
< dl class = "section return" > < dt > Returns< / dt > < dd > time for computation in seconds < / dd > < / dl >
2020-07-11 10:24:26 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00108" > < / a > < span class = "lineno" > 108< / span >   {< / div >
< div class = "line" > < a name = "l00109" > < / a > < span class = "lineno" > 109< / span >   < span class = "keywordflow" > if< / span > (!eigen_vals)< / div >
< div class = "line" > < a name = "l00110" > < / a > < span class = "lineno" > 110< / span >   {< / div >
< div class = "line" > < a name = "l00111" > < / a > < span class = "lineno" > 111< / span >   perror(< span class = "stringliteral" > " Output eigen value vector cannot be NULL!" < / span > );< / div >
< div class = "line" > < a name = "l00112" > < / a > < span class = "lineno" > 112< / span >   < span class = "keywordflow" > return< / span > -1;< / 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 = "keywordtype" > double< / span > **R = (< span class = "keywordtype" > double< / span > **)malloc(< span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > *) * mat_size);< / div >
< div class = "line" > < a name = "l00115" > < / a > < span class = "lineno" > 115< / span >   < span class = "keywordtype" > double< / span > **Q = (< span class = "keywordtype" > double< / span > **)malloc(< span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > *) * mat_size);< / div >
< div class = "line" > < a name = "l00116" > < / a > < span class = "lineno" > 116< / span >   < span class = "keywordflow" > if< / span > (!Q || !R)< / div >
< div class = "line" > < a name = "l00117" > < / a > < span class = "lineno" > 117< / span >   {< / div >
< div class = "line" > < a name = "l00118" > < / a > < span class = "lineno" > 118< / span >   perror(< span class = "stringliteral" > " Unable to allocate memory for Q & R!" < / span > );< / div >
< div class = "line" > < a name = "l00119" > < / a > < span class = "lineno" > 119< / span >   < span class = "keywordflow" > if< / span > (Q)< / div >
< div class = "line" > < a name = "l00120" > < / a > < span class = "lineno" > 120< / span >   {< / div >
< div class = "line" > < a name = "l00121" > < / a > < span class = "lineno" > 121< / span >   free(Q);< / div >
< div class = "line" > < a name = "l00122" > < / a > < span class = "lineno" > 122< / span >   }< / div >
< div class = "line" > < a name = "l00123" > < / a > < span class = "lineno" > 123< / span >   < span class = "keywordflow" > if< / span > (R)< / div >
< div class = "line" > < a name = "l00124" > < / a > < span class = "lineno" > 124< / span >   {< / div >
< div class = "line" > < a name = "l00125" > < / a > < span class = "lineno" > 125< / span >   free(R);< / div >
< div class = "line" > < a name = "l00126" > < / a > < span class = "lineno" > 126< / span >   }< / div >
< div class = "line" > < a name = "l00127" > < / a > < span class = "lineno" > 127< / span >   < span class = "keywordflow" > return< / span > -1;< / div >
< div class = "line" > < a name = "l00128" > < / a > < span class = "lineno" > 128< / span >   }< / div >
< div class = "line" > < a name = "l00129" > < / a > < span class = "lineno" > 129< / span >   < / div >
< div class = "line" > < a name = "l00130" > < / a > < span class = "lineno" > 130< / span >   < span class = "comment" > /* allocate dynamic memory for matrices */< / span > < / div >
< div class = "line" > < a name = "l00131" > < / a > < span class = "lineno" > 131< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < mat_size; i++)< / div >
< div class = "line" > < a name = "l00132" > < / a > < span class = "lineno" > 132< / span >   {< / div >
< div class = "line" > < a name = "l00133" > < / a > < span class = "lineno" > 133< / span >   R[i] = (< span class = "keywordtype" > double< / span > *)malloc(< span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > ) * mat_size);< / div >
< div class = "line" > < a name = "l00134" > < / a > < span class = "lineno" > 134< / span >   Q[i] = (< span class = "keywordtype" > double< / span > *)malloc(< span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > ) * mat_size);< / div >
< div class = "line" > < a name = "l00135" > < / a > < span class = "lineno" > 135< / span >   < span class = "keywordflow" > if< / span > (!Q[i] || !R[i])< / div >
< div class = "line" > < a name = "l00136" > < / a > < span class = "lineno" > 136< / span >   {< / div >
< div class = "line" > < a name = "l00137" > < / a > < span class = "lineno" > 137< / span >   perror(< span class = "stringliteral" > " Unable to allocate memory for Q & R." < / span > );< / div >
< div class = "line" > < a name = "l00138" > < / a > < span class = "lineno" > 138< / span >   < span class = "keywordflow" > for< / span > (; i > = 0; i--)< / div >
< div class = "line" > < a name = "l00139" > < / a > < span class = "lineno" > 139< / span >   {< / div >
< div class = "line" > < a name = "l00140" > < / a > < span class = "lineno" > 140< / span >   free(R[i]);< / div >
< div class = "line" > < a name = "l00141" > < / a > < span class = "lineno" > 141< / span >   free(Q[i]);< / div >
< div class = "line" > < a name = "l00142" > < / a > < span class = "lineno" > 142< / span >   }< / div >
< div class = "line" > < a name = "l00143" > < / a > < span class = "lineno" > 143< / span >   free(Q);< / div >
< div class = "line" > < a name = "l00144" > < / a > < span class = "lineno" > 144< / span >   free(R);< / div >
< div class = "line" > < a name = "l00145" > < / a > < span class = "lineno" > 145< / span >   < span class = "keywordflow" > return< / span > -1;< / div >
< div class = "line" > < a name = "l00146" > < / a > < span class = "lineno" > 146< / span >   }< / div >
< div class = "line" > < a name = "l00147" > < / a > < span class = "lineno" > 147< / span >   }< / div >
< 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 = "keywordflow" > if< / span > (debug_print)< / div >
< div class = "line" > < a name = "l00150" > < / a > < span class = "lineno" > 150< / span >   {< / div >
< div class = "line" > < a name = "l00151" > < / a > < span class = "lineno" > 151< / span >   < a class = "code" href = "../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a" > print_matrix< / a > (A, mat_size, mat_size);< / div >
< div class = "line" > < a name = "l00152" > < / a > < span class = "lineno" > 152< / span >   }< / div >
< div class = "line" > < a name = "l00153" > < / a > < span class = "lineno" > 153< / span >   < / div >
< div class = "line" > < a name = "l00154" > < / a > < span class = "lineno" > 154< / span >   < span class = "keywordtype" > int< / span > rows = mat_size, columns = mat_size;< / div >
< div class = "line" > < a name = "l00155" > < / a > < span class = "lineno" > 155< / span >   < span class = "keywordtype" > int< / span > counter = 0, num_eigs = rows - 1;< / div >
< div class = "line" > < a name = "l00156" > < / a > < span class = "lineno" > 156< / span >   < span class = "keywordtype" > double< / span > last_eig = 0;< / div >
< div class = "line" > < a name = "l00157" > < / a > < span class = "lineno" > 157< / span >   < / div >
< div class = "line" > < a name = "l00158" > < / a > < span class = "lineno" > 158< / span >   clock_t t1 = clock();< / div >
< div class = "line" > < a name = "l00159" > < / a > < span class = "lineno" > 159< / span >   < span class = "keywordflow" > while< / span > (num_eigs > 0) < span class = "comment" > /* continue till all eigen values are found */< / span > < / div >
< div class = "line" > < a name = "l00160" > < / a > < span class = "lineno" > 160< / span >   {< / div >
< div class = "line" > < a name = "l00161" > < / a > < span class = "lineno" > 161< / span >   < span class = "comment" > /* iterate with QR decomposition */< / span > < / div >
< div class = "line" > < a name = "l00162" > < / a > < span class = "lineno" > 162< / span >   < span class = "keywordflow" > while< / span > (fabs(A[num_eigs][num_eigs - 1]) > < a class = "code" href = "../../d7/d50/qr__eigen__values_8c.html#a002b2f4894492820fe708b1b7e7c5e70" > EPSILON< / a > )< / div >
< div class = "line" > < a name = "l00163" > < / a > < span class = "lineno" > 163< / span >   {< / div >
< div class = "line" > < a name = "l00164" > < / a > < span class = "lineno" > 164< / span >   last_eig = A[num_eigs][num_eigs];< / div >
< div class = "line" > < a name = "l00165" > < / a > < span class = "lineno" > 165< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < rows; i++) A[i][i] -= last_eig; < span class = "comment" > /* A - cI */< / span > < / div >
< div class = "line" > < a name = "l00166" > < / a > < span class = "lineno" > 166< / span >   < a class = "code" href = "../../d4/d68/qr__decompose_8h.html#a45c7640d9d22c89c11beb1f567843c56" > qr_decompose< / a > (A, Q, R, rows, columns);< / div >
< div class = "line" > < a name = "l00167" > < / a > < span class = "lineno" > 167< / span >   < / div >
< div class = "line" > < a name = "l00168" > < / a > < span class = "lineno" > 168< / span >   < span class = "keywordflow" > if< / span > (debug_print)< / 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 >   < a class = "code" href = "../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a" > print_matrix< / a > (A, rows, columns);< / div >
< div class = "line" > < a name = "l00171" > < / a > < span class = "lineno" > 171< / span >   < a class = "code" href = "../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a" > print_matrix< / a > (Q, rows, columns);< / div >
< div class = "line" > < a name = "l00172" > < / a > < span class = "lineno" > 172< / span >   < a class = "code" href = "../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a" > print_matrix< / a > (R, columns, columns);< / div >
< div class = "line" > < a name = "l00173" > < / a > < span class = "lineno" > 173< / span >   printf(< span class = "stringliteral" > " -------------------- %d ---------------------\n" < / span > ,< / div >
< div class = "line" > < a name = "l00174" > < / a > < span class = "lineno" > 174< / span >   ++counter);< / div >
< div class = "line" > < a name = "l00175" > < / a > < span class = "lineno" > 175< / span >   }< / div >
< div class = "line" > < a name = "l00176" > < / a > < span class = "lineno" > 176< / span >   < / div >
< div class = "line" > < a name = "l00177" > < / a > < span class = "lineno" > 177< / span >   < a class = "code" href = "../../d7/d50/qr__eigen__values_8c.html#a741477692f001a805b0fea942c9dc2b9" > mat_mul< / a > (R, Q, A, columns, columns, rows, columns);< / div >
< div class = "line" > < a name = "l00178" > < / a > < span class = "lineno" > 178< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < rows; i++) A[i][i] += last_eig; < span class = "comment" > /* A + cI */< / span > < / div >
< div class = "line" > < a name = "l00179" > < / a > < span class = "lineno" > 179< / span >   }< / 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 = "comment" > /* store the converged eigen value */< / span > < / div >
< div class = "line" > < a name = "l00182" > < / a > < span class = "lineno" > 182< / span >   eigen_vals[num_eigs] = last_eig;< / div >
< div class = "line" > < a name = "l00183" > < / a > < span class = "lineno" > 183< / span >   < / div >
< div class = "line" > < a name = "l00184" > < / a > < span class = "lineno" > 184< / span >   < span class = "keywordflow" > if< / span > (debug_print)< / div >
< div class = "line" > < a name = "l00185" > < / a > < span class = "lineno" > 185< / span >   {< / div >
< div class = "line" > < a name = "l00186" > < / a > < span class = "lineno" > 186< / span >   printf(< span class = "stringliteral" > " ========================\n" < / span > );< / div >
< div class = "line" > < a name = "l00187" > < / a > < span class = "lineno" > 187< / span >   printf(< span class = "stringliteral" > " Eigen value: % g,\n" < / span > , last_eig);< / div >
< div class = "line" > < a name = "l00188" > < / a > < span class = "lineno" > 188< / span >   printf(< span class = "stringliteral" > " ========================\n" < / span > );< / div >
< div class = "line" > < a name = "l00189" > < / a > < span class = "lineno" > 189< / span >   }< / 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 >   num_eigs--;< / div >
< div class = "line" > < a name = "l00192" > < / a > < span class = "lineno" > 192< / span >   rows--;< / div >
< div class = "line" > < a name = "l00193" > < / a > < span class = "lineno" > 193< / span >   columns--;< / 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 >   eigen_vals[0] = A[0][0];< / div >
< div class = "line" > < a name = "l00196" > < / a > < span class = "lineno" > 196< / span >   < span class = "keywordtype" > double< / span > dtime = (double)(clock() - t1) / CLOCKS_PER_SEC;< / div >
< div class = "line" > < a name = "l00197" > < / a > < span class = "lineno" > 197< / span >   < / div >
< div class = "line" > < a name = "l00198" > < / a > < span class = "lineno" > 198< / span >   < span class = "keywordflow" > if< / span > (debug_print)< / div >
< div class = "line" > < a name = "l00199" > < / a > < span class = "lineno" > 199< / span >   {< / div >
< div class = "line" > < a name = "l00200" > < / a > < span class = "lineno" > 200< / span >   < a class = "code" href = "../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a" > print_matrix< / a > (R, mat_size, mat_size);< / div >
< div class = "line" > < a name = "l00201" > < / a > < span class = "lineno" > 201< / span >   < a class = "code" href = "../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a" > print_matrix< / a > (Q, mat_size, mat_size);< / div >
< div class = "line" > < a name = "l00202" > < / a > < span class = "lineno" > 202< / span >   }< / div >
< div class = "line" > < a name = "l00203" > < / a > < span class = "lineno" > 203< / span >   < / div >
< div class = "line" > < a name = "l00204" > < / a > < span class = "lineno" > 204< / span >   < span class = "comment" > /* cleanup dynamic memory */< / span > < / div >
< div class = "line" > < a name = "l00205" > < / a > < span class = "lineno" > 205< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < mat_size; i++)< / div >
< div class = "line" > < a name = "l00206" > < / a > < span class = "lineno" > 206< / span >   {< / div >
< div class = "line" > < a name = "l00207" > < / a > < span class = "lineno" > 207< / span >   free(R[i]);< / div >
< div class = "line" > < a name = "l00208" > < / a > < span class = "lineno" > 208< / span >   free(Q[i]);< / div >
< div class = "line" > < a name = "l00209" > < / a > < span class = "lineno" > 209< / span >   }< / div >
< div class = "line" > < a name = "l00210" > < / a > < span class = "lineno" > 210< / span >   free(R);< / div >
< div class = "line" > < a name = "l00211" > < / a > < span class = "lineno" > 211< / span >   free(Q);< / div >
< div class = "line" > < a name = "l00212" > < / a > < span class = "lineno" > 212< / span >   < / div >
< div class = "line" > < a name = "l00213" > < / a > < span class = "lineno" > 213< / span >   < span class = "keywordflow" > return< / span > dtime;< / div >
< div class = "line" > < a name = "l00214" > < / a > < span class = "lineno" > 214< / span >   }< / div >
2020-06-28 23:07:29 +08: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 = "../../d7/d50/qr__eigen__values_8c_a0d8ed79786d17df48396b333c09d05bb_cgraph.svg" width = "534" height = "215" > < 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 = "a741477692f001a805b0fea942c9dc2b9" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a741477692f001a805b0fea942c9dc2b9" > ◆ < / a > < / span > mat_mul()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > double** mat_mul < / 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 > R1< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > C1< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > R2< / em > , < / td >
< / tr >
< tr >
< td class = "paramkey" > < / td >
< td > < / td >
< td class = "paramtype" > int  < / td >
< td class = "paramname" > < em > C2< / em >   < / td >
< / tr >
< tr >
< td > < / td >
< td > )< / td >
< td > < / td > < td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< p > Perform multiplication of two matrices. < / p >
< ul >
2020-06-28 23:07:29 +08:00
< li > R2 must be equal to C1< / li >
< li > Resultant matrix size should be R1xC2 < dl class = "params" > < dt > Parameters< / dt > < dd >
< table class = "params" >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > A< / td > < td > first matrix to multiply < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > B< / td > < td > second matrix to multiply < / td > < / tr >
< tr > < td class = "paramdir" > [out]< / td > < td class = "paramname" > OUT< / td > < td > output matrix (must be pre-allocated) < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > R1< / td > < td > number of rows of first matrix < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > C1< / td > < td > number of columns of first matrix < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > R2< / td > < td > number of rows of second matrix < / td > < / tr >
< tr > < td class = "paramdir" > [in]< / td > < td class = "paramname" > C2< / td > < td > number of columns of second matrix < / td > < / tr >
< / table >
< / dd >
< / dl >
< dl class = "section return" > < dt > Returns< / dt > < dd > pointer to resultant matrix < / dd > < / dl >
< / li >
< / ul >
2020-06-29 04:40:24 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00061" > < / a > < span class = "lineno" > 61< / span >   {< / div >
< div class = "line" > < a name = "l00062" > < / a > < span class = "lineno" > 62< / span >   < span class = "keywordflow" > if< / span > (C1 != R2)< / div >
< div class = "line" > < a name = "l00063" > < / a > < span class = "lineno" > 63< / span >   {< / div >
< div class = "line" > < a name = "l00064" > < / a > < span class = "lineno" > 64< / span >   perror(< span class = "stringliteral" > " Matrix dimensions mismatch!" < / span > );< / div >
< div class = "line" > < a name = "l00065" > < / a > < span class = "lineno" > 65< / span >   < span class = "keywordflow" > return< / span > OUT;< / div >
< div class = "line" > < a name = "l00066" > < / a > < span class = "lineno" > 66< / span >   }< / div >
< div class = "line" > < a name = "l00067" > < / a > < span class = "lineno" > 67< / span >   < / div >
< div class = "line" > < a name = "l00068" > < / a > < span class = "lineno" > 68< / span >   < span class = "keywordtype" > int< / span > i;< / div >
< div class = "line" > < a name = "l00069" > < / a > < span class = "lineno" > 69< / span >   < span class = "preprocessor" > #ifdef _OPENMP< / span > < / div >
< div class = "line" > < a name = "l00070" > < / a > < span class = "lineno" > 70< / span >   < span class = "preprocessor" > #pragma omp for< / span > < / div >
< div class = "line" > < a name = "l00071" > < / a > < span class = "lineno" > 71< / span >   < span class = "preprocessor" > #endif< / span > < / div >
< div class = "line" > < a name = "l00072" > < / a > < span class = "lineno" > 72< / span >   < span class = "keywordflow" > for< / span > (i = 0; i < R1; i++)< / div >
2020-07-11 10:24:26 +08:00
< div class = "line" > < a name = "l00073" > < / a > < span class = "lineno" > 73< / span >   {< / div >
< div class = "line" > < a name = "l00074" > < / a > < span class = "lineno" > 74< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > j = 0; j < C2; j++)< / div >
< div class = "line" > < a name = "l00075" > < / a > < span class = "lineno" > 75< / span >   {< / div >
< div class = "line" > < a name = "l00076" > < / a > < span class = "lineno" > 76< / span >   OUT[i][j] = 0.f;< / div >
< div class = "line" > < a name = "l00077" > < / a > < span class = "lineno" > 77< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > k = 0; k < C1; k++) OUT[i][j] += A[i][k] * B[k][j];< / div >
< div class = "line" > < a name = "l00078" > < / a > < span class = "lineno" > 78< / span >   }< / div >
< div class = "line" > < a name = "l00079" > < / a > < span class = "lineno" > 79< / span >   }< / div >
< div class = "line" > < a name = "l00080" > < / a > < span class = "lineno" > 80< / span >   < span class = "keywordflow" > return< / span > OUT;< / div >
< div class = "line" > < a name = "l00081" > < / a > < span class = "lineno" > 81< / span >   }< / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
< a id = "a1440a7779ac56f47a3f355ce4a8c7da0" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a1440a7779ac56f47a3f355ce4a8c7da0" > ◆ < / a > < / span > test1()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void test1 < / td >
< td > (< / td >
< td class = "paramname" > < / td > < td > )< / td >
< td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< p > test function to compute eigen values of a 2x2 matrix < / p >
< p class = "formulaDsp" >
2020-06-28 23:07:29 +08:00
\[\begin{bmatrix} 5 & 7\\ 7 & 11 \end{bmatrix}\]
< / p >
< p > which are approximately, {15.56158, 0.384227} < / p >
2020-07-11 10:24:26 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00225" > < / a > < span class = "lineno" > 225< / span >   {< / div >
< div class = "line" > < a name = "l00226" > < / a > < span class = "lineno" > 226< / span >   < span class = "keywordtype" > int< / span > mat_size = 2;< / div >
< div class = "line" > < a name = "l00227" > < / a > < span class = "lineno" > 227< / span >   < span class = "keywordtype" > double< / span > X[][2] = {{5, 7}, {7, 11}};< / div >
< div class = "line" > < a name = "l00228" > < / a > < span class = "lineno" > 228< / span >   < span class = "keywordtype" > double< / span > y[] = {15.56158, 0.384227}; < span class = "comment" > // corresponding y-values< / span > < / div >
< div class = "line" > < a name = "l00229" > < / a > < span class = "lineno" > 229< / span >   < span class = "keywordtype" > double< / span > eig_vals[2] = {0, 0};< / div >
< div class = "line" > < a name = "l00230" > < / a > < span class = "lineno" > 230< / span >   < / div >
< div class = "line" > < a name = "l00231" > < / a > < span class = "lineno" > 231< / span >   < span class = "comment" > // The following steps are to convert a " double[][]" to " double **" < / span > < / div >
< div class = "line" > < a name = "l00232" > < / a > < span class = "lineno" > 232< / span >   < span class = "keywordtype" > double< / span > **A = (< span class = "keywordtype" > double< / span > **)malloc(mat_size * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > *));< / div >
< div class = "line" > < a name = "l00233" > < / a > < span class = "lineno" > 233< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < mat_size; i++) A[i] = X[i];< / div >
< div class = "line" > < a name = "l00234" > < / a > < span class = "lineno" > 234< / span >   < / div >
< div class = "line" > < a name = "l00235" > < / a > < span class = "lineno" > 235< / span >   printf(< span class = "stringliteral" > " ------- Test 1 -------\n" < / span > );< / div >
< div class = "line" > < a name = "l00236" > < / a > < span class = "lineno" > 236< / span >   < / div >
< div class = "line" > < a name = "l00237" > < / a > < span class = "lineno" > 237< / span >   < span class = "keywordtype" > double< / span > dtime = < a class = "code" href = "../../d7/d50/qr__eigen__values_8c.html#a0d8ed79786d17df48396b333c09d05bb" > eigen_values< / a > (A, eig_vals, mat_size, 0);< / div >
< div class = "line" > < a name = "l00238" > < / a > < span class = "lineno" > 238< / span >   < / div >
< div class = "line" > < a name = "l00239" > < / a > < span class = "lineno" > 239< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < mat_size; i++)< / div >
< div class = "line" > < a name = "l00240" > < / a > < span class = "lineno" > 240< / span >   {< / div >
< div class = "line" > < a name = "l00241" > < / a > < span class = "lineno" > 241< / span >   printf(< span class = "stringliteral" > " %d/5 Checking for %.3g --> " < / span > , i + 1, y[i]);< / div >
< div class = "line" > < a name = "l00242" > < / a > < span class = "lineno" > 242< / span >   < span class = "keywordtype" > char< / span > result = 0;< / div >
< div class = "line" > < a name = "l00243" > < / a > < span class = "lineno" > 243< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > j = 0; j < mat_size & & !result; j++)< / div >
< div class = "line" > < a name = "l00244" > < / a > < span class = "lineno" > 244< / span >   {< / div >
< div class = "line" > < a name = "l00245" > < / a > < span class = "lineno" > 245< / span >   < span class = "keywordflow" > if< / span > (fabs(y[i] - eig_vals[j]) < 0.1)< / div >
< div class = "line" > < a name = "l00246" > < / a > < span class = "lineno" > 246< / span >   {< / div >
< div class = "line" > < a name = "l00247" > < / a > < span class = "lineno" > 247< / span >   result = 1;< / div >
< div class = "line" > < a name = "l00248" > < / a > < span class = "lineno" > 248< / span >   printf(< span class = "stringliteral" > " (%.3g) " < / span > , eig_vals[j]);< / div >
< div class = "line" > < a name = "l00249" > < / a > < span class = "lineno" > 249< / span >   }< / div >
< div class = "line" > < a name = "l00250" > < / a > < span class = "lineno" > 250< / span >   }< / div >
< div class = "line" > < a name = "l00251" > < / a > < span class = "lineno" > 251< / span >   < / div >
< div class = "line" > < a name = "l00252" > < / a > < span class = "lineno" > 252< / span >   < span class = "comment" > // ensure that i^th expected eigen value was computed< / span > < / div >
< div class = "line" > < a name = "l00253" > < / a > < span class = "lineno" > 253< / span >   assert(result != 0);< / div >
< div class = "line" > < a name = "l00254" > < / a > < span class = "lineno" > 254< / span >   printf(< span class = "stringliteral" > " found\n" < / span > );< / div >
< div class = "line" > < a name = "l00255" > < / a > < span class = "lineno" > 255< / span >   }< / div >
< div class = "line" > < a name = "l00256" > < / a > < span class = "lineno" > 256< / span >   printf(< span class = "stringliteral" > " Test 1 Passed in %.3g sec\n\n" < / span > , dtime);< / div >
< div class = "line" > < a name = "l00257" > < / a > < span class = "lineno" > 257< / span >   free(A);< / div >
< div class = "line" > < a name = "l00258" > < / a > < span class = "lineno" > 258< / span >   }< / div >
2020-06-28 23:07:29 +08: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 = "../../d7/d50/qr__eigen__values_8c_a1440a7779ac56f47a3f355ce4a8c7da0_cgraph.svg" width = "632" height = "215" > < 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 = "a0283886819c7c140a023582b7269e2d0" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a0283886819c7c140a023582b7269e2d0" > ◆ < / a > < / span > test2()< / h2 >
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
< td class = "memname" > void test2 < / td >
< td > (< / td >
< td class = "paramname" > < / td > < td > )< / td >
< td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< p > test function to compute eigen values of a 2x2 matrix < / p >
< p class = "formulaDsp" >
2020-06-28 23:07:29 +08:00
\[\begin{bmatrix} -4& 4& 2& 0& -3\\ 4& -4& 4& -3& -1\\ 2& 4& 4& 3& -3\\ 0& -3& 3& -1& -1\\ -3& -1& -3& -3& 0 \end{bmatrix}\]
< / p >
< p > which are approximately, {9.27648, -9.26948, 2.0181, -1.03516, -5.98994} < / p >
2020-07-11 10:24:26 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00272" > < / a > < span class = "lineno" > 272< / span >   {< / div >
< div class = "line" > < a name = "l00273" > < / a > < span class = "lineno" > 273< / span >   < span class = "keywordtype" > int< / span > mat_size = 5;< / div >
< div class = "line" > < a name = "l00274" > < / a > < span class = "lineno" > 274< / span >   < span class = "keywordtype" > double< / span > X[][5] = {{-4, 4, 2, 0, -3},< / div >
< div class = "line" > < a name = "l00275" > < / a > < span class = "lineno" > 275< / span >   {4, -4, 4, -3, -1},< / div >
< div class = "line" > < a name = "l00276" > < / a > < span class = "lineno" > 276< / span >   {2, 4, 4, 3, -3},< / div >
< div class = "line" > < a name = "l00277" > < / a > < span class = "lineno" > 277< / span >   {0, -3, 3, -1, -3},< / div >
< div class = "line" > < a name = "l00278" > < / a > < span class = "lineno" > 278< / span >   {-3, -1, -3, -3, 0}};< / div >
< div class = "line" > < a name = "l00279" > < / a > < span class = "lineno" > 279< / span >   < span class = "keywordtype" > double< / span > y[] = {9.27648, -9.26948, 2.0181, -1.03516,< / div >
< div class = "line" > < a name = "l00280" > < / a > < span class = "lineno" > 280< / span >   -5.98994}; < span class = "comment" > // corresponding y-values< / span > < / div >
< div class = "line" > < a name = "l00281" > < / a > < span class = "lineno" > 281< / span >   < span class = "keywordtype" > double< / span > eig_vals[5];< / div >
< div class = "line" > < a name = "l00282" > < / a > < span class = "lineno" > 282< / span >   < / div >
< div class = "line" > < a name = "l00283" > < / a > < span class = "lineno" > 283< / span >   < span class = "comment" > // The following steps are to convert a " double[][]" to " double **" < / span > < / div >
< div class = "line" > < a name = "l00284" > < / a > < span class = "lineno" > 284< / span >   < span class = "keywordtype" > double< / span > **A = (< span class = "keywordtype" > double< / span > **)malloc(mat_size * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > *));< / div >
< div class = "line" > < a name = "l00285" > < / a > < span class = "lineno" > 285< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < mat_size; i++) A[i] = X[i];< / div >
< div class = "line" > < a name = "l00286" > < / a > < span class = "lineno" > 286< / span >   < / div >
< div class = "line" > < a name = "l00287" > < / a > < span class = "lineno" > 287< / span >   printf(< span class = "stringliteral" > " ------- Test 2 -------\n" < / span > );< / div >
< div class = "line" > < a name = "l00288" > < / a > < span class = "lineno" > 288< / span >   < / div >
< div class = "line" > < a name = "l00289" > < / a > < span class = "lineno" > 289< / span >   < span class = "keywordtype" > double< / span > dtime = < a class = "code" href = "../../d7/d50/qr__eigen__values_8c.html#a0d8ed79786d17df48396b333c09d05bb" > eigen_values< / a > (A, eig_vals, mat_size, 0);< / div >
< div class = "line" > < a name = "l00290" > < / a > < span class = "lineno" > 290< / span >   < / div >
< div class = "line" > < a name = "l00291" > < / a > < span class = "lineno" > 291< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < mat_size; i++)< / div >
< div class = "line" > < a name = "l00292" > < / a > < span class = "lineno" > 292< / span >   {< / div >
< div class = "line" > < a name = "l00293" > < / a > < span class = "lineno" > 293< / span >   printf(< span class = "stringliteral" > " %d/5 Checking for %.3g --> " < / span > , i + 1, y[i]);< / div >
< div class = "line" > < a name = "l00294" > < / a > < span class = "lineno" > 294< / span >   < span class = "keywordtype" > char< / span > result = 0;< / div >
< div class = "line" > < a name = "l00295" > < / a > < span class = "lineno" > 295< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > j = 0; j < mat_size & & !result; j++)< / div >
< div class = "line" > < a name = "l00296" > < / a > < span class = "lineno" > 296< / span >   {< / div >
< div class = "line" > < a name = "l00297" > < / a > < span class = "lineno" > 297< / span >   < span class = "keywordflow" > if< / span > (fabs(y[i] - eig_vals[j]) < 0.1)< / div >
< div class = "line" > < a name = "l00298" > < / a > < span class = "lineno" > 298< / span >   {< / div >
< div class = "line" > < a name = "l00299" > < / a > < span class = "lineno" > 299< / span >   result = 1;< / div >
< div class = "line" > < a name = "l00300" > < / a > < span class = "lineno" > 300< / span >   printf(< span class = "stringliteral" > " (%.3g) " < / span > , eig_vals[j]);< / div >
< div class = "line" > < a name = "l00301" > < / a > < span class = "lineno" > 301< / span >   }< / div >
< div class = "line" > < a name = "l00302" > < / a > < span class = "lineno" > 302< / span >   }< / div >
< div class = "line" > < a name = "l00303" > < / a > < span class = "lineno" > 303< / span >   < / div >
< div class = "line" > < a name = "l00304" > < / a > < span class = "lineno" > 304< / span >   < span class = "comment" > // ensure that i^th expected eigen value was computed< / span > < / div >
< div class = "line" > < a name = "l00305" > < / a > < span class = "lineno" > 305< / span >   assert(result != 0);< / div >
< div class = "line" > < a name = "l00306" > < / a > < span class = "lineno" > 306< / span >   printf(< span class = "stringliteral" > " found\n" < / span > );< / div >
< div class = "line" > < a name = "l00307" > < / a > < span class = "lineno" > 307< / span >   }< / div >
< div class = "line" > < a name = "l00308" > < / a > < span class = "lineno" > 308< / span >   printf(< span class = "stringliteral" > " Test 2 Passed in %.3g sec\n\n" < / span > , dtime);< / div >
< div class = "line" > < a name = "l00309" > < / a > < span class = "lineno" > 309< / span >   free(A);< / div >
< div class = "line" > < a name = "l00310" > < / a > < span class = "lineno" > 310< / span >   }< / div >
2020-06-28 23:07:29 +08: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 = "../../d7/d50/qr__eigen__values_8c_a0283886819c7c140a023582b7269e2d0_cgraph.svg" width = "632" height = "215" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
< / div >
< / div >
< / div >
< / div >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
2020-06-29 04:40:24 +08:00
< div class = "ttc" id = "aqr__eigen__values_8c_html_a002b2f4894492820fe708b1b7e7c5e70" > < div class = "ttname" > < a href = "../../d7/d50/qr__eigen__values_8c.html#a002b2f4894492820fe708b1b7e7c5e70" > EPSILON< / a > < / div > < div class = "ttdeci" > #define EPSILON< / div > < div class = "ttdoc" > accuracy tolerance limit< / div > < div class = "ttdef" > < b > Definition:< / b > qr_eigen_values.c:20< / 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 = "ttdoc" > number of digits of the large number< / div > < div class = "ttdef" > < b > Definition:< / b > sol1.c:109< / div > < / div >
< div class = "ttc" id = "aqr__decompose_8h_html_a45c7640d9d22c89c11beb1f567843c56" > < div class = "ttname" > < a href = "../../d4/d68/qr__decompose_8h.html#a45c7640d9d22c89c11beb1f567843c56" > qr_decompose< / a > < / div > < div class = "ttdeci" > void qr_decompose(double **A, double **Q, double **R, int M, int N)< / div > < div class = "ttdoc" > Decompose matrix using Gram-Schmidt process.< / div > < div class = "ttdef" > < b > Definition:< / b > qr_decompose.h:142< / div > < / div >
< div class = "ttc" id = "aqr__decompose_8h_html_a90562ce8c3707401e9c5809dece68d6a" > < div class = "ttname" > < a href = "../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a" > print_matrix< / a > < / div > < div class = "ttdeci" > void print_matrix(double **A, int M, int N)< / div > < div class = "ttdoc" > function to display matrix on stdout< / div > < div class = "ttdef" > < b > Definition:< / b > qr_decompose.h:22< / div > < / div >
< div class = "ttc" id = "aqr__eigen__values_8c_html_a741477692f001a805b0fea942c9dc2b9" > < div class = "ttname" > < a href = "../../d7/d50/qr__eigen__values_8c.html#a741477692f001a805b0fea942c9dc2b9" > mat_mul< / a > < / div > < div class = "ttdeci" > double ** mat_mul(double **A, double **B, double **OUT, int R1, int C1, int R2, int C2)< / div > < div class = "ttdoc" > Perform multiplication of two matrices.< / div > < div class = "ttdef" > < b > Definition:< / b > qr_eigen_values.c:59< / div > < / div >
< div class = "ttc" id = "aqr__eigen__values_8c_html_aee57a411f07599034f5ceb8cc7d65b40" > < div class = "ttname" > < a href = "../../d7/d50/qr__eigen__values_8c.html#aee57a411f07599034f5ceb8cc7d65b40" > LIMS< / a > < / div > < div class = "ttdeci" > #define LIMS< / div > < div class = "ttdoc" > limit of range of matrix values< / div > < div class = "ttdef" > < b > Definition:< / b > qr_eigen_values.c:19< / div > < / div >
2020-07-11 10:24:26 +08:00
< div class = "ttc" id = "aqr__eigen__values_8c_html_a0d8ed79786d17df48396b333c09d05bb" > < div class = "ttname" > < a href = "../../d7/d50/qr__eigen__values_8c.html#a0d8ed79786d17df48396b333c09d05bb" > eigen_values< / a > < / div > < div class = "ttdeci" > double eigen_values(double **A, double *eigen_vals, int mat_size, char debug_print)< / div > < div class = "ttdoc" > Compute eigen values using iterative shifted QR decomposition algorithm as follows:< / div > < div class = "ttdef" > < b > Definition:< / b > qr_eigen_values.c:106< / div > < / div >
2020-06-28 23:07:29 +08: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 = "../../d7/d50/qr__eigen__values_8c.html" > qr_eigen_values.c< / a > < / li >
2020-06-28 23:30:37 +08:00
< li class = "footer" > Generated by
2020-06-28 23:07:29 +08: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 >