2017年4月17日月曜日

学習環境

数学読本〈4〉数列の極限,順列/順列・組合せ/確率/関数の極限と微分法(松坂 和夫(著)、岩波書店)の第15章(「場合の数」 を数える - 順列・組合せ)、15.3(二項定理)、二項定理の応用、二項係数の性質、問40、41、42.を取り組んでみる。


    1. r· n! ( nr )!r! = n! ( nr )!( r1 )! n· ( n1 )! ( n1r+1 )!( r1 )! = n! ( nr )!( r1 )!

    2. i=1 n i( n i ) = i=1 n i n! ( ni )!i! =n i=1 n ( n1 )! ( ni )!( i1 )! =n i=0 n1 ( n1 )! ( n( i1 ) )!i! =n i=0 n1 ( n1 )! ( ( n1 )i )!i! =n i=0 n1 ( n i ) =n ( 1+1 ) n1 =n· 2 n1

  1. ( m+n r ) x r = i=0 r ( m i )( n ri )

  2. ( n r+1 ) ( n r ) = n! ( nr1 )!( r+1 )! · ( nr )!r! n! = nr r+1 nr r+1 =1 nr=r+1 r= n1 2 r< n1 2 ( n r )<( n r+1 ) r> n1 2 ( n r )>( n r+1 )

コード(Emacs)

HTML5

<button id="run0">run</button>
<button id="clear0">clear</button>
<pre id="output0"></pre>
<script src="sample40.js"></script>

JavaScript

let btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    pre0 = document.querySelector('#output0'),
    p = (x) => pre0.textContent += x + '\n';

let range = (start, end, step=1) => {
    let iter = (i, result) => {
        return i >= end ? result : iter(i + step, result.concat([i]));
    }
    return iter(start, []);
};
let factorial = (n) => {
    return n <= 1 ? 1 : n * factorial(n - 1);
};

let combination = (n, r) => {
    return factorial(n) / (factorial(r) * factorial(n - r));
};

let term = (n, i) => i * combination(n, i),
    f = (n) => range(1, n + 1).map((i) => term(n, i)).reduce((x, y) => x + y);


let output = () => {        
    p('40-1.');
    let r = Math.floor(Math.random() * 100) + 1,
        n = r + Math.floor(Math.random()) + 1;
    
    p(`${r * combination(n, r)} === ${n * combination(n - 1, r - 1)}: ` +
      `${r * combination(n, r) === n * combination(n - 1, r - 1)}`);

    p('40-2.');
    n = Math.floor(Math.random() * 100);
    p(`${n * Math.pow(2, n - 1)} === ${f(n)}: ` +
      `${n * Math.pow(2, n - 1) === f(n)}`);

    p('42.');
    n = Math.floor(Math.random() * 100) + 2;
    p(range(0, n + 1).map((i) => Math.floor(combination(n, i))));
};

btn0.onclick = output;
btn1.onclick = () => {
    pre0.textContent = '';
};

output();














						

0 コメント:

コメントを投稿

Comments on Google+: