学習環境
- 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.3(三角関数)、問題5.8、9.を取り組んでみる。
コード(Emacs)
HTML5
<div id="graph0"></div> <pre id="output0"></pre> <label for="a0">a = </label> <input id="a0" type="number" min="0.001" value="10"> <label for="b0">b = </label> <input id="b0" type="number" min="0.001" value="5"> <label for="x0">x = </label> <input id="x0" type="number" min="0.001" value="5"> <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="sample10.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_a0 = document.querySelector('#a0'), input_b0 = document.querySelector('#b0'), input_x0 = document.querySelector('#x0'), inputs = [input_a0, input_b0, input_x0], p = (x) => pre0.textContent += x + '\n'; let f = (a, b, x) => Math.atan((a - b) * x / (x ** 2 + a * b)); let draw = () => { pre0.textContent = ''; let a = parseFloat(input_a0.value), b = parseFloat(input_b0.value), x = parseFloat(input_x0.value); if (b <= 0 || a <= b || x <= 0) { return; } let points = [[0, a], [0, b]]; let d = Math.max(a, x); let xscale = d3.scaleLinear() .domain([0, d]) .range([padding, width - padding]); let yscale = d3.scaleLinear() .domain([0, d]) .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('line') .data(points) .enter() .append('line') .attr('x1', (d) => xscale(d[0])) .attr('y1', (d) => yscale(d[1])) .attr('x2', xscale(x)) .attr('y2', yscale(0)) .attr('stroke', (d, i) => i === 0 ? 'green' : 'blue'); svg.append('g') .attr('transform', `translate(0, ${yscale(0)})`) .call(xaxis); svg.append('g') .attr('transform', `translate(${xscale(0)}, 0)`) .call(yaxis); p(`θ = ${f(a, b, x)}`); } inputs.forEach((input) => input.onchange = draw); btn0.onclick = draw; btn1.onclick = () => pre0.textContent = ''; draw();
0 コメント:
コメントを投稿