Files
C-Plus-Plus/dd/d29/false__position_8cpp.html
2022-01-02 02:55:05 +00:00

396 lines
29 KiB
HTML

<!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=11"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: numerical_methods/false_position.cpp File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;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.9.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
/* @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:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(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:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('dd/d29/false__position_8cpp.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#namespaces">Namespaces</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">false_position.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p>Solve the equation \(f(x)=0\) using <a href="https://en.wikipedia.org/wiki/Regula_falsi" target="_blank">false position method</a>, also known as the Secant method.
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;cmath&gt;</code><br />
<code>#include &lt;iostream&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for false_position.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dc/de2/false__position_8cpp__incl.svg" width="178" height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:d1/de0/namespacenumerical__methods"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/de0/namespacenumerical__methods.html">numerical_methods</a></td></tr>
<tr class="memdesc:d1/de0/namespacenumerical__methods"><td class="mdescLeft">&#160;</td><td class="mdescRight">for assert <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:df/dea/namespacefalse__position"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/dea/namespacefalse__position.html">false_position</a></td></tr>
<tr class="memdesc:df/dea/namespacefalse__position"><td class="mdescLeft">&#160;</td><td class="mdescRight">Functions for <a href="https://en.wikipedia.org/wiki/Regula_falsi" target="_blank">False Position</a> method. <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a85a6ec58b5064d63d4f0df3854496713"><td class="memItemLeft" align="right" valign="top">static float&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d29/false__position_8cpp.html#a85a6ec58b5064d63d4f0df3854496713">numerical_methods::false_position::eq</a> (float x)</td></tr>
<tr class="memdesc:a85a6ec58b5064d63d4f0df3854496713"><td class="mdescLeft">&#160;</td><td class="mdescRight">This function gives the value of f(x) for given x. <a href="../../dd/d29/false__position_8cpp.html#a85a6ec58b5064d63d4f0df3854496713">More...</a><br /></td></tr>
<tr class="separator:a85a6ec58b5064d63d4f0df3854496713"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7d69b49dc37da1c02b3ab8c7fe783494"><td class="memItemLeft" align="right" valign="top">static float&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d29/false__position_8cpp.html#a7d69b49dc37da1c02b3ab8c7fe783494">numerical_methods::false_position::regula_falsi</a> (float x1, float x2, float y1, float y2)</td></tr>
<tr class="memdesc:a7d69b49dc37da1c02b3ab8c7fe783494"><td class="mdescLeft">&#160;</td><td class="mdescRight">This function finds root of the equation in given interval i.e. (x1,x2). <a href="../../dd/d29/false__position_8cpp.html#a7d69b49dc37da1c02b3ab8c7fe783494">More...</a><br /></td></tr>
<tr class="separator:a7d69b49dc37da1c02b3ab8c7fe783494"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a85cb7bfb90abc898e042d624372c5345"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d29/false__position_8cpp.html#a85cb7bfb90abc898e042d624372c5345">numerical_methods::false_position::printRoot</a> (float root, const int16_t &amp;count)</td></tr>
<tr class="memdesc:a85cb7bfb90abc898e042d624372c5345"><td class="mdescLeft">&#160;</td><td class="mdescRight">This function prints roots of the equation. <a href="../../dd/d29/false__position_8cpp.html#a85cb7bfb90abc898e042d624372c5345">More...</a><br /></td></tr>
<tr class="separator:a85cb7bfb90abc898e042d624372c5345"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d29/false__position_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <a href="../../dd/d29/false__position_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Solve the equation \(f(x)=0\) using <a href="https://en.wikipedia.org/wiki/Regula_falsi" target="_blank">false position method</a>, also known as the Secant method. </p>
<p >First, multiple intervals are selected with the interval gap provided. Separate recursive function called for every root. Roots are printed Separatelt.</p>
<p >For an interval [a,b] \(a\) and \(b\) such that \(f(a)&lt;0\) and \(f(b)&gt;0\), then the \((i+1)^\text{th}\) approximation is given by: </p><p class="formulaDsp">
\[ x_{i+1} = \frac{a_i\cdot f(b_i) - b_i\cdot f(a_i)}{f(b_i) - f(a_i)} \]
</p>
<p> For the next iteration, the interval is selected as: \([a,x]\) if \(x&gt;0\) or \([x,b]\) if \(x&lt;0\). The Process is continued till a close enough approximation is achieved.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="../../de/dd3/newton__raphson__method_8cpp.html" title="Solve the equation using Newton-Raphson method for both real and complex solutions.">newton_raphson_method.cpp</a>, <a class="el" href="../../d7/d6a/bisection__method_8cpp.html" title="Solve the equation using bisection method">bisection_method.cpp</a></dd></dl>
<dl class="section author"><dt>Author</dt><dd>Unknown author </dd>
<dd>
<a href="https://github.com/sampatil578" target="_blank">Samruddha Patil</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a85a6ec58b5064d63d4f0df3854496713" name="a85a6ec58b5064d63d4f0df3854496713"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a85a6ec58b5064d63d4f0df3854496713">&#9670;&nbsp;</a></span>eq()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static float numerical_methods::false_position::eq </td>
<td>(</td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>x</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>This function gives the value of f(x) for given x. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">x</td><td>value for which we have to find value of f(x). </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>value of f(x) for given x. </dd></dl>
<div class="fragment"><div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> {</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> <span class="keywordflow">return</span> (x * x - x); <span class="comment">// original equation</span></div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span>}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dd/d29/false__position_8cpp_a85a6ec58b5064d63d4f0df3854496713_cgraph.svg" width="154" height="76"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&nbsp;</a></span>main()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int main </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<div class="fragment"><div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> {</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> <span class="keywordtype">float</span> a = 0, b = 0, i = 0, root = 0;</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> int16_t count = 0;</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> <span class="keywordtype">float</span> range =</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> 100000; <span class="comment">// Range in which we have to find the root. (-range,range)</span></div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> <span class="keywordtype">float</span> gap = 0.5; <span class="comment">// interval gap. lesser the gap more the accuracy</span></div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> a = <a class="code hl_function" href="../../dd/d29/false__position_8cpp.html#a85a6ec58b5064d63d4f0df3854496713">numerical_methods::false_position::eq</a>((-1) * range);</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> i = ((-1) * range + gap);</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> <span class="comment">// while loop for selecting proper interval in provided range and with</span></div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> <span class="comment">// provided interval gap.</span></div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> <span class="keywordflow">while</span> (i &lt;= range) {</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> b = <a class="code hl_function" href="../../dd/d29/false__position_8cpp.html#a85a6ec58b5064d63d4f0df3854496713">numerical_methods::false_position::eq</a>(i);</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> <span class="keywordflow">if</span> (b == 0) {</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> count++;</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> <a class="code hl_function" href="../../dd/d29/false__position_8cpp.html#a85cb7bfb90abc898e042d624372c5345">numerical_methods::false_position::printRoot</a>(i, count);</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> }</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> <span class="keywordflow">if</span> (a * b &lt; 0) {</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> root = <a class="code hl_function" href="../../dd/d29/false__position_8cpp.html#a7d69b49dc37da1c02b3ab8c7fe783494">numerical_methods::false_position::regula_falsi</a>(i - gap, i,</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> a, b);</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> count++;</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> <a class="code hl_function" href="../../dd/d29/false__position_8cpp.html#a85cb7bfb90abc898e042d624372c5345">numerical_methods::false_position::printRoot</a>(root, count);</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span> }</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span> a = b;</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> i += gap;</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> }</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span>}</div>
<div class="ttc" id="afalse__position_8cpp_html_a7d69b49dc37da1c02b3ab8c7fe783494"><div class="ttname"><a href="../../dd/d29/false__position_8cpp.html#a7d69b49dc37da1c02b3ab8c7fe783494">numerical_methods::false_position::regula_falsi</a></div><div class="ttdeci">static float regula_falsi(float x1, float x2, float y1, float y2)</div><div class="ttdoc">This function finds root of the equation in given interval i.e. (x1,x2).</div><div class="ttdef"><b>Definition:</b> false_position.cpp:55</div></div>
<div class="ttc" id="afalse__position_8cpp_html_a85a6ec58b5064d63d4f0df3854496713"><div class="ttname"><a href="../../dd/d29/false__position_8cpp.html#a85a6ec58b5064d63d4f0df3854496713">numerical_methods::false_position::eq</a></div><div class="ttdeci">static float eq(float x)</div><div class="ttdoc">This function gives the value of f(x) for given x.</div><div class="ttdef"><b>Definition:</b> false_position.cpp:44</div></div>
<div class="ttc" id="afalse__position_8cpp_html_a85cb7bfb90abc898e042d624372c5345"><div class="ttname"><a href="../../dd/d29/false__position_8cpp.html#a85cb7bfb90abc898e042d624372c5345">numerical_methods::false_position::printRoot</a></div><div class="ttdeci">void printRoot(float root, const int16_t &amp;count)</div><div class="ttdoc">This function prints roots of the equation.</div><div class="ttdef"><b>Definition:</b> false_position.cpp:84</div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a85cb7bfb90abc898e042d624372c5345" name="a85cb7bfb90abc898e042d624372c5345"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a85cb7bfb90abc898e042d624372c5345">&#9670;&nbsp;</a></span>printRoot()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void numerical_methods::false_position::printRoot </td>
<td>(</td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>root</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const int16_t &amp;&#160;</td>
<td class="paramname"><em>count</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>This function prints roots of the equation. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">root</td><td>which we have to print. </td></tr>
<tr><td class="paramname">count</td><td>which is count of the root in an interval [-range,range]. </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> {</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="keywordflow">if</span> (count == 1) {</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Your 1st root is : &quot;</span> &lt;&lt; root &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (count == 2) {</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Your 2nd root is : &quot;</span> &lt;&lt; root &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (count == 3) {</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Your 3rd root is : &quot;</span> &lt;&lt; root &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;Your &quot;</span> &lt;&lt; count &lt;&lt; <span class="stringliteral">&quot;th root is : &quot;</span> &lt;&lt; root &lt;&lt; <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> }</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span>}</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="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dd/d29/false__position_8cpp_a85cb7bfb90abc898e042d624372c5345_cgraph.svg" width="174" height="76"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
<a id="a7d69b49dc37da1c02b3ab8c7fe783494" name="a7d69b49dc37da1c02b3ab8c7fe783494"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7d69b49dc37da1c02b3ab8c7fe783494">&#9670;&nbsp;</a></span>regula_falsi()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">static float numerical_methods::false_position::regula_falsi </td>
<td>(</td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>x1</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>x2</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>y1</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">float&#160;</td>
<td class="paramname"><em>y2</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">static</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>This function finds root of the equation in given interval i.e. (x1,x2). </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">x1,x2</td><td>values for an interval in which root is present. </td></tr>
<tr><td class="paramname">y1,y2</td><td>values of function at x1, x2 espectively. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>root of the equation in the given interval. </dd></dl>
<div class="fragment"><div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> {</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> <span class="keywordtype">float</span> diff = x1 - x2;</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> <span class="keywordflow">if</span> (diff &lt; 0) {</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> diff = (-1) * diff;</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> }</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="keywordflow">if</span> (diff &lt; 0.00001) {</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <span class="keywordflow">if</span> (y1 &lt; 0) {</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> y1 = -y1;</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> }</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <span class="keywordflow">if</span> (y2 &lt; 0) {</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> y2 = -y2;</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> }</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> <span class="keywordflow">if</span> (y1 &lt; y2) {</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> <span class="keywordflow">return</span> x1;</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> } <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> <span class="keywordflow">return</span> x2;</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> }</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> }</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> <span class="keywordtype">float</span> x3 = 0, y3 = 0;</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> x3 = x1 - (x1 - x2) * (y1) / (y1 - y2);</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> y3 = <a class="code hl_function" href="../../dd/d29/false__position_8cpp.html#a85a6ec58b5064d63d4f0df3854496713">eq</a>(x3);</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> <span class="keywordflow">return</span> <a class="code hl_function" href="../../dd/d29/false__position_8cpp.html#a7d69b49dc37da1c02b3ab8c7fe783494">regula_falsi</a>(x2, x3, y2, y3);</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span>}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../dd/d29/false__position_8cpp_a7d69b49dc37da1c02b3ab8c7fe783494_cgraph.svg" width="378" height="76"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_9c6faab82c22511b50177aa2e38e2780.html">numerical_methods</a></li><li class="navelem"><a class="el" href="../../dd/d29/false__position_8cpp.html">false_position.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.2 </li>
</ul>
</div>
</body>
</html>