2017年4月17日月曜日

学習環境

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


  1. f( a ) e λa =f( b ) e λb =0 f'( c ) e λc +f( c )·( λ ) e λc =0 f'( c ) e λc =λf( c ) e λc f'( c )=λf( c )

コード(Emacs)

HTML5

<div id="graph0"></div>
λ = <input id="lambda0" type="number" value="10">
<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="sample8.js"></script>    

JavaScript

let div0 = document.querySelector('#graph0'),
    width = 600,
    height = 600,
    padding = 20,
    input0 = document.querySelector('#lambda0'),
    btn0 = document.querySelector('#draw0'),
    f = (x) => Math.pow(x, 2) - 9,
    a = -3,
    b = 3,
    f1 = (x) => 2 * x;

let draw = () => {
    let points = [],
        l = parseFloat(input0.value);
    for (let x = a; x <= b; x += 0.001) {
        points.push([x, f(x)])
    }
    for (let x = a; x <= b; x += 0.001) {
        points.push([x, l * f1(x)])
    }    
    let xscale = d3.scaleLinear()
        .domain([-10, 10])
        .range([padding, width - padding]);
    let yscale = d3.scaleLinear()
        .domain([-10, 10])
        .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 t = points.length / 2;
    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 < t ? 'blue' : 'green');

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

    svg.append('g')
        .attr('transform', `translate(${width / 2}, 0)`)
        .call(yaxis);
}

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

draw();
λ =

0 コメント:

コメントを投稿

Comments on Google+: