2017年4月18日火曜日

学習環境

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


  1. f( x )= e x ( 1+x )= e x 1x f'( x )= e x 1 f''( x )= e x >0 f'( 0 )=0 f( 0 )=0 x<1,x0 f( x )>0 1+x< e x f( x )= 1 1x e x = 1 e x +x e x 1x g( x )=1 e x +x e x g'( x )= e x + e x +x e x =x e x x<0 g'( x )<0 0<x<1 g'( x )>0 g'( 0 )=0 f( 0 )=0 x<1,x0 f( x )>0 e x < 1 1x x<1,x0 1+x< e x < 1 1x

コード(Emacs)

HTML5

<div id="graph0"></div>
<input id="a0" type="number" max="0.9" value="-5">
<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="sample9.js"></script>    

JavaScript

let div0 = document.querySelector('#graph0'),
    input0 = document.querySelector('#a0'),
    width = 600,
    height = 600,
    padding = 20,
    btn0 = document.querySelector('#draw0'),
    f = (x) => 1 + x,
    g = (x) => Math.exp(x),
    h = (x) => 1 / (1 - x);

let draw = () => {
    let points = [],
        a = parseFloat(input0.value),
        b = 1;
    
    for (let x = a; x < b; x += 0.001) {
        if (x === 0) {
            continue;
        }
        points.push([x, f(x)])
    }
    for (let x = a; x < b; x += 0.001) {
        if (x === 0) {
            continue;
        }
        points.push([x, g(x)])
    }    
    for (let x = a; x < b; x += 0.001) {
        if (x === 0) {
            continue;
        }
        points.push([x, h(x)])
    }
    let xscale = d3.scaleLinear()
        .domain([a, Math.E])
        .range([padding, width - padding]);
    let yscale = d3.scaleLinear()
        .domain([a, Math.E])
        .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 / 3,
        t2 = 2 * points.length / 3;
    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 ? 'red' :
              i < t2 ? 'green' :
              'blue');

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

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

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

draw();

0 コメント:

コメントを投稿