2017年4月21日金曜日

開発環境

The Art of Computer Programming Volume 1 Fundamental Algorithms Third Edition 日本語版(Donald E. Knuth (著)、青木 孝 (著)、筧 一彦 (著)、鈴木 健一 (著)、長尾 高弘 (著)、有澤 誠 (その他)、和田 英一 (その他)、ドワンゴ)の第1章(基礎概念)、1.2(数学的な基礎)、演習問題11を取り組んでみる。


  1. n=0, 1 5 n=1, 1 5 27 85 = 1727 85 = 10 85 = 2 17 n=2, 2 17 + 125 629 = 74+125 629 = 51 629 = 3 37 n=3, 3 37 343 2405 = 195343 2405 = 148 2405 = 4 65

    分母に注目。

    5,17,37,65,··· 12,20,28,··· b n =8n+12 n1 a n =5+ n( 12+( 8( n1 )+12 ) ) 2 =5+ n( 12+8n+4 ) 2 =5+4n( n+2 ) =4 n 2 +8n+5 =4 ( n+1 ) 2 +1
    S n = ( 1 ) n ( n+1 ) 4 ( n+1 ) 2 +1 S 0 = 1 5 S n = S n1 + ( 1 ) n ( 2n+1 ) 3 ( 2n+1 ) 4 +4 = ( 1 ) n1 n 4 n 2 +1 + ( 1 ) n ( 2n+1 ) 3 ( 2n+1 ) 4 +4 = ( 1 ) n n( ( 2n+1 ) 4 +4 )+( 4 n 2 +1 ) ( 1 ) n ( 2n+1 ) 3 ( 4 n 2 +1 )( ( 2n+1 ) 4 +4 ) = ( 1 ) n ( 4 n 2 +1 )( 8 n 3 +12 n 2 +6n+1 )( 16 n 5 +32 n 4 +24 n 3 +8 n 2 +5n ) ( 4 n 2 +1 )( ( 2n+1 ) 4 +4 ) = ( 1 ) n ( 32 n 5 +48 n 4 +32 n 3 +16 n 2 +6n+1 )( 16 n 5 +32 n 4 +24 n 3 +8 n 2 +5n ) ( 4 n 2 +1 )( ( 2n+1 ) 4 +4 ) = ( 1 ) n 16 n 5 +16 n 4 +8 n 3 +8 n 2 +n+1 64 n 6 +128 n 5 +112 n 4 +64 n 3 +44 n 2 +8n+5 = ( 1 ) n ( n+1 )( 16 n 4 +8 n 2 +1 ) ( 4 n 2 +1 )( ( 2n+1 ) 4 +4 ) = ( 1 ) n ( n+1 ) ( 4 n 2 +1 ) 2 ( 4 n 2 +1 )( ( 2n+1 ) 4 +4 ) = ( 1 ) n ( n+1 )( 4 n 2 +1 ) ( ( 2n+1 ) 4 +4 ) = ( 1 ) n ( n+1 )( 4 n 2 +1 ) 16 n 4 +32 n 3 +24 n 2 +8n+5 = ( 1 ) n ( n+1 ) 4 n 2 +8n+5 = ( 1 ) n ( n+1 ) 4 ( n+1 ) 2 +1

コード(Emacs)

HTML5

<pre id="output0"></pre>
n = <input id="n0" type="number" min="0" step="1" value="10">
<button id="run0">run</button>
<button id="clear0">clear</button>

<script src="sample11.js"></script>

JavaScript

let input0 = document.querySelector('#n0'),
    pre0 = document.querySelector('#output0'),
    btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    p = (x) => pre0.textContent += x + '\n',
    range = (start, end, step=1) => {
        let result = [];

        for (let i = start; i < end; i += step) {
            result.push(i);
        }
        return result;
    };

let term = (n) =>
    Math.pow(-1, n) * Math.pow(2 * n + 1, 3) / (Math.pow(2 * n + 1, 4) + 4),
    f = (n) => range(0, n + 1)
    .map((i) => term(i))
    .reduce((x, y) => x + y),
    s = (n) => Math.pow(-1, n) * (n + 1) / (4 * Math.pow(n + 1, 2) + 1);
        
    
let output = () => {
    let n = parseInt(input0.value, 10),
        a1 = f(n),
        a2 = s(n),
        d = Math.abs(a1 - a2);

    p(f(n));
    p(s(n));
    p(`誤差: ${d}`)
};

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

output();

n = 














						

0 コメント:

コメントを投稿

Comments on Google+: