Documentation for 15ce8ac92d

This commit is contained in:
github-actions
2020-10-30 16:31:57 +00:00
parent 2e6c2d823a
commit 76d718f563
210 changed files with 5654 additions and 4667 deletions

View File

@@ -0,0 +1,251 @@
<!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.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: /Users/runner/work/C-Plus-Plus/C-Plus-Plus/numerical_methods/rungekutta.cpp</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C++
&#160;<span id="projectnumber">1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('dc/dc4/_2_users_2runner_2work_2_c-_plus-_plus_2_c-_plus-_plus_2numerical_methods_2rungekutta_8cpp-example.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="headertitle">
<div class="title">/Users/runner/work/C-Plus-Plus/C-Plus-Plus/numerical_methods/rungekutta.cpp</div> </div>
</div><!--header-->
<div class="contents">
<p>it solves \frac{\mathrm{d} y}{\mathrm{d} x}= \frac{\left ( x-y \right )}{2} given x for given initial conditions There can be many such equations</p>
<div class="fragment"><div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @{</span></div>
<div class="line"><span class="comment"> * \file</span></div>
<div class="line"><span class="comment"> * \brief [Runge Kutta fourth order](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods) method implementation</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * \author [Rudra Prasad Das](http://github.com/rudra697)</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * \details</span></div>
<div class="line"><span class="comment"> * It solves the unknown value of y </span></div>
<div class="line"><span class="comment"> * for a given value of x</span></div>
<div class="line"><span class="comment"> * only first order differential equations</span></div>
<div class="line"><span class="comment"> * can be solved</span></div>
<div class="line"><span class="comment"> * \example</span></div>
<div class="line"><span class="comment"> * it solves \frac{\mathrm{d} y}{\mathrm{d} x}= \frac{\left ( x-y \right )}{2}</span></div>
<div class="line"><span class="comment"> * given x for given initial </span></div>
<div class="line"><span class="comment"> * conditions</span></div>
<div class="line"><span class="comment"> * There can be many such equations </span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span> <span class="comment">/// for io operations</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#include &lt;vector&gt;</span> <span class="comment">/// for using the vector container</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#include &lt;cassert&gt;</span> <span class="comment">/// asserting the test functions</span></div>
<div class="line"><span class="comment"></span><span class="comment"></span> </div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @brief The change() function is used </span></div>
<div class="line"><span class="comment"> * to return the updated iterative value corresponding </span></div>
<div class="line"><span class="comment"> * to the given function</span></div>
<div class="line"><span class="comment"> * @param x is the value corresponding to the x coordinate</span></div>
<div class="line"><span class="comment"> * @param y is the value corresponding to the y coordinate </span></div>
<div class="line"><span class="comment"> * @returns the computed function value at that call</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">double</span> <a name="a0"></a><a class="code" href="../../d1/da6/rungekutta_8cpp.html#a450497475f5607333f9aca8f88901579">change</a>(<span class="keywordtype">double</span> x, <span class="keywordtype">double</span> y) </div>
<div class="line">{ </div>
<div class="line"> <span class="keywordflow">return</span> ((x - y)/2.0); </div>
<div class="line"> </div>
<div class="line">} </div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @namespace numerical_methods</span></div>
<div class="line"><span class="comment"> * @brief Numerical Methods</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keyword">namespace </span><a class="code" href="../../d1/de0/namespacenumerical__methods.html">numerical_methods</a> {<span class="comment"></span></div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @namespace runge_kutta</span></div>
<div class="line"><span class="comment"> * @brief Functions for [Runge Kutta fourth order](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods) method</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keyword">namespace </span><a class="code" href="../../d2/de7/namespacerunge__kutta.html">runge_kutta</a> {<span class="comment"></span></div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @brief the Runge Kutta method finds the value of integration of a function in the given limits.</span></div>
<div class="line"><span class="comment"> * the lower limit of integration as the initial value and the upper limit is the given x</span></div>
<div class="line"><span class="comment"> * @param init_x is the value of initial x and is updated after each call</span></div>
<div class="line"><span class="comment"> * @param init_y is the value of initial x and is updated after each call</span></div>
<div class="line"><span class="comment"> * @param x is current iteration at which the function needs to be evaluated</span></div>
<div class="line"><span class="comment"> * @param h is the step value </span></div>
<div class="line"><span class="comment"> * @returns the value of y at thr required value of x from the initial conditions</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keywordtype">double</span> <a name="a1"></a><a class="code" href="../../d1/da6/rungekutta_8cpp.html#a7b9f40c7b5e9749cc550f19be3dc8856">rungeKutta</a>(<span class="keywordtype">double</span> init_x, <span class="keyword">const</span> <span class="keywordtype">double</span> &amp;init_y, <span class="keyword">const</span> <span class="keywordtype">double</span> &amp;x, <span class="keyword">const</span> <span class="keywordtype">double</span> &amp;<a name="a2"></a><a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>) </div>
<div class="line">{ </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Count number of iterations </span></div>
<div class="line"> <span class="comment">// using step size or </span></div>
<div class="line"> <span class="comment">// step height h </span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// n calucates the number of iterations</span></div>
<div class="line"> <span class="comment">// k1, k2, k3, k4 are the Runge Kutta variables </span></div>
<div class="line"> <span class="comment">// used for calculation of y at each iteration</span></div>
<div class="line"> </div>
<div class="line"> <span class="keyword">auto</span> n = <span class="keyword">static_cast&lt;</span>uint64_t<span class="keyword">&gt;</span>((x - init_x) / <a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>); </div>
<div class="line"> <span class="comment">// used a vector container for the variables</span></div>
<div class="line"> <a name="_a3"></a><a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;double&gt;</a> k(4,0.0);</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Iterate for number of iterations </span></div>
<div class="line"> </div>
<div class="line"> <span class="keywordtype">double</span> y = init_y; </div>
<div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=1; i&lt;=n; ++i) </div>
<div class="line"> { </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Apply Runge Kutta Formulas </span></div>
<div class="line"> <span class="comment">// to find next value of y </span></div>
<div class="line"> k[0] = <a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>*<a class="code" href="../../d1/da6/rungekutta_8cpp.html#a450497475f5607333f9aca8f88901579">change</a>(init_x, y); </div>
<div class="line"> k[1] = <a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>*<a class="code" href="../../d1/da6/rungekutta_8cpp.html#a450497475f5607333f9aca8f88901579">change</a>(init_x + 0.5*<a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>, y + 0.5*k[0]); </div>
<div class="line"> k[2] = <a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>*<a class="code" href="../../d1/da6/rungekutta_8cpp.html#a450497475f5607333f9aca8f88901579">change</a>(init_x + 0.5*<a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>, y + 0.5*k[1]); </div>
<div class="line"> k[3] = <a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>*<a class="code" href="../../d1/da6/rungekutta_8cpp.html#a450497475f5607333f9aca8f88901579">change</a>(init_x + <a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>, y + k[2]); </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Update next value of y </span></div>
<div class="line"> </div>
<div class="line"> y += (1.0/6.0)*(k[0] + 2*k[1] + 2*k[2] + k[3]);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Update next value of x </span></div>
<div class="line"> </div>
<div class="line"> init_x += <a class="code" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>; </div>
<div class="line"> } </div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> y; </div>
<div class="line">} </div>
<div class="line">} <span class="comment">// namespace runge_kutta</span></div>
<div class="line">} <span class="comment">// namespace numerical_methods</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @brief Tests to check algorithm implementation.</span></div>
<div class="line"><span class="comment"> * @returns void </span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> <span class="keyword">static</span> <span class="keywordtype">void</span> <a name="a4"></a><a class="code" href="../../dc/d5a/rat__maze_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>()</div>
<div class="line"> {</div>
<div class="line"> <a name="_a5"></a><a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;The Runge Kutta function will be tested on the basis of precomputed values\n&quot;</span>;</div>
<div class="line"> </div>
<div class="line"> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Test 1....&quot;</span> &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"> <span class="keywordtype">double</span> valfirst=<a class="code" href="../../d1/da6/rungekutta_8cpp.html#a7b9f40c7b5e9749cc550f19be3dc8856">numerical_methods::runge_kutta::rungeKutta</a>(2,3,4,0.2); <span class="comment">// Tests the function with pre calculated values</span></div>
<div class="line"> assert(valfirst==3.10363932323749570);</div>
<div class="line"> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Passed Test 1\n&quot;</span>;</div>
<div class="line"> </div>
<div class="line"> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Test 2....&quot;</span> &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"> <span class="keywordtype">double</span> valsec=<a class="code" href="../../d1/da6/rungekutta_8cpp.html#a7b9f40c7b5e9749cc550f19be3dc8856">numerical_methods::runge_kutta::rungeKutta</a>(1,2,5,0.1); <span class="comment">// The value of step changed</span></div>
<div class="line"> assert(valsec==3.40600589380261409);</div>
<div class="line"> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Passed Test 2\n&quot;</span>;</div>
<div class="line"> </div>
<div class="line"> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Test 3....&quot;</span> &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"> <span class="keywordtype">double</span> valthird=<a class="code" href="../../d1/da6/rungekutta_8cpp.html#a7b9f40c7b5e9749cc550f19be3dc8856">numerical_methods::runge_kutta::rungeKutta</a>(-1,3,4,0.1); <span class="comment">// Tested with negative value</span></div>
<div class="line"> assert(valthird==2.49251005860244268);</div>
<div class="line"> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Passed Test 3\n&quot;</span>;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment"></span></div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @brief Main function</span></div>
<div class="line"><span class="comment"> * @returns 0 on exit </span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keywordtype">int</span> <a name="a6"></a><a class="code" href="../../d3/d40/graph__coloring_8cpp.html#gae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() </div>
<div class="line">{ </div>
<div class="line"> </div>
<div class="line"> <a class="code" href="../../dc/d5a/rat__maze_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// Execute the tests</span></div>
<div class="line"> <span class="keywordflow">return</span> 0; </div>
<div class="line">} </div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="arat__maze_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../dc/d5a/rat__maze_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Test implementations.</div><div class="ttdef"><b>Definition:</b> rat_maze.cpp:84</div></div>
<div class="ttc" id="anamespacenumerical__methods_html"><div class="ttname"><a href="../../d1/de0/namespacenumerical__methods.html">numerical_methods</a></div><div class="ttdoc">for io operations</div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt; double &gt;</a></div></div>
<div class="ttc" id="agraph__coloring_8cpp_html_gae66f6b31b5ad750f1fe042a706a4e3d4"><div class="ttname"><a href="../../d3/d40/graph__coloring_8cpp.html#gae66f6b31b5ad750f1fe042a706a4e3d4">main</a></div><div class="ttdeci">int main()</div><div class="ttdef"><b>Definition:</b> graph_coloring.cpp:96</div></div>
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
<div class="ttc" id="ahash__search_8cpp_html_a566eaf0ffafd50bc61e644561fd27001"><div class="ttname"><a href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a></div><div class="ttdeci">int h(int key)</div><div class="ttdef"><b>Definition:</b> hash_search.cpp:45</div></div>
<div class="ttc" id="anamespacerunge__kutta_html"><div class="ttname"><a href="../../d2/de7/namespacerunge__kutta.html">runge_kutta</a></div><div class="ttdoc">Functions for Runge Kutta fourth order method.</div></div>
<div class="ttc" id="arungekutta_8cpp_html_a450497475f5607333f9aca8f88901579"><div class="ttname"><a href="../../d1/da6/rungekutta_8cpp.html#a450497475f5607333f9aca8f88901579">change</a></div><div class="ttdeci">static double change(double x, double y)</div><div class="ttdoc">asserting the test functions</div><div class="ttdef"><b>Definition:</b> rungekutta.cpp:31</div></div>
<div class="ttc" id="arungekutta_8cpp_html_a7b9f40c7b5e9749cc550f19be3dc8856"><div class="ttname"><a href="../../d1/da6/rungekutta_8cpp.html#a7b9f40c7b5e9749cc550f19be3dc8856">numerical_methods::runge_kutta::rungeKutta</a></div><div class="ttdeci">double rungeKutta(double init_x, const double &amp;init_y, const double &amp;x, const double &amp;h)</div><div class="ttdoc">the Runge Kutta method finds the value of integration of a function in the given limits....</div><div class="ttdef"><b>Definition:</b> rungekutta.cpp:56</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by <a href="http://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20 </li>
</ul>
</div>
</body>
</html>