2016年9月6日火曜日

学習環境/開発環境

線型代数入門 (松坂 和夫(著)、岩波書店)の第4章(複素数、複素ベクトル空間)、2(複素平面)、問9.を取り組んでみる。

問9.

| αβ | 2 | 1 α ¯ β | 2 =( αβ ) ( αβ ) ¯ ( 1 α ¯ β ) ( 1 α ¯ β ) ¯ =( αβ )( α ¯ β ¯ )( 1 α ¯ β )( 1 α ¯ β ¯ ) = | α | 2 + | β | 2 α β ¯ α β ¯ ( 1 α ¯ β )( 1α β ¯ ) = | α | 2 + | β | 2 α β ¯ α β ¯ 1+ α ¯ β+α β ¯ | α | 2 | β | 2 = | α | 2 + | β | 2 | α | 2 | β | 2 1 <1+111=0 | αβ | 2 < | 1 α ¯ β | 2 | αβ |<| 1 α ¯ β | | αβ | | 1 α ¯ β | <1 | αβ 1 α ¯ β |<1

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 = '<math>' + c + '</math>';
        
        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

0 コメント:

コメントを投稿

Comments on Google+: