2017年4月22日土曜日

学習環境

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の1章(R^nにおけるベクトル)、6(複素数)、練習問題1、2、3.を取り組んでみる。


    1. 13i 1+9 = 1 10 3 10 i

    2. 2+0i

    3. ( 1+i )( 2i )=1+3i

    4. 1+3i

    5. 6π+( 7+ π 2 )i

    6. 2π+πi

    7. ( 2 π3 )+( π+3 2 )i

    8. ( 3i )( i+3 )=86i

    1. 1i 1+1 = 1 2 1 2 i

    2. 3i 9+1 = 3 10 1 10 i

    3. 3+4i 4+1 = 3 5 + 4 5 i

    4. 2+i 4+1 = 2 5 + 1 5 i

    5. 1i

    6. 1+i 1+1 = 1 2 + 1 2 i

    7. 2+6i 9+1 = 1 5 + 3 5 i

    8. 1i 1+1 = 1 2 1 2 i

  1. x+yi x+yi xyi = x 2 y 2 +2xyi x 2 + y 2 ( x 2 y 2 ) 2 +4 x 2 y 2 ( x 2 + y 2 ) 2 = ( x 2 + y 2 ) 2 ( x 2 + y 2 ) 2 =1 | α |

コード(Emacs)

HTML5

<pre id="output0"></pre>
<br>
<button id="run0">run</button>
<button id="clear0">clear</button>

<script src="sample1.js"></script>

JavaScript

let pre0 = document.querySelector('#output0'),
    btn0 = document.querySelector('#run0'),
    btn1 = document.querySelector('#clear0'),
    p = (x) => pre0.textContent += x + '\n',
    range = (start, end, step=1) => {
        let result = [];

        for (let i = start; i < end; i += step) {
            result.push(i);
        }
        return result;
    };

let Complex = (x, y) => {
    let that = {},
        toString = () => `${x} + ${y}i`,
        real = () => x,
        imag = () => y,
        add = (z) => Complex(x + z.real(), y + z.imag()),
        mul = (z) => Complex(x * z.real() - y * z.imag(),
                             x * z.imag() + y * z.real()),
        conjugate = () => Complex(x, -y),
        inv = () => {
            let den = Math.pow(x, 2) + Math.pow(y, 2);
            return Complex(x / den, -y / den);
        },
        mag = () => Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)),
        isEqual = (z) => x === z.real() && y === z.imag();

    that.toString = toString;
    that.real = real;
    that.imag = imag;
    that.add = add;
    that.mul = mul;
    that.conjugate = conjugate;
    that.inv = inv;
    that.mag = mag;
    that.isEqual = isEqual;
    
    return that;
};

let output = () => {
    p('1.');
    [[-1/10, -3/10, Complex(-1, 3).inv()],
     [2, 0, Complex(1, 1).mul(Complex(1, -1))],
     [-1, 3, Complex(1, 1).mul(Complex(0, 1)).mul(Complex(2, -1))],
     [-1, 3, Complex(-1, 1).mul(Complex(2, -1))],
     [6 * Math.PI, 7 + Math.pow(Math.PI, 2),
      Complex(7, Math.PI).mul(Complex(Math.PI, 1))],
     [-2 * Math.PI, Math.PI, Complex(1, 2).mul(Complex(0, Math.PI))],
     [Math.sqrt(2) * Math.PI - 3, Math.PI + 3 * Math.sqrt(2),
      Complex(Math.sqrt(2), 1).mul(Complex(Math.PI, 3))],
     [-8, -6, Complex(1, 1).mul(Complex(-2, 1)).mul(Complex(3, 1))]
    ].forEach((x) => {
        let z1 = Complex(x[0], x[1]),
            z2 = x[2];

        p(z1.isEqual(z2));
        p(z1);
        p(z2);
    });
    p('2.');
    [[1/2, -1/2, Complex(1, 1).inv()],
     [3/10, -1/10, Complex(3, 1).inv()],
     [3/5, 4/5, Complex(2, 1).mul(Complex(2, -1).inv())],
     [2/5, 1/5, Complex(2, -1).inv()],
     [1, -1, Complex(1, 1).mul(Complex(0, 1).inv())],
     [1/2, 1/2, Complex(0, 1).mul(Complex(1, 1).inv())],
     [-1/5, 3/5, Complex(0, 2).mul(Complex(3, -1).inv())],
     [-1/2, -1/2, Complex(-1, 1).inv()]
    ].forEach((x) => {
        let z1 = Complex(x[0], x[1]),
            z2 = x[2];

        p(z1.isEqual(z2));
        p(z1);
        p(z2);
    });
    p('3.');
    let z = Complex(2, 3);    
    p(z.mul(z.conjugate().inv()).mag());
    p(z.mag());
    p(z.conjugate().conjugate().mag());
};

btn0.onclick = output;
btn1.onclick = () => pre0.textContent = '';

output();


0 コメント:

コメントを投稿