mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-26 11:37:13 +08:00
Documentation for 0931d530ae
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.9.5"/>
|
||||
<meta name="generator" content="Doxygen 1.9.6"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Algorithms_in_C++: numerical_methods/composite_simpson_rule.cpp File Reference</title>
|
||||
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||||
@@ -41,7 +41,7 @@ MathJax.Hub.Config({
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.9.5 -->
|
||||
<!-- Generated by Doxygen 1.9.6 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
||||
@@ -134,35 +134,35 @@ Functions</h2></td></tr>
|
||||
<tr class="memitem:a6ccc5eddc537dc0293d0ae3d0480f068"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html#a6ccc5eddc537dc0293d0ae3d0480f068">numerical_methods::simpson_method::evaluate_by_simpson</a> (<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/integer.html">std::int32_t</a> N, double <a class="el" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>, double a, const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/utility/functional/function.html">std::function</a>< double(double)> &func)</td></tr>
|
||||
<tr class="separator:a6ccc5eddc537dc0293d0ae3d0480f068"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a4251b4df4748a0b9c43a48f61bdd2397"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html#a4251b4df4748a0b9c43a48f61bdd2397">numerical_methods::simpson_method::f</a> (double x)</td></tr>
|
||||
<tr class="memdesc:a4251b4df4748a0b9c43a48f61bdd2397"><td class="mdescLeft"> </td><td class="mdescRight">A function f(x) that will be used to test the method. <a href="../../d4/d18/composite__simpson__rule_8cpp.html#a4251b4df4748a0b9c43a48f61bdd2397">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a4251b4df4748a0b9c43a48f61bdd2397"><td class="mdescLeft"> </td><td class="mdescRight">A function f(x) that will be used to test the method. <br /></td></tr>
|
||||
<tr class="separator:a4251b4df4748a0b9c43a48f61bdd2397"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a2f67508d5f392b0321772169342c98ad"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">numerical_methods::simpson_method::g</a> (double x)</td></tr>
|
||||
<tr class="memdesc:a2f67508d5f392b0321772169342c98ad"><td class="mdescLeft"> </td><td class="mdescRight">Another test function. <a href="../../d4/d18/composite__simpson__rule_8cpp.html#a2f67508d5f392b0321772169342c98ad">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a2f67508d5f392b0321772169342c98ad"><td class="mdescLeft"> </td><td class="mdescRight">Another test function. <br /></td></tr>
|
||||
<tr class="separator:a2f67508d5f392b0321772169342c98ad"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a1b74d828b33760094906797042b89442"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html#a1b74d828b33760094906797042b89442">numerical_methods::simpson_method::k</a> (double x)</td></tr>
|
||||
<tr class="memdesc:a1b74d828b33760094906797042b89442"><td class="mdescLeft"> </td><td class="mdescRight">Another test function. <a href="../../d4/d18/composite__simpson__rule_8cpp.html#a1b74d828b33760094906797042b89442">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a1b74d828b33760094906797042b89442"><td class="mdescLeft"> </td><td class="mdescRight">Another test function. <br /></td></tr>
|
||||
<tr class="separator:a1b74d828b33760094906797042b89442"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a6d8df83a6f26ce24a75d3b358b7f5b8a"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html#a6d8df83a6f26ce24a75d3b358b7f5b8a">numerical_methods::simpson_method::l</a> (double x)</td></tr>
|
||||
<tr class="memdesc:a6d8df83a6f26ce24a75d3b358b7f5b8a"><td class="mdescLeft"> </td><td class="mdescRight">Another test function. <a href="../../d4/d18/composite__simpson__rule_8cpp.html#a6d8df83a6f26ce24a75d3b358b7f5b8a">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a6d8df83a6f26ce24a75d3b358b7f5b8a"><td class="mdescLeft"> </td><td class="mdescRight">Another test function. <br /></td></tr>
|
||||
<tr class="separator:a6d8df83a6f26ce24a75d3b358b7f5b8a"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a2ae48a41e43dc6ab11b962742349646e"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html#a2ae48a41e43dc6ab11b962742349646e">test</a> (<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/integer.html">std::int32_t</a> N, double <a class="el" href="../../d1/df3/hash__search_8cpp.html#a566eaf0ffafd50bc61e644561fd27001">h</a>, double a, double b, bool used_argv_parameters)</td></tr>
|
||||
<tr class="memdesc:a2ae48a41e43dc6ab11b962742349646e"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <a href="../../d4/d18/composite__simpson__rule_8cpp.html#a2ae48a41e43dc6ab11b962742349646e">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a2ae48a41e43dc6ab11b962742349646e"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <br /></td></tr>
|
||||
<tr class="separator:a2ae48a41e43dc6ab11b962742349646e"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a3c04138a5bfe5d72780bb7e82a18e627"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a> (int argc, char **argv)</td></tr>
|
||||
<tr class="memdesc:a3c04138a5bfe5d72780bb7e82a18e627"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../d4/d18/composite__simpson__rule_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a3c04138a5bfe5d72780bb7e82a18e627"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <br /></td></tr>
|
||||
<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 >Implementation of the Composite Simpson Rule for the approximation. </p>
|
||||
<p >The following is an implementation of the Composite Simpson Rule for the approximation of definite integrals. More info -> wiki: <a href="https://en.wikipedia.org/wiki/Simpson%27s_rule#Composite_Simpson's_rule">https://en.wikipedia.org/wiki/Simpson%27s_rule#Composite_Simpson's_rule</a></p>
|
||||
<p >The idea is to split the interval in an EVEN number N of intervals and use as interpolation points the xi for which it applies that xi = x0 + i*h, where h is a step defined as h = (b-a)/N where a and b are the first and last points of the interval of the integration [a, b].</p>
|
||||
<p >We create a table of the xi and their corresponding f(xi) values and we evaluate the integral by the formula: I = h/3 * {f(x0) + 4*f(x1) + 2*f(x2) + ... + 2*f(xN-2) + 4*f(xN-1) + f(xN)}</p>
|
||||
<p >That means that the first and last indexed i f(xi) are multiplied by 1, the odd indexed f(xi) by 4 and the even by 2.</p>
|
||||
<p >In this program there are 4 sample test functions f, g, k, l that are evaluated in the same interval.</p>
|
||||
<p >Arguments can be passed as parameters from the command line argv[1] = N, argv[2] = a, argv[3] = b</p>
|
||||
<p >N must be even number and a<b.</p>
|
||||
<p >In the end of the <a class="el" href="../../d3/d40/graph__coloring_8cpp.html#gae66f6b31b5ad750f1fe042a706a4e3d4" title="Main function.">main()</a> i compare the program's result with the one from mathematical software with 2 decimal points margin.</p>
|
||||
<p >Add sample function by replacing one of the f, g, k, l and the assert</p>
|
||||
<div class="textblock"><p>Implementation of the Composite Simpson Rule for the approximation. </p>
|
||||
<p>The following is an implementation of the Composite Simpson Rule for the approximation of definite integrals. More info -> wiki: <a href="https://en.wikipedia.org/wiki/Simpson%27s_rule#Composite_Simpson's_rule">https://en.wikipedia.org/wiki/Simpson%27s_rule#Composite_Simpson's_rule</a></p>
|
||||
<p>The idea is to split the interval in an EVEN number N of intervals and use as interpolation points the xi for which it applies that xi = x0 + i*h, where h is a step defined as h = (b-a)/N where a and b are the first and last points of the interval of the integration [a, b].</p>
|
||||
<p>We create a table of the xi and their corresponding f(xi) values and we evaluate the integral by the formula: I = h/3 * {f(x0) + 4*f(x1) + 2*f(x2) + ... + 2*f(xN-2) + 4*f(xN-1) + f(xN)}</p>
|
||||
<p>That means that the first and last indexed i f(xi) are multiplied by 1, the odd indexed f(xi) by 4 and the even by 2.</p>
|
||||
<p>In this program there are 4 sample test functions f, g, k, l that are evaluated in the same interval.</p>
|
||||
<p>Arguments can be passed as parameters from the command line argv[1] = N, argv[2] = a, argv[3] = b</p>
|
||||
<p>N must be even number and a<b.</p>
|
||||
<p>In the end of the <a class="el" href="../../d3/d40/graph__coloring_8cpp.html#gae66f6b31b5ad750f1fe042a706a4e3d4" title="Main function.">main()</a> i compare the program's result with the one from mathematical software with 2 decimal points margin.</p>
|
||||
<p>Add sample function by replacing one of the f, g, k, l and the assert</p>
|
||||
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/ggkogkou" target="_blank">ggkogkou</a> </dd></dl>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="a6ccc5eddc537dc0293d0ae3d0480f068" name="a6ccc5eddc537dc0293d0ae3d0480f068"></a>
|
||||
@@ -405,9 +405,9 @@ Here is the call graph for this function:</div>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
||||
<p >Number of intervals to divide the integration interval. MUST BE EVEN</p>
|
||||
<p >Starting and ending point of the integration in the real axis</p>
|
||||
<p >Step, calculated by a, b and N</p>
|
||||
<p>Number of intervals to divide the integration interval. MUST BE EVEN</p>
|
||||
<p>Starting and ending point of the integration in the real axis</p>
|
||||
<p>Step, calculated by a, b and N</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 170</span> {</div>
|
||||
<div class="line"><span class="lineno"> 171</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/integer.html">std::int32_t</a> <a class="code hl_variable" href="../../d6/d42/data__structures_2sparse__table_8cpp.html#a10f3ffb3f6f7e1b83d556b9c8de89a5d">N</a> = 16; <span class="comment">/// Number of intervals to divide the integration</span><span class="comment"></span></div>
|
||||
<div class="line"><span class="lineno"> 172</span><span class="comment"> /// interval. MUST BE EVEN</span></div>
|
||||
@@ -567,7 +567,7 @@ Here is the call graph for this function:</div>
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="../../dir_9c6faab82c22511b50177aa2e38e2780.html">numerical_methods</a></li><li class="navelem"><a class="el" href="../../d4/d18/composite__simpson__rule_8cpp.html">composite_simpson_rule.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.5 </li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user