学習環境
- 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(三角関数)、問題11.を取り組んでみる。
nコード(Emacs)
HTML5
<div id="graph0"></div> <pre id="output0"></pre> P1 = (0, <input id="y1" type="number" min="0.001" value="5">), P2 = (<input id="x2" type="number" value="5">, <input id="y2" type="number" max="-0.001" value="-5">), X = (<input id="x0" type="number" step="0.01" value="2.5">, 0), <label for="v1">v1 = </label><input id="v1" min="0.001" value="20">, <label for="v2">v2 = </label><input id="v2" min="0.001" value="200"> <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="sample11.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_y1 = document.querySelector('#y1'), input_x2 = document.querySelector('#x2'), input_y2 = document.querySelector('#y2'), input_x0 = document.querySelector('#x0'), input_v1 = document.querySelector('#v1'), input_v2 = document.querySelector('#v2'), inputs = [input_y1, input_x2, input_y2, input_x0, input_v1, input_v2], p = (x) => pre0.textContent += x + '\n'; let draw = () => { pre0.textContent = ''; let y1 = parseFloat(input_y1.value), x2 = parseFloat(input_x2.value), y2 = parseFloat(input_y2.value), x0 = parseFloat(input_x0.value), lines = [[0, y1, x0, 0], [x0, 0, x2, y2]], v1 = parseFloat(input_v1.value), v2 = parseFloat(input_v2.value), p1x = Math.sqrt(x0 ** 2 + y1 ** 2), theta1 = Math.asin(x0 / p1x), p2x = Math.sqrt((x2 - x0) ** 2 + y2 ** 2), theta2 = Math.asin((x2 - x0) / p2x), t = p1x / v1 + p2x / v2; let d1 = Math.min(0, x0, y2), d2 = Math.max(y1, x0, x2); let xscale = d3.scaleLinear() .domain([d1, d2]) .range([padding, width - padding]); let yscale = d3.scaleLinear() .domain([d1, d2]) .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(lines) .enter() .append('line') .attr('x1', (d) => xscale(d[0])) .attr('y1', (d) => yscale(d[1])) .attr('x2', (d) => xscale(d[2])) .attr('y2', (d) => yscale(d[3])) .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(`time: ${t}`); p(`θ1 = ${theta1}`); p(`θ2 = ${theta2}`); p(`sin θ1 / v1 = ${Math.sin(theta1) / v1}`); p(`sin θ2 / v2 = ${Math.sin(theta2) / v2}`); p(`difference: ${Math.abs(Math.sin(theta1) / v1 - Math.sin(theta2) / v2)}`); }; inputs.forEach((input) => input.onchange = draw); btn0.onclick = draw; btn1.onclick = () => pre0.textContent = ''; draw();P1 = (0, ), P2 = (, ), X = (, 0), ,
0 コメント:
コメントを投稿