学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- 数式入力ソフト(TeX, MathML): MathType
- MathML対応ブラウザ: Firefox、Safari
- MathML非対応ブラウザ(Internet Explorer, Google Chrome...)用JavaScript Library: MathJax
- 参考書籍
解析入門〈1〉(松坂 和夫(著)、岩波書店)の第5章(各種の初等関数)、5.4(三角関数(続き)、逆三角関数)、問題1.を取り組んでみる。
nコード(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 コメント:
コメントを投稿