2016年9月6日火曜日

数学 - 線型代数 - JavaScript - 複素数、複素ベクトル空間(複素平面、絶対値と不等式)

$\begin{array}{l}{|\alpha -\beta |}^{2}-{|1-\overline{\alpha }\beta |}^{2}\\ =\left(\alpha -\beta \right)\overline{\left(\alpha -\beta \right)}-\left(1-\overline{\alpha }\beta \right)\overline{\left(1-\overline{\alpha }\beta \right)}\\ =\left(\alpha -\beta \right)\left(\overline{\alpha }-\overline{\beta }\right)-\left(1-\overline{\alpha }\beta \right)\left(1-\overline{\overline{\alpha }\beta }\right)\\ ={|\alpha |}^{2}+{|\beta |}^{2}-\alpha \overline{\beta }-\alpha \overline{\beta }-\left(1-\overline{\alpha }\beta \right)\left(1-\alpha \overline{\beta }\right)\\ ={|\alpha |}^{2}+{|\beta |}^{2}-\alpha \overline{\beta }-\alpha \overline{\beta }-1+\overline{\alpha }\beta +\alpha \overline{\beta }-{|\alpha |}^{2}{|\beta |}^{2}\\ ={|\alpha |}^{2}+{|\beta |}^{2}-{|\alpha |}^{2}{|\beta |}^{2}-1\\ <1+1-1-1=0\\ {|\alpha -\beta |}^{2}<{|1-\overline{\alpha }\beta |}^{2}\\ |\alpha -\beta |<|1-\overline{\alpha }\beta |\\ \frac{|\alpha -\beta |}{|1-\overline{\alpha }\beta |}<1\\ |\frac{\alpha -\beta }{1-\overline{\alpha }\beta }|<1\end{array}$

number.js で確認。

HTML5

 <div id="graph0"></div> <span id="result0"></span> <br> <span>1</span>, <span id="mul0" style="color:green"></span> <br> <label for="real0" style="color:red"> α = </label> <input id="real0" type="number" step="0.01" value="0.7"> <label for="imag0"> + </label> <input id="imag0" type="number" step="0.01" value="0.7">i, <br> <label for="real1" style="color:blue"> β = </label> <input id="real1" type="number" step="0.01" value="-0.7"> <label for="imag1"> + </label> <input id="imag1" type="number" step="0.01" value="-0.7">i <script src="number.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script> <script src="sample9.js"></script> 

JavaScript

コード(Emacs)

 (function () { 'use strict'; var width = 600, height = 600, padding = 50, div_graph = document.querySelector('#graph0'), input_real0 = document.querySelector('#real0'), input_imag0 = document.querySelector('#imag0'), input_real1 = document.querySelector('#real1'), input_imag1 = document.querySelector('#imag1'), inputs = [input_real0, input_imag0, input_real1, input_imag1], span_result = document.querySelector('#result0'), span_mul = document.querySelector('#mul0'), draw; draw = function () { var real0 = parseFloat(input_real0.value), imag0 = parseFloat(input_imag0.value), real1 = parseFloat(input_real1.value), imag1 = parseFloat(input_imag1.value), a = new Complex(real0, imag0), b = new Complex(real1, imag1), c = a.conjugate().mul(b), real2 = c.getReal(), imag2 = c.getImag(), max = 1, min = -max, svg, xscale, yscale, xaxis, yaxis; span_result.innerText = a.sub(b).div((1).sub(a.conjugate().mul(b))) .magnitude(); span_mul.innerHTML = '$' + c + '$'; xscale = d3.scaleLinear() .domain([min, max]) .range([padding, width - padding]); yscale = d3.scaleLinear() .domain([min, max]) .range([height - padding, padding]); xaxis = d3.axisBottom().scale(xscale); yaxis = d3.axisLeft().scale(yscale); div_graph.innerHTML = ''; svg = d3.select('#graph0') .append('svg') .attr('width', width) .attr('height', height); svg.append('circle') .attr('cx', xscale(0)) .attr('cy', yscale(0)) .attr('r', xscale(1) - xscale(0)) .attr('fill', 'rgba(255, 255, 0, 0.5)'); svg.append('line') .attr('x1', xscale(real0)) .attr('y1', yscale(imag0)) .attr('x2', xscale(real1)) .attr('y2', yscale(imag1)) .attr('stroke', 'black'); svg.append('line') .attr('x1', xscale(1)) .attr('y1', yscale(0)) .attr('x2', xscale(real2)) .attr('y2', yscale(imag2)) .attr('stroke', 'black'); svg.append('circle') .attr('cx', xscale(real0)) .attr('cy', yscale(imag0)) .attr('r', 5) .attr('fill', 'red'); svg.append('circle') .attr('cx', xscale(real1)) .attr('cy', yscale(imag1)) .attr('r', 5) .attr('fill', 'blue'); svg.append('circle') .attr('cx', xscale(real2)) .attr('cy', yscale(imag2)) .attr('r', 5) .attr('fill', 'green'); svg.append('circle') .attr('cx', xscale(1)) .attr('cy', yscale(0)) .attr('r', 5) .attr('fill', 'black'); svg.append('g') .attr('transform', 'translate(0, ' + (height / 2) + ')') .call(xaxis); svg.append('g') .attr('transform', 'translate(' + (width / 2) + ', 0)') .call(yaxis); }; draw(); inputs.forEach(function (input) { input.onchange = draw; }); }()); 

1,
i,
i