Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

2017年4月15日土曜日

学習環境

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


    1. 4a4+4a32b+6a2(2b)2+4a(2b)3+(2b)4=4a4+8a3b+24a2b2+32ab3+16b4

    2. x5+5x4(y)+10x3(y)2+10x2(y)3+5x(y)4+(y)5=x55x4y+10x3y210x2y35x4yy5

    3. 26+6·25x+15·24x2+20·23x3+15·22x4+6·2x5+x6=64+192x+240x2+160x3+60x4+x6

    4. (2x)7+7(2x)6(3y)+21(2x)5(3y)2+35(2x)4(3y)3+35(2x)3(3y)4+21(2x)2(3y)5+7(2x)(3y)6+(3y)7=128x71344x6y+6048x5y215120x4y3+22680x3y420412x2y5+10206xy62187y7

    1. ni=0(ni)anbni

    2. ni=0(ni)(1)nixni

コード(Emacs)

HTML5

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

JavaScript

let input0 = document.querySelector('#n0'),
    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, a, b) => {
    return combination(n, i) * Math.pow(a, n - i) * Math.pow(b, i);
};
let f = (n, a1, b1, a2, b2) => {
    return range(0, n + 1)
        .map((i) => `${term(n, i, a1, b1)}${a2}^${n - i}${b2}^${i}`)
        .join(' + ');
};
let output = () => {
    p(f(4, 1, 2, 'a', 'b'));
    p(f(5, 1, -1, 'x', 'y'));
    p(f(6, 2, 1, '', 'x'));
    p(f(7, 2, -3, 'x', 'y'));
};

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

output();
1a^4b^0 + 8a^3b^1 + 24a^2b^2 + 32a^1b^3 + 16a^0b^4
1x^5y^0 + -5x^4y^1 + 10x^3y^2 + -10x^2y^3 + 5x^1y^4 + -1x^0y^5
64^6x^0 + 192^5x^1 + 240^4x^2 + 160^3x^3 + 60^2x^4 + 12^1x^5 + 1^0x^6
128x^7y^0 + -1344x^6y^1 + 6048x^5y^2 + -15120x^4y^3 + 22680x^3y^4 + -20412x^2y^5 + 10206x^1y^6 + -2187x^0y^7

0 コメント:

コメントを投稿