Files
C-Plus-Plus/d6/db0/binomial__dist_8cpp.html
2021-10-13 21:29:54 +00:00

468 lines
31 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++: probability/binomial_dist.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('d6/db0/binomial__dist_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="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">binomial_dist.cpp File Reference</div></div>
</div><!--header-->
<div class="contents">
<p><a href="https://en.wikipedia.org/wiki/Binomial_distribution" target="_blank">Binomial distribution</a> example
<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 binomial_dist.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d3/d56/binomial__dist_8cpp__incl.svg" width="168" 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="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a4416a7bc7fa87201883c54cdc4c82813"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/db0/binomial__dist_8cpp.html#a4416a7bc7fa87201883c54cdc4c82813">binomial_expected</a> (double n, double p)</td></tr>
<tr class="separator:a4416a7bc7fa87201883c54cdc4c82813"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:acd4dd4558031e4c5d045c801f73d8861"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/db0/binomial__dist_8cpp.html#acd4dd4558031e4c5d045c801f73d8861">binomial_variance</a> (double n, double p)</td></tr>
<tr class="separator:acd4dd4558031e4c5d045c801f73d8861"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af09e51f513cee647d41192ab0a872cdc"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/db0/binomial__dist_8cpp.html#af09e51f513cee647d41192ab0a872cdc">binomial_standard_deviation</a> (double n, double p)</td></tr>
<tr class="separator:af09e51f513cee647d41192ab0a872cdc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a78d36635232e54b5d71fcbf1eac9a49a"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/db0/binomial__dist_8cpp.html#a78d36635232e54b5d71fcbf1eac9a49a">nCr</a> (double n, double r)</td></tr>
<tr class="separator:a78d36635232e54b5d71fcbf1eac9a49a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a19ae0a6a2bd200fd1eb0e31b2bf4cc76"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/db0/binomial__dist_8cpp.html#a19ae0a6a2bd200fd1eb0e31b2bf4cc76">binomial_x_successes</a> (double n, double p, double x)</td></tr>
<tr class="separator:a19ae0a6a2bd200fd1eb0e31b2bf4cc76"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a76ed6ce71415fb400b65f0656cef3d25"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/db0/binomial__dist_8cpp.html#a76ed6ce71415fb400b65f0656cef3d25">binomial_range_successes</a> (double n, double p, double lower_bound, double upper_bound)</td></tr>
<tr class="separator:a76ed6ce71415fb400b65f0656cef3d25"><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="../../d6/db0/binomial__dist_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</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 ><a href="https://en.wikipedia.org/wiki/Binomial_distribution" target="_blank">Binomial distribution</a> example </p>
<p >The binomial distribution models the number of successes in a sequence of n independent events</p>
<p >Summary of variables used:</p><ul>
<li>n : number of trials</li>
<li>p : probability of success</li>
<li>x : desired successes </li>
</ul>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a4416a7bc7fa87201883c54cdc4c82813" name="a4416a7bc7fa87201883c54cdc4c82813"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4416a7bc7fa87201883c54cdc4c82813">&#9670;&nbsp;</a></span>binomial_expected()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double binomial_expected </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>p</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p >finds the expected value of a binomial distribution </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">n</td><td></td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">p</td><td></td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>\(\mu=np\) </dd></dl>
<div class="fragment"><div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span>{ <span class="keywordflow">return</span> n * p; }</div>
</div><!-- fragment -->
</div>
</div>
<a id="a76ed6ce71415fb400b65f0656cef3d25" name="a76ed6ce71415fb400b65f0656cef3d25"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a76ed6ce71415fb400b65f0656cef3d25">&#9670;&nbsp;</a></span>binomial_range_successes()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double binomial_range_successes </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>p</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>lower_bound</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>upper_bound</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p >calculates the probability of a result within a range (inclusive, inclusive) </p><dl class="section return"><dt>Returns</dt><dd>\(\displaystyle \left.P(n,p)\right|_{x_0}^{x_1} = \sum_{i=x_0}^{x_1} P(i) =\sum_{i=x_0}^{x_1} {n\choose i} p^i (1-p)^{n-i}\) </dd></dl>
<div class="fragment"><div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> {</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> <span class="keywordtype">double</span> <a class="code hl_namespace" href="../../d4/ded/namespaceprobability.html">probability</a> = 0;</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = lower_bound; i &lt;= <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/upper_bound.html">upper_bound</a>; i++) {</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <a class="code hl_namespace" href="../../d4/ded/namespaceprobability.html">probability</a> += <a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#a78d36635232e54b5d71fcbf1eac9a49a">nCr</a>(n, i) * <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/pow.html">std::pow</a>(p, i) * <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/pow.html">std::pow</a>(1 - p, n - i);</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> }</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <span class="keywordflow">return</span> <a class="code hl_namespace" href="../../d4/ded/namespaceprobability.html">probability</a>;</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span>}</div>
<div class="ttc" id="abinomial__dist_8cpp_html_a78d36635232e54b5d71fcbf1eac9a49a"><div class="ttname"><a href="../../d6/db0/binomial__dist_8cpp.html#a78d36635232e54b5d71fcbf1eac9a49a">nCr</a></div><div class="ttdeci">double nCr(double n, double r)</div><div class="ttdef"><b>Definition:</b> binomial_dist.cpp:47</div></div>
<div class="ttc" id="anamespaceprobability_html"><div class="ttname"><a href="../../d4/ded/namespaceprobability.html">probability</a></div><div class="ttdoc">Probability algorithms.</div></div>
<div class="ttc" id="apow_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/pow.html">std::pow</a></div><div class="ttdeci">T pow(T... args)</div></div>
<div class="ttc" id="aupper_bound_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/upper_bound.html">std::upper_bound</a></div><div class="ttdeci">T upper_bound(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="../../d6/db0/binomial__dist_8cpp_a76ed6ce71415fb400b65f0656cef3d25_cgraph.svg" width="314" height="88"><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="af09e51f513cee647d41192ab0a872cdc" name="af09e51f513cee647d41192ab0a872cdc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af09e51f513cee647d41192ab0a872cdc">&#9670;&nbsp;</a></span>binomial_standard_deviation()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double binomial_standard_deviation </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>p</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p >finds the standard deviation of the binomial distribution </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">n</td><td></td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">p</td><td></td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>\(\sigma = \sqrt{\sigma^2} = \sqrt{n\cdot p\cdot (1-p)}\) </dd></dl>
<div class="fragment"><div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> {</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> <span class="keywordflow">return</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">std::sqrt</a>(<a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#acd4dd4558031e4c5d045c801f73d8861">binomial_variance</a>(n, p));</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span>}</div>
<div class="ttc" id="abinomial__dist_8cpp_html_acd4dd4558031e4c5d045c801f73d8861"><div class="ttname"><a href="../../d6/db0/binomial__dist_8cpp.html#acd4dd4558031e4c5d045c801f73d8861">binomial_variance</a></div><div class="ttdeci">double binomial_variance(double n, double p)</div><div class="ttdef"><b>Definition:</b> binomial_dist.cpp:29</div></div>
<div class="ttc" id="asqrt_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">std::sqrt</a></div><div class="ttdeci">T sqrt(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="../../d6/db0/binomial__dist_8cpp_af09e51f513cee647d41192ab0a872cdc_cgraph.svg" width="380" height="88"><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="acd4dd4558031e4c5d045c801f73d8861" name="acd4dd4558031e4c5d045c801f73d8861"></a>
<h2 class="memtitle"><span class="permalink"><a href="#acd4dd4558031e4c5d045c801f73d8861">&#9670;&nbsp;</a></span>binomial_variance()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double binomial_variance </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>p</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p >finds the variance of the binomial distribution </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">n</td><td></td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">p</td><td></td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>\(\sigma^2 = n\cdot p\cdot (1-p)\) </dd></dl>
<div class="fragment"><div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span>{ <span class="keywordflow">return</span> n * p * (1 - p); }</div>
</div><!-- fragment -->
</div>
</div>
<a id="a19ae0a6a2bd200fd1eb0e31b2bf4cc76" name="a19ae0a6a2bd200fd1eb0e31b2bf4cc76"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a19ae0a6a2bd200fd1eb0e31b2bf4cc76">&#9670;&nbsp;</a></span>binomial_x_successes()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double binomial_x_successes </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>p</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>x</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p >calculates the probability of exactly x successes </p><dl class="section return"><dt>Returns</dt><dd>\(\displaystyle P(n,p,x) = {n\choose x} p^x (1-p)^{n-x}\) </dd></dl>
<div class="fragment"><div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> {</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <span class="keywordflow">return</span> <a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#a78d36635232e54b5d71fcbf1eac9a49a">nCr</a>(n, x) * <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/pow.html">std::pow</a>(p, x) * <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/pow.html">std::pow</a>(1 - p, n - x);</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</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="../../d6/db0/binomial__dist_8cpp_a19ae0a6a2bd200fd1eb0e31b2bf4cc76_cgraph.svg" width="287" height="88"><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>
<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> <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;expected value : &quot;</span> &lt;&lt; <a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#a4416a7bc7fa87201883c54cdc4c82813">binomial_expected</a>(100, 0.5)</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> &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> </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;variance : &quot;</span> &lt;&lt; <a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#acd4dd4558031e4c5d045c801f73d8861">binomial_variance</a>(100, 0.5) &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> </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;standard deviation : &quot;</span></div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> &lt;&lt; <a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#af09e51f513cee647d41192ab0a872cdc">binomial_standard_deviation</a>(100, 0.5) &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="l00092" name="l00092"></a><span class="lineno"> 92</span> </div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</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;exactly 30 successes : &quot;</span> &lt;&lt; <a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#a19ae0a6a2bd200fd1eb0e31b2bf4cc76">binomial_x_successes</a>(100, 0.5, 30)</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> &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="l00095" name="l00095"></a><span class="lineno"> 95</span> </div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</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;45 or more successes : &quot;</span></div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> &lt;&lt; <a class="code hl_function" href="../../d6/db0/binomial__dist_8cpp.html#a76ed6ce71415fb400b65f0656cef3d25">binomial_range_successes</a>(100, 0.5, 45, 100) &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="l00098" name="l00098"></a><span class="lineno"> 98</span> </div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</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="abinomial__dist_8cpp_html_a19ae0a6a2bd200fd1eb0e31b2bf4cc76"><div class="ttname"><a href="../../d6/db0/binomial__dist_8cpp.html#a19ae0a6a2bd200fd1eb0e31b2bf4cc76">binomial_x_successes</a></div><div class="ttdeci">double binomial_x_successes(double n, double p, double x)</div><div class="ttdef"><b>Definition:</b> binomial_dist.cpp:65</div></div>
<div class="ttc" id="abinomial__dist_8cpp_html_a4416a7bc7fa87201883c54cdc4c82813"><div class="ttname"><a href="../../d6/db0/binomial__dist_8cpp.html#a4416a7bc7fa87201883c54cdc4c82813">binomial_expected</a></div><div class="ttdeci">double binomial_expected(double n, double p)</div><div class="ttdef"><b>Definition:</b> binomial_dist.cpp:22</div></div>
<div class="ttc" id="abinomial__dist_8cpp_html_a76ed6ce71415fb400b65f0656cef3d25"><div class="ttname"><a href="../../d6/db0/binomial__dist_8cpp.html#a76ed6ce71415fb400b65f0656cef3d25">binomial_range_successes</a></div><div class="ttdeci">double binomial_range_successes(double n, double p, double lower_bound, double upper_bound)</div><div class="ttdef"><b>Definition:</b> binomial_dist.cpp:74</div></div>
<div class="ttc" id="abinomial__dist_8cpp_html_af09e51f513cee647d41192ab0a872cdc"><div class="ttname"><a href="../../d6/db0/binomial__dist_8cpp.html#af09e51f513cee647d41192ab0a872cdc">binomial_standard_deviation</a></div><div class="ttdeci">double binomial_standard_deviation(double n, double p)</div><div class="ttdef"><b>Definition:</b> binomial_dist.cpp:36</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="../../d6/db0/binomial__dist_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="479" height="291"><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="a78d36635232e54b5d71fcbf1eac9a49a" name="a78d36635232e54b5d71fcbf1eac9a49a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a78d36635232e54b5d71fcbf1eac9a49a">&#9670;&nbsp;</a></span>nCr()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">double nCr </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>r</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p >Computes n choose r </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">n</td><td></td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">r</td><td></td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>\(\displaystyle {n\choose r} = \frac{n!}{r!(n-r)!} = \frac{n\times(n-1)\times(n-2)\times\cdots(n-r)}{r!} \) </dd></dl>
<div class="fragment"><div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> {</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> <span class="keywordtype">double</span> numerator = n;</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> <span class="keywordtype">double</span> denominator = r;</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> </div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = n - 1; i &gt;= ((n - r) + 1); i--) {</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> numerator *= i;</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> }</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> </div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i &lt; r; i++) {</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> denominator *= i;</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> }</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> </div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <span class="keywordflow">return</span> numerator / denominator;</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span>}</div>
</div><!-- fragment -->
</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_82e494173a87936756866de2fa774307.html">probability</a></li><li class="navelem"><a class="el" href="../../d6/db0/binomial__dist_8cpp.html">binomial_dist.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>