学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- 数式入力ソフト(TeX, MathML): MathType
- MathML対応ブラウザ: Firefox、Safari
- MathML非対応ブラウザ(Internet Explorer, Google Chrome...)用JavaScript Library: MathJax
ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の1章(R^nにおけるベクトル)、6(複素数)、練習問題1、2、3.を取り組んでみる。
コード(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 コメント:
コメントを投稿