2017年5月13日土曜日

学習環境

解析入門〈1〉(松坂 和夫(著)、岩波書店)の第5章(各種の初等関数)、5.4(三角関数(続き)、逆三角関数)、問題1.を取り組んでみる。

n

  1. b a lim x0 sinbx bx · ax sinax = b a

  2. lim x0 1cos( x 2 + x 2 ) x 2 = lim x0 1( cos 2 x 2 sin 2 x 2 ) x 2 = lim x0 2 sin 2 x 2 4 ( x 2 ) 2 = 2 4 = 1 2

  3. y=arctanx tany=x x0y0 lim y y tany =1

  4. y=xnπ xnπy0 x=y+nπ sinx=sin( y+nπ ) =siny lim y0 y 2 sin 2 y =1

コード(Emacs)

Python 3

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sympy import Symbol, Limit, sin, cos, atan, pi, pprint

a = Symbol('a')
b = Symbol('b')
x = Symbol('x')
n = Symbol('n')

ts = [(sin(b * x) / sin(a * x), 0),
      ((1 - cos(x)) / x**2, 0),
      (atan(x) / x, 0),
      ((x - 5 * pi) ** 2 / sin(x) ** 2,  5 * pi)]

for i, (expr, v) in enumerate(ts):
    print('({})'.format(i + 1))
    pprint(Limit(expr, x, v).doit())

入出力結果(Terminal, IPython)

$ ./sample1.py
(1)
b
─
a
(2)
1/2
(3)
1
(4)
1
$

HTML5

<div id="graph0"></div>
<pre id="output0"></pre>
<label for="e0">ε = </label>
<input id="e0" type="number" value="0.001">
<label for="x1">x1 = </label>
<input id="x1" type="number" value="-5">
<label for="x2">x2 = </label>
<input id="x2" type="number" value="5">
<label for="a0">a = </label>
<input id="a0" type="number" step="1" value="2">
<label for="b0">b = </label>
<input id="b0" type="number" step="1" value="3">
<label for="n0">n = </label>
<input id="n0" type="number" step="1" value="1">

<button id="draw0">draw</button>
<button id="clear0">clear</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="sample1.js"></script>    

JavaScript

let div0 = document.querySelector('#graph0'),
    pre0 = document.querySelector('#output0'),
    width = 600,
    height = 600,
    padding = 50,
    btn0 = document.querySelector('#draw0'),
    btn1 = document.querySelector('#clear0'),
    input_e = document.querySelector('#e0'),
    input_x1 = document.querySelector('#x1'),
    input_x2 = document.querySelector('#x2'),
    input_a = document.querySelector('#a0'),
    input_b = document.querySelector('#b0'),
    input_n = document.querySelector('#n0'),
    inputs = [input_e, input_x1, input_x2, input_a, input_b, input_n],
    p = (x) => pre0.textContent += x + '\n';

let f2 = (x) => (1 - Math.cos(x)) / x ** 2,
    f3 = (x) => Math.atan(x) / x;

let draw = () => {
    pre0.textContent = '';

    let epsilon = parseFloat(input_e.value),
        x1 = parseFloat(input_x1.value),
        x2 = parseFloat(input_x2.value),
        a = parseFloat(input_a.value),
        b = parseFloat(input_b.value),
        n = parseInt(input_n.value, 10);

    if (a === 0 || b === 0) {
        return;
    }

    let f1 = (x) => Math.sin(b * x) / Math.sin(a * x),
        f4 = (x) => (x - n * Math.PI) ** 2 / Math.sin(x) ** 2;

    let points = [];

    for (let x = x1; x <= x2; x += epsilon) {
        if (x !== 0) {
            points.push([x, f1(x)]);
        }
    }
    let t1 = points.length;

    for (let x = x1; x <= x2; x += epsilon) {
        if (x !== 0) {
            points.push([x, f2(x)]);
        }
    }
    let t2 = points.length;
    
    for (let x = x1; x <= x2; x += epsilon) {
        if (x !== 0) {
            points.push([x, f3(x)]);
        }
    }
    let t3 = points.length;

    for (let x = x1; x <= x2; x += epsilon) {
        if (x !== n * Math.PI) {
            points.push([x, f4(x)]);
        }
    }

    let xscale = d3.scaleLinear()
        .domain([x1, x2])
        .range([padding, width - padding]);
    let yscale = d3.scaleLinear()
        .domain([x1, x2])
        .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);

    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':
              i < t3 ? 'blue': 'greenyellow');

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

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

    p(`b / a = ${b / a}`);
};

inputs.forEach((input) => input.onchange = draw);
btn0.onclick = draw;
btn1.onclick = () => pre0.textContent = '';
draw();






























						

0 コメント:

コメントを投稿

Comments on Google+: