2016年12月2日金曜日

学習環境

解析入門〈1〉(松坂 和夫(著)、岩波書店)の第2章(数列と級数)、2.2(数列の収束条件)、問題2.2、4-a、b.を取り組んでみる。

問題2.2、4-a、b.


  1. a n a n+2 = a n a n+1 +α a n+1 +1 = a n a n +α a n +1 +α a n +α a n +1 +1 = a n a n +α+α( a n +1 ) a n +1 · a n +1 a n +α+ a n +1 = a n ( 1+α ) a n +2α 2 a n +α+1 = 2 a n 2 +( α+1 ) a n ( α+1 ) a n 2α 2 a n +α+1 = 2( a n 2 α ) 2 a n +α+1 a n+1 α = a n +α a n +1 α = a n +α α a n α a n +1 = ( 1 α ) a n + α ( α 1 ) a n +1 = ( α 1 )( α a n ) a n +1 a n < α a n < a n+2 a n > a a n > a n+2 a 1 < α a 2 α = ( α 1 )( α a 1 ) a 1 +1 >0 a 2 > α

  2. a 2n1 < α a 2n > α a n+2 = a n +α a n +1 +α a n +α a n +1 +1 β= β+α β+1 +α β+α β+1 +1 β= ( 1+α )β+2α 2β+α+1 2 β 2 +αβ+β=β+αβ+2α β 2 =α β= α

HTML5

<div id="graph0"></div>
<div id="output0"></div>
<label for="alpha0">α = </label>
<input id="alpha0" type="number" min="1" value="5">
<label for="a1">a1 = </label>
<input id="a1" type="number" min="0" value="2">
<label for="n0">n = </label>
<input id="n0" type="number" min="1" step="1" value="10">


<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="sample4.js"></script>

JavaScript

{
    let div_graph = document.querySelector('#graph0'),
        div_output = document.querySelector('#output0'),
        input_alpha = document.querySelector('#alpha0'),
        input_a = document.querySelector('#a1'),
        input_n = document.querySelector('#n0'),
        inputs = [input_alpha, input_a, input_n],
        width = 600,
        height = 600,
        padding = 50;

    let f = (alpha, prev) => {
        return (prev + alpha) / (prev + 1);
    };
    let getPoints = (alpha, a1, n) => {
        let prev = a1,
            result = [[1, prev]];

        for (let i = 2; i <= n; i += 1) {
            let next = f(alpha, prev);
            result.push([i, next]);
            prev = next;
        }
        return result;
    }
    let plot = () => {
        let alpha = parseFloat(input_alpha.value),
            a1 = parseFloat(input_a.value);

        if (alpha > 1 && 0 < a1 && a1 < Math.sqrt(alpha)) {
            let n = parseInt(input_n.value, 10),
                points = getPoints(alpha, a1, n);

            console.log(points);
            let xscale = d3.scaleLinear()
                .domain([1, n])
                .range([padding, width - padding])
            let yscale = d3.scaleLinear()
                .domain([points[0][1] * 0.9, points[1][1] * 1.1])
                .range([height - padding, padding]);

            console.log(points.map((x) => x[1]));
            div_graph.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', 2)
                .attr('color', 'green');

            let xaxis = d3.axisBottom().scale(xscale);
            let yaxis = d3.axisLeft().scale(yscale);

            svg.append('line')
                .attr('x1', xscale(1))
                .attr('y1', yscale(Math.sqrt(alpha)))
                .attr('x2', xscale(n))
                .attr('y2', yscale(Math.sqrt(alpha)))
                .attr('stroke', 'red');
            
            svg.append('g')
                .attr('transform', `translate(0, ${height - padding})`)
                .call(xaxis);
            svg.append('g')
                .attr('transform', `translate(${padding}, 0)`)
                .call(yaxis);

            div_output.innerHTML =
                points.map((x) => `${x[0]}: ${x[1]}`).join('<br>') +
                `<br>√α(Math.sqrt(${alpha})): ${Math.sqrt(alpha)}`;
            
        } else {
            div_output.innerHTML = '注意: α > 1, 0 < a1 < √α';
        }
    };

    inputs.forEach((input) => input.onchange = plot);
    plot();

}

0 コメント:

コメントを投稿