mirror of
https://github.com/TheAlgorithms/C
synced 2025-01-21 00:52:05 +03:00
Documentation for 81f4428569
This commit is contained in:
parent
35166e32da
commit
2f8c7039b2
@ -272,97 +272,113 @@ int </td><td class="memItemRight" valign="bottom"><a class="el" href="../..
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>time for computation in seconds </dd></dl>
|
||||
<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">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="l00108"></a><span class="lineno"> 108</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="l00109"></a><span class="lineno"> 109</span>  </div>
|
||||
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordflow">if</span> (!eigen_vals)</div>
|
||||
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  {</div>
|
||||
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  perror(<span class="stringliteral">"Output eigen value vector cannot be NULL!"</span>);</div>
|
||||
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  <span class="keywordflow">return</span> -1;</div>
|
||||
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  }</div>
|
||||
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!Q || !R)</div>
|
||||
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  {</div>
|
||||
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  perror(<span class="stringliteral">"Unable to allocate memory for Q & R!"</span>);</div>
|
||||
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  <span class="keywordflow">return</span> -1;</div>
|
||||
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  }</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>  <span class="comment">/* allocate dynamic memory for matrices */</span></div>
|
||||
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < mat_size; i++)</div>
|
||||
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  {</div>
|
||||
<div class="line"><a name="l00124"></a><span class="lineno"> 124</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="l00125"></a><span class="lineno"> 125</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="l00126"></a><span class="lineno"> 126</span>  <span class="keywordflow">if</span> (!Q[i] || !R[i])</div>
|
||||
<div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  {</div>
|
||||
<div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  perror(<span class="stringliteral">"Unable to allocate memory for Q & R."</span>);</div>
|
||||
<div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  <span class="keywordflow">return</span> -1;</div>
|
||||
<div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  }</div>
|
||||
<div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  }</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>  <span class="keywordflow">if</span> (debug_print)</div>
|
||||
<div class="line"><a name="l00134"></a><span class="lineno"> 134</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="l00135"></a><span class="lineno"> 135</span>  </div>
|
||||
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  <span class="keywordtype">int</span> rows = mat_size, columns = mat_size;</div>
|
||||
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  <span class="keywordtype">int</span> counter = 0, num_eigs = rows - 1;</div>
|
||||
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  <span class="keywordtype">double</span> last_eig = 0;</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>  clock_t t1 = clock();</div>
|
||||
<div class="line"><a name="l00141"></a><span class="lineno"> 141</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="l00142"></a><span class="lineno"> 142</span>  {</div>
|
||||
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  <span class="comment">/* iterate with QR decomposition */</span></div>
|
||||
<div class="line"><a name="l00144"></a><span class="lineno"> 144</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="l00145"></a><span class="lineno"> 145</span>  {</div>
|
||||
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  last_eig = A[num_eigs][num_eigs];</div>
|
||||
<div class="line"><a name="l00147"></a><span class="lineno"> 147</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="l00148"></a><span class="lineno"> 148</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="l00149"></a><span class="lineno"> 149</span>  </div>
|
||||
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  <span class="keywordflow">if</span> (debug_print)</div>
|
||||
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  {</div>
|
||||
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <a class="code" href="../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a">print_matrix</a>(A, rows, columns);</div>
|
||||
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <a class="code" href="../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a">print_matrix</a>(Q, rows, columns);</div>
|
||||
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  <a class="code" href="../../d4/d68/qr__decompose_8h.html#a90562ce8c3707401e9c5809dece68d6a">print_matrix</a>(R, columns, columns);</div>
|
||||
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  printf(<span class="stringliteral">"-------------------- %d ---------------------\n"</span>,</div>
|
||||
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  ++counter);</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>  </div>
|
||||
<div class="line"><a name="l00159"></a><span class="lineno"> 159</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="l00160"></a><span class="lineno"> 160</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="l00161"></a><span class="lineno"> 161</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">/* store the converged eigen value */</span></div>
|
||||
<div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  eigen_vals[num_eigs] = last_eig;</div>
|
||||
<div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  </div>
|
||||
<div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  <span class="keywordflow">if</span> (debug_print)</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>  printf(<span class="stringliteral">"========================\n"</span>);</div>
|
||||
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  printf(<span class="stringliteral">"Eigen value: % g,\n"</span>, last_eig);</div>
|
||||
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  printf(<span class="stringliteral">"========================\n"</span>);</div>
|
||||
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  }</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>  num_eigs--;</div>
|
||||
<div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  rows--;</div>
|
||||
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  columns--;</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>  eigen_vals[0] = A[0][0];</div>
|
||||
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  <span class="keywordtype">double</span> dtime = (double)(clock() - t1) / CLOCKS_PER_SEC;</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>  <span class="keywordflow">if</span> (debug_print)</div>
|
||||
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  {</div>
|
||||
<div class="line"><a name="l00182"></a><span class="lineno"> 182</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="l00183"></a><span class="lineno"> 183</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="l00184"></a><span class="lineno"> 184</span>  }</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>  <span class="comment">/* cleanup dynamic memory */</span></div>
|
||||
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < mat_size; i++)</div>
|
||||
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  {</div>
|
||||
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  free(R[i]);</div>
|
||||
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  free(Q[i]);</div>
|
||||
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  }</div>
|
||||
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  free(R);</div>
|
||||
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  free(Q);</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>  <span class="keywordflow">return</span> dtime;</div>
|
||||
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span> }</div>
|
||||
<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>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@ -458,13 +474,15 @@ Here is the call graph for this function:</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>
|
||||
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < C2; j++)</div>
|
||||
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  {</div>
|
||||
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  OUT[i][j] = 0.f;</div>
|
||||
<div class="line"><a name="l00076"></a><span class="lineno"> 76</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="l00077"></a><span class="lineno"> 77</span>  }</div>
|
||||
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="keywordflow">return</span> OUT;</div>
|
||||
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span> }</div>
|
||||
<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>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
@ -488,40 +506,40 @@ Here is the call graph for this function:</div>
|
||||
\[\begin{bmatrix} 5 & 7\\ 7 & 11 \end{bmatrix}\]
|
||||
</p>
|
||||
<p> which are approximately, {15.56158, 0.384227} </p>
|
||||
<div class="fragment"><div class="line"><a name="l00207"></a><span class="lineno"> 207</span> {</div>
|
||||
<div class="line"><a name="l00208"></a><span class="lineno"> 208</span>  <span class="keywordtype">int</span> mat_size = 2;</div>
|
||||
<div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  <span class="keywordtype">double</span> X[][2] = {{5, 7}, {7, 11}};</div>
|
||||
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  <span class="keywordtype">double</span> y[] = {15.56158, 0.384227}; <span class="comment">// corresponding y-values</span></div>
|
||||
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  <span class="keywordtype">double</span> eig_vals[2];</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="comment">// The following steps are to convert a "double[][]" to "double **"</span></div>
|
||||
<div class="line"><a name="l00214"></a><span class="lineno"> 214</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="l00215"></a><span class="lineno"> 215</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="l00216"></a><span class="lineno"> 216</span>  </div>
|
||||
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  printf(<span class="stringliteral">"------- Test 1 -------\n"</span>);</div>
|
||||
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  </div>
|
||||
<div class="line"><a name="l00219"></a><span class="lineno"> 219</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="l00220"></a><span class="lineno"> 220</span>  </div>
|
||||
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < mat_size; i++)</div>
|
||||
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  {</div>
|
||||
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  printf(<span class="stringliteral">"%d/5 Checking for %.3g --> "</span>, i + 1, y[i]);</div>
|
||||
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  <span class="keywordtype">char</span> result = 0;</div>
|
||||
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < mat_size && !result; j++)</div>
|
||||
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  {</div>
|
||||
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>  <span class="keywordflow">if</span> (fabs(y[i] - eig_vals[j]) < 0.1)</div>
|
||||
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span>  {</div>
|
||||
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span>  result = 1;</div>
|
||||
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span>  printf(<span class="stringliteral">"(%.3g) "</span>, eig_vals[j]);</div>
|
||||
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span>  }</div>
|
||||
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  }</div>
|
||||
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  </div>
|
||||
<div class="line"><a name="l00234"></a><span class="lineno"> 234</span>  <span class="comment">// ensure that i^th expected eigen value was computed</span></div>
|
||||
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  assert(result != 0);</div>
|
||||
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span>  printf(<span class="stringliteral">"found\n"</span>);</div>
|
||||
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  }</div>
|
||||
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  printf(<span class="stringliteral">"Test 1 Passed in %.3g sec\n\n"</span>, dtime);</div>
|
||||
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>  free(A);</div>
|
||||
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span> }</div>
|
||||
<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>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@ -551,45 +569,45 @@ Here is the call graph for this function:</div>
|
||||
\[\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>
|
||||
<div class="fragment"><div class="line"><a name="l00254"></a><span class="lineno"> 254</span> {</div>
|
||||
<div class="line"><a name="l00255"></a><span class="lineno"> 255</span>  <span class="keywordtype">int</span> mat_size = 5;</div>
|
||||
<div class="line"><a name="l00256"></a><span class="lineno"> 256</span>  <span class="keywordtype">double</span> X[][5] = {{-4, 4, 2, 0, -3},</div>
|
||||
<div class="line"><a name="l00257"></a><span class="lineno"> 257</span>  {4, -4, 4, -3, -1},</div>
|
||||
<div class="line"><a name="l00258"></a><span class="lineno"> 258</span>  {2, 4, 4, 3, -3},</div>
|
||||
<div class="line"><a name="l00259"></a><span class="lineno"> 259</span>  {0, -3, 3, -1, -3},</div>
|
||||
<div class="line"><a name="l00260"></a><span class="lineno"> 260</span>  {-3, -1, -3, -3, 0}};</div>
|
||||
<div class="line"><a name="l00261"></a><span class="lineno"> 261</span>  <span class="keywordtype">double</span> y[] = {9.27648, -9.26948, 2.0181, -1.03516,</div>
|
||||
<div class="line"><a name="l00262"></a><span class="lineno"> 262</span>  -5.98994}; <span class="comment">// corresponding y-values</span></div>
|
||||
<div class="line"><a name="l00263"></a><span class="lineno"> 263</span>  <span class="keywordtype">double</span> eig_vals[5];</div>
|
||||
<div class="line"><a name="l00264"></a><span class="lineno"> 264</span>  </div>
|
||||
<div class="line"><a name="l00265"></a><span class="lineno"> 265</span>  <span class="comment">// The following steps are to convert a "double[][]" to "double **"</span></div>
|
||||
<div class="line"><a name="l00266"></a><span class="lineno"> 266</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="l00267"></a><span class="lineno"> 267</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="l00268"></a><span class="lineno"> 268</span>  </div>
|
||||
<div class="line"><a name="l00269"></a><span class="lineno"> 269</span>  printf(<span class="stringliteral">"------- Test 2 -------\n"</span>);</div>
|
||||
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span>  </div>
|
||||
<div class="line"><a name="l00271"></a><span class="lineno"> 271</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="l00272"></a><span class="lineno"> 272</span>  </div>
|
||||
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < mat_size; i++)</div>
|
||||
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  {</div>
|
||||
<div class="line"><a name="l00275"></a><span class="lineno"> 275</span>  printf(<span class="stringliteral">"%d/5 Checking for %.3g --> "</span>, i + 1, y[i]);</div>
|
||||
<div class="line"><a name="l00276"></a><span class="lineno"> 276</span>  <span class="keywordtype">char</span> result = 0;</div>
|
||||
<div class="line"><a name="l00277"></a><span class="lineno"> 277</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < mat_size && !result; j++)</div>
|
||||
<div class="line"><a name="l00278"></a><span class="lineno"> 278</span>  {</div>
|
||||
<div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  <span class="keywordflow">if</span> (fabs(y[i] - eig_vals[j]) < 0.1)</div>
|
||||
<div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  {</div>
|
||||
<div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  result = 1;</div>
|
||||
<div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  printf(<span class="stringliteral">"(%.3g) "</span>, eig_vals[j]);</div>
|
||||
<div class="line"><a name="l00283"></a><span class="lineno"> 283</span>  }</div>
|
||||
<div class="line"><a name="l00284"></a><span class="lineno"> 284</span>  }</div>
|
||||
<div class="line"><a name="l00285"></a><span class="lineno"> 285</span>  </div>
|
||||
<div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  <span class="comment">// ensure that i^th expected eigen value was computed</span></div>
|
||||
<div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  assert(result != 0);</div>
|
||||
<div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  printf(<span class="stringliteral">"found\n"</span>);</div>
|
||||
<div class="line"><a name="l00289"></a><span class="lineno"> 289</span>  }</div>
|
||||
<div class="line"><a name="l00290"></a><span class="lineno"> 290</span>  printf(<span class="stringliteral">"Test 2 Passed in %.3g sec\n\n"</span>, dtime);</div>
|
||||
<div class="line"><a name="l00291"></a><span class="lineno"> 291</span>  free(A);</div>
|
||||
<div class="line"><a name="l00292"></a><span class="lineno"> 292</span> }</div>
|
||||
<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>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
@ -607,7 +625,7 @@ Here is the call graph for this function:</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>
|
||||
<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:104</div></div>
|
||||
<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>
|
||||
<!-- start footer part -->
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
|
@ -252,7 +252,7 @@ Here is the call graph for this function:</div>
|
||||
<div class="ttc" id="aproblem__26_2sol1_8c_html_ac70138609ef6aa6fabca57aca8681e83"><div class="ttname"><a href="../../d1/df9/problem__26_2sol1_8c.html#ac70138609ef6aa6fabca57aca8681e83">compare</a></div><div class="ttdeci">int compare(const void *a, const void *b)</div><div class="ttdoc">comparison function for use with internal qsort algorithm</div><div class="ttdef"><b>Definition:</b> sol1.c:19</div></div>
|
||||
<div class="ttc" id="aproblem__22_2sol1_8c_html_a5bc3659aa0949ea33118c95b1dee5f63"><div class="ttname"><a href="../../dd/d8b/problem__22_2sol1_8c.html#a5bc3659aa0949ea33118c95b1dee5f63">shell_sort</a></div><div class="ttdeci">void shell_sort(char data[][MAX_NAME_LEN], int LEN)</div><div class="ttdoc">Alphabetical sorting using 'shell sort' algorithm.</div><div class="ttdef"><b>Definition:</b> sol1.c:20</div></div>
|
||||
<div class="ttc" id="aproblem__8_2sol1_8c_html_a9ffc8845f17b01a353767a40a3adf7bd"><div class="ttname"><a href="../../dc/d63/problem__8_2sol1_8c.html#a9ffc8845f17b01a353767a40a3adf7bd">get_product</a></div><div class="ttdeci">long long int get_product(FILE *fp, long start_pos, int num_digits)</div><div class="ttdoc">Compute the product of two numbers in a file.</div><div class="ttdef"><b>Definition:</b> sol1.c:16</div></div>
|
||||
<div class="ttc" id="aqr__eigen__values_8c_html_a3c04138a5bfe5d72780bb7e82a18e627"><div class="ttname"><a href="../../d7/d50/qr__eigen__values_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a></div><div class="ttdeci">int main(int argc, char **argv)</div><div class="ttdoc">main function</div><div class="ttdef"><b>Definition:</b> qr_eigen_values.c:297</div></div>
|
||||
<div class="ttc" id="aqr__eigen__values_8c_html_a3c04138a5bfe5d72780bb7e82a18e627"><div class="ttname"><a href="../../d7/d50/qr__eigen__values_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a></div><div class="ttdeci">int main(int argc, char **argv)</div><div class="ttdoc">main function</div><div class="ttdef"><b>Definition:</b> qr_eigen_values.c:315</div></div>
|
||||
<div class="ttc" id="aproblem__401_2sol1_8c_html_adf2a0717e3307419a9d7c52707f5631e"><div class="ttname"><a href="../../d4/d83/problem__401_2sol1_8c.html#adf2a0717e3307419a9d7c52707f5631e">MAX_L</a></div><div class="ttdeci">#define MAX_L</div><div class="ttdoc">chunk size of array allocation</div><div class="ttdef"><b>Definition:</b> sol1.c:18</div></div>
|
||||
<div class="ttc" id="astructdata_html"><div class="ttname"><a href="../../df/dea/structdata.html">data</a></div><div class="ttdef"><b>Definition:</b> prime_factoriziation.c:25</div></div>
|
||||
<div class="ttc" id="amodified__binary__search_8c_html_a7df9a198e30cded6229d79bef7591f8f"><div class="ttname"><a href="../../d3/d47/modified__binary__search_8c.html#a7df9a198e30cded6229d79bef7591f8f">modifiedBinarySearch</a></div><div class="ttdeci">void modifiedBinarySearch(const int **mat, int n, int m, int x)</div><div class="ttdoc">Function to perform binary search on the mid values of row to get the desired pair of rows where the ...</div><div class="ttdef"><b>Definition:</b> modified_binary_search.c:48</div></div>
|
||||
@ -265,7 +265,7 @@ Here is the call graph for this function:</div>
|
||||
<div class="ttc" id="aproblem__22_2sol1_8c_html_afd709f201d7643c3909621f620ea648a"><div class="ttname"><a href="../../dd/d8b/problem__22_2sol1_8c.html#afd709f201d7643c3909621f620ea648a">MAX_NAME_LEN</a></div><div class="ttdeci">#define MAX_NAME_LEN</div><div class="ttdoc">Maximum length of each name.</div><div class="ttdef"><b>Definition:</b> sol1.c:15</div></div>
|
||||
<div class="ttc" id="agroup__sorting_html_ga2fb01e00dedb437a42010f6309e7eba8"><div class="ttname"><a href="../../d5/d4c/group__sorting.html#ga2fb01e00dedb437a42010f6309e7eba8">bead_sort</a></div><div class="ttdeci">void bead_sort(int *a, size_t len)</div><div class="ttdoc">This is where the sorting of the array takes place.</div><div class="ttdef"><b>Definition:</b> bead_sort.c:37</div></div>
|
||||
<div class="ttc" id="arealtime__stats_8c_html_a63ddcdaab24f722f0963fa2fbe0ae628"><div class="ttname"><a href="../../dc/d47/realtime__stats_8c.html#a63ddcdaab24f722f0963fa2fbe0ae628">stats_computer1</a></div><div class="ttdeci">void stats_computer1(float x, float *mean, float *variance, float *std)</div><div class="ttdoc">continuous mean and variance computance using first value as an approximation for the mean.</div><div class="ttdef"><b>Definition:</b> realtime_stats.c:24</div></div>
|
||||
<div class="ttc" id="aqr__eigen__values_8c_html_a0283886819c7c140a023582b7269e2d0"><div class="ttname"><a href="../../d7/d50/qr__eigen__values_8c.html#a0283886819c7c140a023582b7269e2d0">test2</a></div><div class="ttdeci">void test2()</div><div class="ttdoc">test function to compute eigen values of a 2x2 matrix</div><div class="ttdef"><b>Definition:</b> qr_eigen_values.c:253</div></div>
|
||||
<div class="ttc" id="aqr__eigen__values_8c_html_a0283886819c7c140a023582b7269e2d0"><div class="ttname"><a href="../../d7/d50/qr__eigen__values_8c.html#a0283886819c7c140a023582b7269e2d0">test2</a></div><div class="ttdeci">void test2()</div><div class="ttdoc">test function to compute eigen values of a 2x2 matrix</div><div class="ttdef"><b>Definition:</b> qr_eigen_values.c:271</div></div>
|
||||
<div class="ttc" id="aproblem__20_2sol1_8c_html_a54a02c4b963fdb16f24959e0137763f1"><div class="ttname"><a href="../../db/d80/problem__20_2sol1_8c.html#a54a02c4b963fdb16f24959e0137763f1">remove_digits</a></div><div class="ttdeci">char remove_digits(big_int *digit, int N)</div><div class="ttdoc">Function to remove digits preceeding the current digit.</div><div class="ttdef"><b>Definition:</b> sol1.c: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="ttdoc">number of digits of the large number</div><div class="ttdef"><b>Definition:</b> sol1.c:109</div></div>
|
||||
<div class="ttc" id="astruct__big__int_html_a273ee73fd755f2a99512cca5f0e09008"><div class="ttname"><a href="../../dc/d77/struct__big__int.html#a273ee73fd755f2a99512cca5f0e09008">_big_int::value</a></div><div class="ttdeci">char value</div><div class="ttdoc">tens place (single digit)</div><div class="ttdef"><b>Definition:</b> sol1.c:19</div></div>
|
||||
@ -277,7 +277,7 @@ Here is the call graph for this function:</div>
|
||||
<div class="ttc" id="astruct_node_html_a87c003c9f600e3fc58e6e90835f0b605"><div class="ttname"><a href="../../db/d8b/struct_node.html#a87c003c9f600e3fc58e6e90835f0b605">Node::data</a></div><div class="ttdeci">int data</div><div class="ttdoc">stores the number</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:28</div></div>
|
||||
<div class="ttc" id="aproblem__23_2sol2_8c_html_ac5d600bf3077f4188afc4c5cd2c40eaf"><div class="ttname"><a href="../../d4/dbd/problem__23_2sol2_8c.html#ac5d600bf3077f4188afc4c5cd2c40eaf">get_next_abundant</a></div><div class="ttdeci">unsigned long get_next_abundant(unsigned long N)</div><div class="ttdoc">Find the next abundant number after N and not including N.</div><div class="ttdef"><b>Definition:</b> sol2.c:70</div></div>
|
||||
<div class="ttc" id="astruct_node_html"><div class="ttname"><a href="../../db/d8b/struct_node.html">Node</a></div><div class="ttdoc">Node, the basic data structure of the tree.</div><div class="ttdef"><b>Definition:</b> threaded_binary_trees.c:27</div></div>
|
||||
<div class="ttc" id="aqr__eigen__values_8c_html_a1440a7779ac56f47a3f355ce4a8c7da0"><div class="ttname"><a href="../../d7/d50/qr__eigen__values_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">test1</a></div><div class="ttdeci">void test1()</div><div class="ttdoc">test function to compute eigen values of a 2x2 matrix</div><div class="ttdef"><b>Definition:</b> qr_eigen_values.c:206</div></div>
|
||||
<div class="ttc" id="aqr__eigen__values_8c_html_a1440a7779ac56f47a3f355ce4a8c7da0"><div class="ttname"><a href="../../d7/d50/qr__eigen__values_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">test1</a></div><div class="ttdeci">void test1()</div><div class="ttdoc">test function to compute eigen values of a 2x2 matrix</div><div class="ttdef"><b>Definition:</b> qr_eigen_values.c:224</div></div>
|
||||
<div class="ttc" id="arealtime__stats_8c_html_aa54c915581fcc495489175a4386d59fd"><div class="ttname"><a href="../../dc/d47/realtime__stats_8c.html#aa54c915581fcc495489175a4386d59fd">test_function</a></div><div class="ttdeci">void test_function(const float *test_data, const int number_of_samples)</div><div class="ttdoc">Test the algorithm implementation.</div><div class="ttdef"><b>Definition:</b> realtime_stats.c:92</div></div>
|
||||
<div class="ttc" id="aproblem__25_2sol1_8c_html_a001791a21d538b8b9176287ae60d9b61"><div class="ttname"><a href="../../d8/d32/problem__25_2sol1_8c.html#a001791a21d538b8b9176287ae60d9b61">MAX_DIGITS</a></div><div class="ttdeci">#define MAX_DIGITS</div><div class="ttdoc">maximum number of digits</div><div class="ttdef"><b>Definition:</b> sol1.c:13</div></div>
|
||||
<div class="ttc" id="aproblem__10_2sol1_8c_html_ae3d987cb2ad0ddb0c3caa4c2506a20e5"><div class="ttname"><a href="../../d0/d6d/problem__10_2sol1_8c.html#ae3d987cb2ad0ddb0c3caa4c2506a20e5">sum_of_primes</a></div><div class="ttdeci">unsigned long long sum_of_primes(unsigned long N)</div><div class="ttdoc">Computes sum of prime numbers less than N.</div><div class="ttdef"><b>Definition:</b> sol1.c:21</div></div>
|
||||
@ -332,7 +332,7 @@ Here is the call graph for this function:</div>
|
||||
<div class="ttc" id="agroup__sorting_html_gab99b8a397bdd0bf2903d66c22ba4ba43"><div class="ttname"><a href="../../d5/d4c/group__sorting.html#gab99b8a397bdd0bf2903d66c22ba4ba43">merge_sort</a></div><div class="ttdeci">void merge_sort(int *a, int n, int l, int r)</div><div class="ttdoc">Merge sort algorithm implementation.</div><div class="ttdef"><b>Definition:</b> merge_sort.c:82</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>
|
||||
<div class="ttc" id="abinary__search_8c_html_a908fd6d2ad0bba33f63f8454888a0032"><div class="ttname"><a href="../../df/d3b/binary__search_8c.html#a908fd6d2ad0bba33f63f8454888a0032">binarysearch2</a></div><div class="ttdeci">int binarysearch2(const int *arr, int l, int r, int x)</div><div class="ttdoc">Iterative implementation.</div><div class="ttdef"><b>Definition:</b> binary_search.c:51</div></div>
|
||||
<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:104</div></div>
|
||||
<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>
|
||||
<div class="ttc" id="agroup__sorting_html_ga4fdb8af29a07ac8f496e49a11bf9f1bd"><div class="ttname"><a href="../../d5/d4c/group__sorting.html#ga4fdb8af29a07ac8f496e49a11bf9f1bd">BEAD</a></div><div class="ttdeci">#define BEAD(i, j)</div><div class="ttdoc">Create easy access of elements from a 2D matrix stored in memory as a 1D array.</div><div class="ttdef"><b>Definition:</b> bead_sort.c:16</div></div>
|
||||
<div class="ttc" id="ac__atoi__str__to__integer_8c_html_a8c66c03637e48e375b80b5d7791e57be"><div class="ttname"><a href="../../d7/dd8/c__atoi__str__to__integer_8c.html#a8c66c03637e48e375b80b5d7791e57be">test_c_atoi</a></div><div class="ttdeci">void test_c_atoi()</div><div class="ttdoc">test the function implementation</div><div class="ttdef"><b>Definition:</b> c_atoi_str_to_integer.c:56</div></div>
|
||||
<div class="ttc" id="agroup__sorting_html_ga5bc16eaf3ffe6a6ab66780dd445904c0"><div class="ttname"><a href="../../d5/d4c/group__sorting.html#ga5bc16eaf3ffe6a6ab66780dd445904c0">shell_sort</a></div><div class="ttdeci">void shell_sort(int *array, long LEN)</div><div class="ttdoc">Shell sort algorithm.</div><div class="ttdef"><b>Definition:</b> shell_sort2.c:41</div></div>
|
||||
|
Loading…
Reference in New Issue
Block a user