2016年8月31日水曜日

学習環境/開発環境

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

問5.

|αβ|=|α+(β)||α|+|β|=|α|+|β||αβ||α|+|β|α=0α0,β=cα,c0α0,β=dα,d0

number.js で確認。

JavaScript

コード(Emacs)

(function () {
    'use strict';
    var div_output = document.querySelector('#output0'),
        button_calc = document.querySelector('#calc0'),        
        nl = '<br>',
        display;

    display = function () {
        var a,
            b,
            a,
            b,
            d = -Math.floor(Math.random() * 100),
            left,
            right,
            output = '';
        
        a = new Complex(Math.floor(Math.random() * 100) + 1,
                        Math.floor(Math.random() * 100) + 1);
        b = new Complex(Math.floor(Math.random() * 100) + 1,
                        Math.floor(Math.random() * 100) + 1);
        left = a.sub(b).abs();
        right = a.abs().add(b.abs());
        output += 
            'a = <math>' + a + '</math>, b = <math>' + b + '</math>' + nl +
            '左辺: <math><mn>' + left + '</mn></math>' + nl +
            '右辺: <math><mn>' + right + '</mn></math>' + nl +
            '左辺 ≤ 右辺 : ' + left.le(right) + nl + nl;
        
        a = 0;
        b = new Complex(Math.floor(Math.random() * 100) + 1,
                        Math.floor(Math.random() * 100) + 1);
        left = a.sub(b).abs();
        right = a.abs().add(b.abs());
        output += 
            'a = <math><mn>' + a + '</mn></math>, ' +
            'b = <math>' + b +'</math>' + nl +
            '左辺: <math><mn>' + left + '</mn></math>' + nl +
            '右辺: <math><mn>' + right + '</mn></math>' + nl +
            '左辺 = 右辺: ' + left.isEqual(right) + nl + 
            '差: ' + left.sub(right).abs() + nl + nl;

        a = new Complex(Math.floor(Math.random() * 100) + 1,
                        Math.floor(Math.random() * 100) + 1);
        b = d.mul(a);
        left = a.sub(b).abs();
        right = a.abs().add(b.abs());
        output += 
            'a = <math>' + a + '</math>, b = <math>' + b +'</math>' + nl +
            '左辺: <math><mn>' + left + '</mn></math>' + nl +
            '右辺: <math><mn>' + right + '</mn></math>' + nl +
            '左辺 = 右辺: ' + left.isEqual(right) + nl + 
            '差: ' + left.sub(right).abs() + nl + nl;

        div_output.innerHTML = output;
    };
    
    button_calc.onclick = display;
    
    display();
}());
a = 72+77i, b = 43+6i
左辺: 76.69419795525604
右辺: 148.83480143707604
左辺 ≤ 右辺 : true

a = 0, b = 31+59i
左辺: 66.64833081180653
右辺: 66.64833081180653
左辺 = 右辺: true
差: 0

a = 81+11i, b = -3726-506i
左辺: 3841.944559724932
右辺: 3841.944559724932
左辺 = 右辺: true
差: 0

0 コメント:

コメントを投稿