2017年4月30日日曜日

学習環境

数学読本〈4〉数列の極限,順列/順列・組合せ/確率/関数の極限と微分法(松坂 和夫(著)、岩波書店)の第16章(確からしさをみる - 確率)、16.2(条件つき確率と確率の乗法定理)、独立事象と従属事象、問29、30、31.を取り組んでみる。


  1. P A ( B )= 2 3 P A ( B )P( B ) P A ( C )= 1 3 P A ( C )=P( C )

    1. P( A )= 13 52 = 1 4 P( B )= 3·4 52 = 3 13 P( A )·P( B )= 3 52 P( AB )= 3 52 = 3 52

    2. P( A )= 3 6 = 1 2 P( B )= 2 6 = 1 3 P( A )·P( B )= 1 6 P( AB )= 1 6

    3. P( A )= 1 2 P( B )= 1 2 P( A )·P( B )= 1 4 P( AB )= 1 4

    4. P( A )= 13·39 52·51 = 13 4·17 = 13 68 P( B )= 13·12 52·51 + 39·13 52·51 = 4+13 4·17 = 1 4 P( AB )= 13·13 52·51 = 13 4·51 = 13 204 P( A )P( B )= 13 272 P( AB )P( A )P( B )

  2. P( A )=p P( A )=1p P( B )=q P( AB )=pq P( A )P( B )=( 1p )q P( A B ) =P( B )P( AB ) =qpq =( 1p )q P( A B )=P( A )P( B )

コード(Emacs)

HTML5

<div id="graph0"></div>
<pre id="output0"></pre>
ÂõûÊï∞: <input id="n0" type="number" min="1" step="1" value="1000">
<br>
<button id="run0">run</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="sample29.js"></script>    

JavaScript

let pre0 = document.querySelector('#output0'),
    input_n = document.querySelector('#n0'),
    btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    div0 = document.querySelector('#graph0'),
    width = 600,
    height = 600,
    padding = 50,
    p = (x) => pre0.textContent += x + '\n';

let range = (n) => {
    let result = [];
    for (let i = 0; i < n; i += 1) {
        result.push(i);
    }
    return result;
};

let suit = range(13).map(() => 0)
    .concat(range(13).map(() => 1))
    .concat(range(13).map(() => 2))
    .concat(range(13).map(() => 3)),
    spade = 0,
    club = 1,
    dia = 2,
    heart = 3;

let f = () => {
    let suit0 = suit.slice(),
        i = Math.floor(Math.random() * suit0.length),
        card1 = suit[i];

    suit0.splice(i, 1);
    i = Math.floor(Math.random() * suit0.length);
    let card2 = suit[i];

    return card1 === heart && card2 === spade;
};
let output = () => {
    p('30-4.');
    let n = parseInt(input_n.value, 10),
        results = range(n).map(() => f()),
        points = [];

    points = range(n).map((i) => {
        return [i + 1,
                range(i + 1)
                .map(() => f())
                .filter((b) => b)
                .length / (i + 1)]
    });
    
    let t = points[points.length - 1][1],
        result = 13 / 204;
    p(t ===  result);
    p(t);
    p(result);
    p(Math.abs(t - result));

    let xscale = d3.scaleLinear()
        .domain([1, n])
        .range([padding, width - padding]);
    let yscale = d3.scaleLinear()
        .domain([0, 1])
        .range([height - padding, padding]);

    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);

    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', 'green');

    svg.append('g')
        .attr('transform', `translate(0, ${height - padding})`)
        .call(xaxis);

    svg.append('g')
        .attr('transform', `translate(${padding}, 0)`)
        .call(yaxis);
};

input_n.onchange = output;
btn0.onclick = output;
btn1.onclick = () => pre0.textContent = '';

output();

回数: 

0 コメント:

コメントを投稿

Comments on Google+: