2017年4月20日木曜日

学習環境

解析入門〈1〉(松坂 和夫(著)、岩波書店)の第5章(各種の初等関数)、5.1(対数関数・指数関数)、問題5.1-10.を取り組んでみる。


    1. lim h0 log( 1+h ) hloga = lim h0 log ( 1+h ) 1 h loga = 1 loga

    2. lim h0 a 0+h a 0 h = a 0 loga=loga

コード(Emacs)

HTML5

<div id="graph0"></div>
<pre id="output0"></pre>
a = <input id="a0" type="number" min="0.01" step="0.01" value="2">
<br>
<button id="draw0">draw</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="sample10.js"></script>    

JavaScript

let div0 = document.querySelector('#graph0'),
    input0 = document.querySelector('#a0'),
    pre0 = document.querySelector('#output0'),
    width = 600,
    height = 600,
    padding = 20,
    btn0 = document.querySelector('#draw0'),
    p = (x) => pre0.textContent = x + '\n'
    f = (a, h) => Math.log(1 + h) / (h * Math.log(a)),
    g = (a, h) => (Math.pow(a, h) - 1) / h,
    h1 = (a) => Math.log(a),
    h2 = (a) => 1 / h1(a);    

let draw = () => {
    let points = [],
        a = parseFloat(input0.value);

    if (a === 1) {
        return;
    }
    for (let h = -0.99; h < 1; h += 0.001) {
        if (h === 0) {
            continue;
        }
        points.push([h, f(a, h)]);
    }
    for (let h = -0.99; h < 1; h += 0.001) {
        if (h === 0) {
            continue;
        }
        points.push([h, g(a, h)]);
    }
    for (let h = -0.99; h < 1; h += 0.001) {
        if (h === 0) {
            continue;
        }
        points.push([h, h1(a)]);
    }
    for (let h = -0.99; h < 1; h += 0.001) {
        if (h === 0) {
            continue;
        }
        points.push([h, h2(a)]);
    }
    let xscale = d3.scaleLinear()
        .domain([-1, 1])
        .range([padding, width - padding]);
    let ys = points.map((a) => a[1]);
    let yscale = d3.scaleLinear()
        .domain([Math.min(...ys), Math.max(...ys)])
        .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);

    let t1 = points.length / 4,
        t2 = 2 * points.length / 4,
        t3 = 3 * points.length / 4;
    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', (d, i) =>
              i < t1 ? 'green' :
              i < t2 ? 'blue' :
              i < t3 ? 'red' : 'red');

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

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

input0.onchange = draw;
btn0.onclick = draw;

draw();

a = 

0 コメント:

コメントを投稿

Comments on Google+: