mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-23 05:12:40 +08:00
Documentation for c26eea874d
This commit is contained in:
@@ -4,7 +4,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.12.0"/>
|
||||
<meta name="generator" content="Doxygen 1.13.2"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>TheAlgorithms/C++: numerical_methods/newton_raphson_method.cpp File Reference</title>
|
||||
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
||||
@@ -60,7 +60,7 @@ window.MathJax = {
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.12.0 -->
|
||||
<!-- Generated by Doxygen 1.13.2 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
||||
@@ -164,8 +164,7 @@ Variables</h2></td></tr>
|
||||
<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/Newton%27s_method" target="_blank">Newton-Raphson method</a> for both real and complex solutions. </p>
|
||||
<p>The \((i+1)^\text{th}\) approximation is given by: </p><p class="formulaDsp">
|
||||
\[
|
||||
x_{i+1} = x_i - \frac{f(x_i)}{f'(x_i)}
|
||||
\[x_{i+1} = x_i - \frac{f(x_i)}{f'(x_i)}
|
||||
\]
|
||||
</p>
|
||||
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kvedala" target="_blank">Krishna Vedala</a> </dd></dl>
|
||||
@@ -191,13 +190,12 @@ x_{i+1} = x_i - \frac{f(x_i)}{f'(x_i)}
|
||||
</table>
|
||||
</td>
|
||||
<td class="mlabels-right">
|
||||
<span class="mlabels"><span class="mlabel">static</span></span> </td>
|
||||
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>define \(f(x)\) to find root for. Currently defined as: </p><p class="formulaDsp">
|
||||
\[
|
||||
f(x) = x^3 - 4x - 9
|
||||
\[f(x) = x^3 - 4x - 9
|
||||
\]
|
||||
</p>
|
||||
|
||||
@@ -226,13 +224,12 @@ f(x) = x^3 - 4x - 9
|
||||
</table>
|
||||
</td>
|
||||
<td class="mlabels-right">
|
||||
<span class="mlabels"><span class="mlabel">static</span></span> </td>
|
||||
<span class="mlabels"><span class="mlabel static">static</span></span> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
<p>define the derivative function \(f'(x)\) For the current problem, it is: </p><p class="formulaDsp">
|
||||
\[
|
||||
f'(x) = 3x^2 - 4
|
||||
\[f'(x) = 3x^2 - 4
|
||||
\]
|
||||
</p>
|
||||
|
||||
@@ -269,14 +266,14 @@ f'(x) = 3x^2 - 4
|
||||
<div class="line"><span class="lineno"> 51</span> std::cout << <span class="stringliteral">"\nInitial approximation: "</span> << c;</div>
|
||||
<div class="line"><span class="lineno"> 52</span> </div>
|
||||
<div class="line"><span class="lineno"> 53</span> <span class="comment">// start iterations</span></div>
|
||||
<div class="line"><span class="lineno"> 54</span> <span class="keywordflow">for</span> (i = 0; i < <a class="code hl_variable" href="#a5c5ff05b9f37ae59dad67e1d4f6cd51d">MAX_ITERATIONS</a>; i++) {</div>
|
||||
<div class="line"><span class="lineno"> 54</span> <span class="keywordflow">for</span> (i = 0; i < <a class="code hl_define" href="../../d7/d6a/bisection__method_8cpp.html#a0a3abbca80bc98e7abcb3ae73abe0f14">MAX_ITERATIONS</a>; i++) {</div>
|
||||
<div class="line"><span class="lineno"> 55</span> m = <a class="code hl_function" href="#a2003b5b2dcfff0769b957ab5c968b03d">eq</a>(c);</div>
|
||||
<div class="line"><span class="lineno"> 56</span> n = <a class="code hl_function" href="#a3d3f7f41977394680af6ebbed96f3386">eq_der</a>(c);</div>
|
||||
<div class="line"><span class="lineno"> 57</span> </div>
|
||||
<div class="line"><span class="lineno"> 58</span> z = c - (m / n);</div>
|
||||
<div class="line"><span class="lineno"> 59</span> c = z;</div>
|
||||
<div class="line"><span class="lineno"> 60</span> </div>
|
||||
<div class="line"><span class="lineno"> 61</span> <span class="keywordflow">if</span> (std::abs(m) < <a class="code hl_variable" href="#a75f355966e0a97665eaf5a4c79baa7af">EPSILON</a>) { <span class="comment">// stoping criteria</span></div>
|
||||
<div class="line"><span class="lineno"> 61</span> <span class="keywordflow">if</span> (std::abs(m) < EPSILON) { <span class="comment">// stoping criteria</span></div>
|
||||
<div class="line"><span class="lineno"> 62</span> <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><span class="lineno"> 63</span> }</div>
|
||||
<div class="line"><span class="lineno"> 64</span> }</div>
|
||||
@@ -284,10 +281,9 @@ f'(x) = 3x^2 - 4
|
||||
<div class="line"><span class="lineno"> 66</span> std::cout << <span class="stringliteral">"\n\nRoot: "</span> << z << <span class="stringliteral">"\t\tSteps: "</span> << i << std::endl;</div>
|
||||
<div class="line"><span class="lineno"> 67</span> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><span class="lineno"> 68</span>}</div>
|
||||
<div class="ttc" id="abisection__method_8cpp_html_a0a3abbca80bc98e7abcb3ae73abe0f14"><div class="ttname"><a href="../../d7/d6a/bisection__method_8cpp.html#a0a3abbca80bc98e7abcb3ae73abe0f14">MAX_ITERATIONS</a></div><div class="ttdeci">#define MAX_ITERATIONS</div><div class="ttdoc">Maximum number of iterations to check.</div><div class="ttdef"><b>Definition</b> <a href="../../d7/d6a/bisection__method_8cpp_source.html#l00022">bisection_method.cpp:22</a></div></div>
|
||||
<div class="ttc" id="anewton__raphson__method_8cpp_html_a2003b5b2dcfff0769b957ab5c968b03d"><div class="ttname"><a href="#a2003b5b2dcfff0769b957ab5c968b03d">eq</a></div><div class="ttdeci">static double eq(double i)</div><div class="ttdef"><b>Definition</b> <a href="../../de/dd3/newton__raphson__method_8cpp_source.html#l00030">newton_raphson_method.cpp:30</a></div></div>
|
||||
<div class="ttc" id="anewton__raphson__method_8cpp_html_a3d3f7f41977394680af6ebbed96f3386"><div class="ttname"><a href="#a3d3f7f41977394680af6ebbed96f3386">eq_der</a></div><div class="ttdeci">static double eq_der(double i)</div><div class="ttdef"><b>Definition</b> <a href="../../de/dd3/newton__raphson__method_8cpp_source.html#l00040">newton_raphson_method.cpp:40</a></div></div>
|
||||
<div class="ttc" id="anewton__raphson__method_8cpp_html_a5c5ff05b9f37ae59dad67e1d4f6cd51d"><div class="ttname"><a href="#a5c5ff05b9f37ae59dad67e1d4f6cd51d">MAX_ITERATIONS</a></div><div class="ttdeci">constexpr int16_t MAX_ITERATIONS</div><div class="ttdoc">Maximum number of iterations.</div><div class="ttdef"><b>Definition</b> <a href="../../de/dd3/newton__raphson__method_8cpp_source.html#l00022">newton_raphson_method.cpp:22</a></div></div>
|
||||
<div class="ttc" id="anewton__raphson__method_8cpp_html_a75f355966e0a97665eaf5a4c79baa7af"><div class="ttname"><a href="#a75f355966e0a97665eaf5a4c79baa7af">EPSILON</a></div><div class="ttdeci">constexpr double EPSILON</div><div class="ttdoc">system accuracy limit</div><div class="ttdef"><b>Definition</b> <a href="../../de/dd3/newton__raphson__method_8cpp_source.html#l00021">newton_raphson_method.cpp:21</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
@@ -307,7 +303,7 @@ f'(x) = 3x^2 - 4
|
||||
</table>
|
||||
</td>
|
||||
<td class="mlabels-right">
|
||||
<span class="mlabels"><span class="mlabel">constexpr</span></span> </td>
|
||||
<span class="mlabels"><span class="mlabel constexpr">constexpr</span></span> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
@@ -333,7 +329,7 @@ f'(x) = 3x^2 - 4
|
||||
</table>
|
||||
</td>
|
||||
<td class="mlabels-right">
|
||||
<span class="mlabels"><span class="mlabel">constexpr</span></span> </td>
|
||||
<span class="mlabels"><span class="mlabel constexpr">constexpr</span></span> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
@@ -350,7 +346,7 @@ f'(x) = 3x^2 - 4
|
||||
<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="../../de/dd3/newton__raphson__method_8cpp.html">newton_raphson_method.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.12.0 </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.13.2 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user