2016年9月11日日曜日

学習環境/開発環境

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

問4.

cos3φ+isin3φ = ( cosφ+isinφ ) 3 = cos 3 φ+3i cos 2 φsinφ3cosφ sin 2 φi sin 3 φ = cos 3 φ3cosφ sin 2 φ+i( 3 cos 2 φsinφ sin 3 φ ) cos3φ= cos 2 φ3cosφ sin 2 φ cos4φ+isin4φ = ( cosφ+isinφ ) 4 = cos 4 φ+4i cos 3 φsinφ6 cos 2 φ sin 2 φ4icosφ sin 3 φ+ sin 4 φ sin4φ=4 cos 3 φsinφ4cosφ sin 3 φ cos5φ+isin5φ = ( cosφ+isinφ ) 5 = cos 5 φ+5i cos 4 φsinφ10 cos 3 φ sin 2 φ10i cos 2 φ sin 3 φ+5cosφ sin 4 φ+i sin 5 φ cos5φ= cos 5 φ10 cos 3 φ sin 2 φ+5cosφ sin 4 φ

JavaScriptで確認してみる。

HTML5

<label for="varphi0">
  φ = 
</label>
<input id="varphi0" type="number" min="0.01" step="0.01" value="0.5">
<br>
cos 3φ = <span id="answer00"></span><br>
cos^2 φ - 3cos φ sin^2 φ = <span id="answer01"></span><br>
差: <span id="diff0"></span><br>
sin 4φ = <span id="answer10"></span><br>
4cos^3 φ sin φ - 4 cos φ sin^3 φ = <span id="answer11"></span><br>
差: <span id="diff1"></span><br>
cos 5φ = <span id="answer20"></span><br>
cos^5 φ - 10cos^3 φ sin^2 φ + 5 cos φ sin^4 φ = <span id="answer21"></span><br>
差: <span id="diff2"></span><br>


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

JavaScript

コード(Emacs)

(function () {
    'use strict';
    var input_varphi = document.querySelector('#varphi0'),
        span_answer00 = document.querySelector('#answer00'),    
        span_answer01 = document.querySelector('#answer01'),
        span_diff0 = document.querySelector('#diff0'),
        span_answer10 = document.querySelector('#answer10'),
        span_answer11 = document.querySelector('#answer11'),
        span_diff1 = document.querySelector('#diff1'),
        span_answer20 = document.querySelector('#answer20'),
        span_answer21 = document.querySelector('#answer21'),
        span_diff2 = document.querySelector('#diff2'),
        calc0,
        calc1,
        calc2,
        cos,
        sin,
        output;

    calc0 = function (c, s) {
        return Math.pow(c, 3) - 3 * c * Math.pow(s, 2);
    };
    calc1 = function (c, s) {
        return 4 * Math.pow(c, 3) * s - 4 * c * Math.pow(s, 3);
    };
    calc2 = function (c, s) {
        return Math.pow(c, 5) - 10 * Math.pow(c, 3) * Math.pow(s, 2) +
            5 * c * Math.pow(s, 4);
    };
    output = function () {
        var varphi = parseFloat(input_varphi.value),
            cos = Math.cos(varphi),
            sin = Math.sin(varphi),
            a00 = Math.cos(3 * varphi),
            a01 = calc0(cos, sin),
            a10 = Math.sin(4 * varphi),
            a11 = calc1(cos, sin),
            a20 = Math.cos(5 * varphi),
            a21 = calc2(cos, sin);

        span_answer00.innerText = a00;
        span_answer01.innerText = a01;
        span_diff0.innerText = a00 - a01;
        span_answer10.innerText = a10;
        span_answer11.innerText = a11;
        span_diff1.innerText = a10 - a11;
        span_answer20.innerText = a20;
        span_answer21.innerText = a21;
        span_diff2.innerText = a20 - a21;
    };
    input_varphi.onchange = output;

    output();
}());

cos 3φ =
cos^2 φ - 3cos φ sin^2 φ =
差:
sin 4φ =
4cos^3 φ sin φ - 4 cos φ sin^3 φ =
差:
cos 5φ =
cos^5 φ - 10cos^3 φ sin^2 φ + 5 cos φ sin^4 φ =
差:

0 コメント:

コメントを投稿

Comments on Google+: