2017年4月23日日曜日

学習環境

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


  1. α=a+bi β=c+di αβ ¯ = acbd+( ad+bc )i ¯ =acbd( ad+bc )i α ¯ β ¯ =( abi )( cdi ) =acbd( ad+bc )i αβ ¯ = α ¯ β ¯ α+β ¯ = a+c+( b+d )i ¯ =a+c( b+d )i α ¯ β ¯ =( abi )+( cdi ) =a+c( b+d )i

  2. α=a+bi β=c+di | αβ | =| acbd+( ad+bc )i | = ( acbd ) 2 + ( ad+bc ) 2 = a 2 c 2 + a 2 d 2 + b 2 c 2 + b 2 d 2 | α || β | = a 2 + b 2 c 2 + d 2 = a 2 c 2 + a 2 d 2 + b 2 c 2 + b 2 d 2

    1. α k = a k + b k i β k = c k + d k i B,A = k=1 n ( a k + b k i ) ( c k + d k i ) ¯ = k=1 n ( a k + b k i )( c k d k i ) = k=1 n ( a k c k + b k d k +( b k c k a k d k )i ) B,A ¯ = k=1 n ( c k + d k i ) ( a k + b k i ) ¯ ¯ = k=1 n ( c k + d k i ) ¯ ( a k b k i ) ¯ = k=1 n ( c k d k i )( a k + b k i ) = k=1 n ( a k c k + b k d k +( b k c k a k d k )i )

    2. γ k = e k + f k i A,B+C = k=1 n ( a k + b k i ) ( ( c k + e k )+( d k + f k )i ) ¯ = k=1 n ( a k + b k i )( ( c k + e k )( d k + f k )i ) = k=1 n ( a k c k + a k e k + b k d k + b k f k +( b k c k + b k e k a k d k a k f k )i ) A,B + A,C = k=1 n ( ( a k + b k i )( c k d k i )+( a k + b k i )( e k f k i ) ) = k=1 n ( ( a k + b k i )( c k d k i )+( a k + b k i )( e k f k i ) ) = k=1 n ( a k c k + a k e k + b k d k + b k f k +( b k c k + b k e k a k d k a k f k )i ) A,B+C = A,B + A,C

    3. αA,B = k=1 n ( ( a+bi )( a k + b k i )( c k d k i ) ) =( a+bi ) k=1 n ( a k + b k i )( c k d k i ) =α A,B A,αβ = k=1 n ( ( a k + b k i )( abi )( c k d k i ) ) =( abi ) k=1 n ( a k + b k i )( c k d k i ) = α ¯ A,β

    4. A,A = k=1 n α k α k ¯ = k=1 n | a k | 2 O,O =0 AO A,A 0

コード(Emacs)

HTML5

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

<script src="sample4.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 innerProd = (A, B) => {
    return A.reduce((prev, next, i) => prev.add(next.mul(B[i].conjugate())),
                    Complex(0, 0));
};
let output = () => {
    let a = Complex(Math.floor(Math.random() * 100),
                    Math.floor(Math.random() * 100)),
        b = Complex(Math.floor(Math.random() * 100),
                    Math.floor(Math.random() * 100)),
        c = Complex(Math.floor(Math.random() * 100),
                    Math.floor(Math.random() * 100));
    p('4.');
    let l = a.mul(b).conjugate(),
        r = a.conjugate().mul(b.conjugate());

    p(l.isEqual(r));
    p(l);
    p(r);

    l = a.add(b).conjugate();
    r = a.conjugate().add(b.conjugate());
    p(l.isEqual(r));
    p(l);
    p(r);

    p('5.');
    l = a.mul(b).mag();
    r = a.mag() * b.mag();
    p(l === r);
    p(l);
    p(r);

    p('6.');
    let A = [],
        B = [],
        C = [],
        O = [],
        n = Math.floor(Math.random() * 100);

    for (let k = 0; k < n; k += 1) {
        A.push(Complex(Math.floor(Math.random() * 100),
                       Math.floor(Math.random() * 100)));
        B.push(Complex(Math.floor(Math.random() * 100),
                       Math.floor(Math.random() * 100)));
        C.push(Complex(Math.floor(Math.random() * 100),
                       Math.floor(Math.random() * 100)));
        O.push(Complex(0, 0));
    }
    p('6.');
    p('SP1');
    l = innerProd(A, B);
    r = innerProd(B, A).conjugate();
    p(l.isEqual(r));
    p(l);
    p(r);
    p('SP2');
    l = innerProd(A, B.map((z, i) => z.add(C[i])));
    r = innerProd(A, B).add(innerProd(A, C));
    p(l.isEqual(r));
    p(l);
    p(r);
    p('SP3');
    l = innerProd(A.map((z) => a.mul(z)), B);
    r = a.mul(innerProd(A, B));
    p(l.isEqual(r));
    p(l);
    p(r);
    l = innerProd(A, B.map((z) => a.mul(z)));
    r = a.conjugate().mul(innerProd(A, B));
    p(l.isEqual(r));
    p(l);
    p(r);
    p('SP4');
    p(innerProd(O, O));
    p(innerProd(A, A));
};

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

output();
















						

0 コメント:

コメントを投稿