## 2017年4月24日月曜日

### 数学 - JavaScript - 確からしさをみる - 確率 – 確率とその基本性質 - 確率の計算(極限)

1. $1-\frac{1}{{2}^{5}}=\frac{31}{32}$

1. $\frac{\left(\begin{array}{c}5\\ 2\end{array}\right)}{\left(\begin{array}{c}20\\ 2\end{array}\right)}=\frac{10}{190}=\frac{1}{19}$

2. $1-\frac{\left(\begin{array}{c}15\\ 2\end{array}\right)}{\left(\begin{array}{c}20\\ 2\end{array}\right)}=1-\frac{105}{190}=1-\frac{21}{38}=\frac{17}{38}$

3. $1-\frac{\left(\begin{array}{c}15\\ 3\end{array}\right)}{\left(\begin{array}{c}20\\ 3\end{array}\right)}=1-\frac{15·14·13}{20·19·18}=1-\frac{7·13}{4·19·3}=1-\frac{91}{228}=\frac{137}{228}$

4. $1-\frac{\left(\begin{array}{c}15\\ 3\end{array}\right)+\left(\begin{array}{c}5\\ 3\end{array}\right)}{\left(\begin{array}{c}20\\ 3\end{array}\right)}=1-\frac{15·14·13+5·4·3}{20·19·18}=1-\frac{14·13+4}{4·19·6}=1-\frac{93}{12·19}=\frac{135}{228}=\frac{45}{76}$

1. $1-\frac{{4}^{3}}{{6}^{3}}=1-\frac{{2}^{3}}{{3}^{3}}=1-\frac{8}{27}=\frac{19}{27}$

2. $1-\frac{{2}^{3}}{{6}^{3}}=1-\frac{1}{27}=\frac{26}{27}$

3. $\left(1-\frac{{4}^{3}}{{6}^{3}}\right)+\left(1-\frac{{4}^{3}}{{6}^{3}}\right)-\left(1-\frac{{2}^{3}}{{6}^{3}}\right)=\frac{12}{27}=\frac{4}{9}$

1. $\frac{\left(\begin{array}{c}3\\ 2\end{array}\right)+\left(\begin{array}{c}4\\ 2\end{array}\right)+\left(\begin{array}{c}5\\ 2\end{array}\right)}{\left(\begin{array}{c}12\\ 2\end{array}\right)}=\frac{3·2+4·3+5·4}{12·11}=\frac{38}{132}=\frac{19}{66}$

2. $1-\frac{\left(\begin{array}{c}7\\ 2\end{array}\right)}{\left(\begin{array}{c}12\\ 2\end{array}\right)}=1-\frac{7·6}{12·11}=1-\frac{7}{22}=\frac{15}{22}$

1. $\begin{array}{l}{p}_{n}=\frac{\left(\begin{array}{c}n\\ 2\end{array}\right)+\left(\begin{array}{c}n\\ 2\end{array}\right)}{\left(\begin{array}{c}2n\\ 2\end{array}\right)}=\frac{2n\left(n-1\right)}{2n\left(2n-1\right)}=\frac{n-1}{2n-1}\\ {q}_{n}=1-\frac{n-1}{2n-1}=\frac{2n-1-n+1}{2n-1}=\frac{n}{2n-1}\end{array}$

2. ${p}_{n}<{q}_{n}$

3. $\begin{array}{l}\underset{n\to \infty }{\mathrm{lim}}{p}_{n}=\underset{n\to \infty }{\mathrm{lim}}\frac{n-1}{2n-1}=\frac{1}{2}\\ \underset{n\to \infty }{\mathrm{lim}}{q}_{n}=\underset{n\to \infty }{\mathrm{lim}}\frac{n}{2n-1}=\frac{1}{2}\end{array}$

コード(Emacs)

HTML5

<div id="graph0"></div>
<pre id="output0"></pre>
n = <input id="n0" type="number" min="2" step="1" value="100">
<br>
<button id="draw0">draw</button>
<button id="clear0">clear</button>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.6/d3.min.js" integrity="sha256-5idA201uSwHAROtCops7codXJ0vja+6wbBrZdQ6ETQc=" crossorigin="anonymous"></script>
<script src="sample6.js"></script>


JavaScript

let div0 = document.querySelector('#graph0'),
input0 = document.querySelector('#n0'),
pre0 = document.querySelector('#output0'),
width = 600,
height = 600,
btn0 = document.querySelector('#draw0'),
btn1 = document.querySelector('#clear0'),
p = (x) => pre0.textContent += x + '\n',
pn = (n) => (n - 1) / (2 * n - 1),
qn = (n) => n / (2 * n - 1);

let draw = () => {
let points = [],
n = parseInt(input0.value, 10);

for (let i = 2; i <= n; i += 1) {
points.push([i, pn(i)]);
}
for (let i = 2; i <= n; i += 1) {
points.push([i, qn(i)]);
}
let xscale = d3.scaleLinear()
.domain([2, n])
let ys = points.map((a) => a[1]);
let yscale = d3.scaleLinear()
.domain([Math.min(...ys), Math.max(...ys)])

let xaxis = d3.axisBottom().scale(xscale);
let yaxis = d3.axisLeft().scale(yscale);
div0.innerHTML = '';
let svg = d3.select('#graph0')
.append('svg')
.attr('width', width)
.attr('height', height);

let t = points.length / 2;
svg.selectAll('circle')
.data(points)
.enter()
.append('circle')
.attr('cx', (d) => xscale(d[0]))
.attr('cy', (d) => yscale(d[1]))
.attr('r', 1)
.attr('fill', (d, i) => i < t ? 'green' : 'blue');

svg.append('g')
.attr('transform', translate(0, ${height - padding})) .call(xaxis); svg.append('g') .attr('transform', translate(${padding}, 0))
.call(yaxis);
p('n, pn, qn, difference');
for (let i = 2; i <= n; i += 1) {
let a = pn(i),
b = qn(i);
p(${i},${a}, ${b},${b - a});
}
}

input0.onchange = draw;
btn0.onclick = draw;
btn1.onclick = () => pre0.textContent = '';

draw();


n =